Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISNULL slows down query

We have a table that has either NULL or "Accepted" as values. My query returns about 250 rows.

If I add a where condition of -

AND Description = 'Accepted'

my 250 rows return in 2 seconds.

However, if I add a where condition of -

ISNULL(Description, '') = 'Accepted'

my 250 rows return in 47 seconds.

Has anyone encountered performance issues with using the ISNULL function? Unfortunately I am programatically limited to having to use ISNULL at this point.

like image 302
duckmike Avatar asked Oct 24 '11 15:10

duckmike


2 Answers

When you include a field inside of a function, it changes how the optimizer has to run and forces it to ignore indexes.

see here: What makes a SQL statement sargable?

like image 178
Rob Allen Avatar answered Sep 19 '22 11:09

Rob Allen


You can also bypass the functions entirely by using:

WHERE (Description = 'Accepted' OR Description IS NULL)

like image 45
JNK Avatar answered Sep 21 '22 11:09

JNK