2014年2月15日土曜日

【SQLSERVER】Or指定をUnion化してインデックスを有効活用する方法

col1、col2にインデックスが存在する場合に有効。

◆改善前
select *
   from XXX
  where col1 = AAA
       or col2 = BBB

◆改善後
select *
   from (
             select * from XXX where col1 = AAA Union
             select * from XXX where col2 = BBB
            ) XXX

0 件のコメント:

コメントを投稿