Is there any difference in performance between the operator IS NULL
and the function ISNULL()
?
Asked
Active
Viewed 2.9k times
24
-
1Pretty much the same, I think. http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html – Amadan Aug 20 '10 at 10:50
2 Answers
15
This thread is similar, though not exactly on MySQL. According to the test shown there:
IS NULL
is more efficient as it doesn't require a scan.
Seek is generally faster than a scan as it only includes qualifying records, while scan includes every row. It is explained in more detail here.
Another difference (though it's not performance) is their negation syntax:
IS NOT NULL /* using NOT operator */
! ISNULL() /* using exclamation mark */
-
-
4
-
-
3The thread you're referring to is about MSSQL where `isnull` is not the same as MySQL `isnull` but the same as MySQL `ifnull`. So the answer overall is incorrect and misleading. – Sam Dark Nov 19 '15 at 23:22
-
11
Looking into the MySQL manual, they seem to be synonyms really.
and even if they aren't, I would tend to trust the query optimizer to pick the best solution.
-
3I readed that too, but the ISNULL doc says that SHARES some special behaviors with IS NULL, that scared me. – Wiliam Aug 20 '10 at 10:54
-
@Wiliam good point. Maybe doing a test run is indeed the best way to go! – Pekka Aug 20 '10 at 10:55
-
5Huh? In my understanding, "shares special behaviour" just means they're weird, but they're weird in the *same way*. – Amadan Aug 25 '10 at 18:37
-
@Wiliam, `isnull()` seems like a function, whereas `is null` is surely a "language feature". – Pacerier May 04 '15 at 10:28