そういえば、2012 から追加されたカラムストアインデックスは、2014 になると更新も可能になるんですよね。ちょっと検証してみたいと思います。ここを参考にしました。AdventureWorksDW2012 の FactProductInventory テーブルを使用して検証してみたいと思います。カラムストアインデックスを作成には、下記のスクリプトを使用します。
USE [AdventureWorksDW2012] CREATE NONCLUSTERED INDEX [IX_FactProductInventory] ON [dbo].[FactProductInventory] ([ProductKey] ASC ) CREATE NONCLUSTERED COLUMNSTORE INDEX [IX_FactProductInventory] ON [dbo].[FactProductInventory] (ProductKey) WITH (DROP_EXISTING = ON, MAXDOP = 2)
検証に使用した SQL は下記の通りです。
SELECT COUNT(ProductKey) FROM [dbo].[FactProductInventory]
カラムストアインデックス適用前は下記の通りです。
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 2 ms. (1 row(s) affected) Table 'FactProductInventory'. Scan count 3, logical reads 6396, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. (1 row(s) affected) SQL Server Execution Times: CPU time = 250 ms, elapsed time = 250 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 0 ms. SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms.
カラムストアインデックス適用後は下記の通りです。
SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 0 ms. (1 row(s) affected) Table 'FactProductInventory'. Scan count 1, logical reads 9, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. (1 row(s) affected) SQL Server Execution Times: CPU time = 141 ms, elapsed time = 343 ms. SQL Server parse and compile time: CPU time = 0 ms, elapsed time = 0 ms. SQL Server Execution Times: CPU time = 0 ms, elapsed time = 0 ms.
カラムストアインデックス適用後は、logical reads の回数が低下しており、I/O にも相当な影響があると思います。それぞれの 実行プラン内容を見ても明らかです。
※カラムストアインデックス適用前の実行プラン
※カラムストアインデックス適用後の実行プラン
今回の検証で、ColumnStored Index Scan の I/O コストは、Clustered Index Scan の I/O コストと比較して非常に低いです。数千万、数億件のレコードを保持するテーブルから件数を取得するようなケースの場合は圧倒的な効果が得られるのでしょう。
メモリ最適化テーブルと同様に、カラムストアインデックスも SQL Server 2014 の注目すべき技術の一つですね。