Performance linkage between sql SELECT NULL and SELECT 1

Which one is better for performance

IF EXISTS(Select null from table) 

or

 IF EXISTS(Select 1 from table) 

?

+4
source share
1 answer

Both execute the same way, because the SELECT clause in EXISTS is never evaluated. You can test using:

 ... EXISTS(SELECT 1/0 FROM TABLE) 

This should cause a division by zero error, but will not.

I personally prefer to use NULL, because it is obvious that nothing is mentioned in the table, so it is more noticeable to others. Choosing a value, such as INT 1 in the second example, can lead to assumptions about what happens if they are not familiar with the EXISTS clause.

+14
source

Source: https://habr.com/ru/post/1338112/


All Articles