22

Is there any difference in performance between the operator IS NULL and the function ISNULL()?

Thanatos
  • 40,566
  • 14
  • 81
  • 139
Wiliam
  • 3,603
  • 7
  • 32
  • 55
  • 1
    Pretty 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 Answers2

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 */
Community
  • 1
  • 1
Geo
  • 12,222
  • 4
  • 33
  • 54
10

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.

Geo
  • 12,222
  • 4
  • 33
  • 54
Pekka
  • 431,103
  • 135
  • 960
  • 1,075
  • 2
    I 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
  • 5
    Huh? 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