UNION ALL vs OR condition in sql server query

前端 未结 3 989
野趣味
野趣味 2020-12-01 13:08

I have to select some rows based on a not exists condition on a table. If I use a union all as below, it gets executed in less than 1 second.

SELECT 1 FROM d         


        
3条回答
  •  臣服心动
    2020-12-01 13:39

    The usage of the OR is probably causing the query optimizer to no longer use an index in the second query. Look at the explain for each query and that will tell you the answer.

提交回复
热议问题