Doubt in SQL Performance

Asked

Viewed 38 times

0

A question that has arisen now, and which I always see in one way or another in Sqls of procedures, is the following: NOT TABELA.CAMPO IS NULL or TABELA.CAMPO IS NOT NULL. What is the difference in practice in terms of performance, execution time, from one to the other? Performance would be affected, depending on the number of records in the table and/or existence of the index in the field?

  • In the question of table indexing: By default, relational databases ignore NULL values (because the relational model says that NULL means "not present"). Therefore, the index does not store NULL value, therefore if you have null condition in the SQL statement, the related index is ignored (by default).

1 answer

0


There is no measurable performance difference. Both forms are compiled and optimized for the same internal representation by any modern DBMS, thus having the same performance.

  • 2

    I saw that if there is more than one argument there is difference in the case: NOT (val1, val2) IS NULL you get true if any of the values are null, but I could not reproduce in the sql server, maybe in another SGBD source: https://stackoverflow.com/a/4074619/7558069

Browser other questions tagged

You are not signed in. Login or sign up in order to post.