最近、フィルター化インデックスがうまく使用できないことで、はまってました。MSDN Blog でこの記事を見つけました。
記事の題名は、『 The Pains of Filtered Indexes 』。ほう。興味のそそられる記事ですね。早速確認してみましょう。フィルター化インデックスを WITH 句で指定し、実行すると下記のようなエラーが発生します。
対応するには、ほう....
While incredibly useful, you can see that filtered indexes do have some drawbacks when it comes to how they can be applied. In most cases, the best way to take advantage of the filtered indexes you have is through the use of dynamic string execution. In this case I was lazy and just modified how I was using sp_executesql. The EXECUTE statement would have worked just as well.
動的に文字列連結した結果を executesql したらいいんですね。
DECLARE @SQL NVARCHAR(MAX), @ProductID INT SET @ProductID = 870 SET @SQL = N'SELECT ProductID FROM Sales.SalesOrderDetail WHERE ProductID = ' + CAST(@ProductID AS VARCHAR(10)) EXECUTE sp_executesql @SQL
インデックスひとつとっても奥が深いですね。まだまだ、修行がたりません。今回は他力で終了です...(一切検証していません。)
※ある程度は、力を抜いていかないと。
- 作者: 高田純次
- 出版社/メーカー: 河出書房新社
- 発売日: 2007/06
- メディア: 文庫
- 購入: 10人 クリック: 133回
- この商品を含むブログ (75件) を見る