【发布时间】:2016-11-10 19:41:02
【问题描述】:
我有以下大型选择查询,它在 08:15 返回 150 万行。我需要优化选择大约 290 列的查询,我不能减少列数来提高速度。
select Column1 ... Column290
from dob.table1
where (ISNULL(Column50, 1) = 1)
我读到ISNULL 如果在WHERE 子句中使用会降低性能,因为优化器不使用索引而是诉诸扫描,对吗?
我正在研究如何重写
WHERE (ISNULL(Column50, 1) = 1)
我尝试使用 with cte 并设置
IP_Column50 = case when IP_Column50 is null then else IP_Column50 end
并将我的查询重写为
select *
from cte
where IP_Column50 = 1
但 CTE 需要更长的时间。
我读到了这种方法
如果是这样,请考虑使用 if isnull(col1, 0) 的结果创建一个计算列并将计算列索引并在 where 子句中使用它
但我不确定如何实现这一点。对优化此查询的任何帮助表示赞赏。
谢谢
【问题讨论】:
-
Column50的数据类型是什么?
标签: sql sql-server tsql