我在MS SQl server 2008中使用ISNULL
,因为我的表太大,使用ISNULL
是否会对性能造成任何影响?
提前致谢
最佳答案
select子句中的ISNULL()对性能的影响可以忽略不计。 另一方面,在 where 子句中,它会对性能产生非常巨大的影响,因为它会阻止优化器在该列上使用索引。
where isnull(col1, 0) = 0 -- unable to use index, because every
-- row has to be evaluated
where col1 = isnull(@myVar, 0) -- index will be used, since isnull(@myVar, 0)
-- returns the same static value for every row and
-- not every row has to be evaluated by the function.
因此,当在 where 子句中使用 isnull() 时,请评估它是否会阻止查询优化器使用索引。如果是这样,请考虑使用结果 if isnull(col1, 0) 创建一个计算列,并对计算列建立索引并在 where 子句中使用它。
关于sql - 在 SQL Server 中使用 ISNULL() 时是否存在任何性能问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8924913/