Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there is any Performance issue while using ISNULL() in SQL Server?

Tags:

I am using ISNULL in MS SQl server 2008, since my table is too huge, whether using of ISNULL may cause any thing to the performance ?.

Thanks in advance

like image 809
kbvishnu Avatar asked Jan 19 '12 11:01

kbvishnu


1 Answers

ISNULL() in the select-clause has neglible influence on the performance. In the where-clause on the other hand it can have a very huge impact on performance, since it prevents the optimizer for using an index on that column.

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. 

So, when using isnull() in a where-clause, evaluate if it prevents the query optimizer from using an index. 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.

like image 66
Heino Zunzer Avatar answered Sep 19 '22 13:09

Heino Zunzer