I have the following large select query which return 1.5 million rows in 08:15. I need to optimize the query which selects about 290 columns and I can't reduce the number of columns to improve the speed.
select Column1 ... Column290
from dob.table1
where (ISNULL(Column50, 1) = 1)
I have read that ISNULL
has a performance cost if used in the WHERE
clause because the optimizer does not use the index but resort to scan, correct?
I am trying to figure out how to rewrite the
WHERE (ISNULL(Column50, 1) = 1)
I tried using with cte and setting the
IP_Column50 = case when IP_Column50 is null then else IP_Column50 end
and rewriting my query to
select *
from cte
where IP_Column50 = 1
but the CTE took longer.
I read about this approach
If so, consider creating a computed column with the result if isnull(col1, 0) and index the computed column and use it in your where-clause
But I am not sure how to implement this. Any help is appreciated with optimizing this query.
Thanks