なぜ、InMemory の方が速くならないかと疑問に思い、再度検証してみました。検証環境は前回記事の同じです。前回の検証で気になっていたことがありました。それは下図実行プランの注意マークです。
前回は特に気にせず検証していましたが、よく見てみると、下記のワーニングが発生していますね。
Columns With No Statistics: [AdventureWorksDW2012].[dbo].[FactProductInventoryInMemoryTable].ProductKey
早速統計情報の作成をやってみました。ここを参考にしてください。統計情報を作成するコマンドは下記の通りです。
UPDATE STATISTICS [dbo].[FactProductInventoryInMemoryTable] WITH FULLSCAN, NORECOMPUTE
統計情報作成後に、同じクエリを実行すると下記のようになります。注意マークが消えました。( 通常のテーブルで統計情報が存在しない場合、このような警告でてました?)
前回と同様に下記のSQLを実行してみましょう。
①
USE AdventureWorksDW2012 SELECT * FROM FactProductInventory WHERE ProductKey = 606 AND DateKey = 20081231
② USE AdventureWorksDW2012 SELECT * FROM FactProductInventoryInMemoryTable WHERE ProductKey = 606 AND DateKey = 20081231
まず、①から実行してみましょう。
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.
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 0, logical reads 3, 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 = 0 ms, elapsed time = 2 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.
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)
(1 row(s) affected)
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.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
いい感じに、メモリ最適化テーブルの方が高速になりましたね。実行プランをきちんと作成したら、やはり速いんですね。(あ、常識....)