开发者

Performance Comparation Between sql SELECT NULL and SELECT 1

开发者 https://www.devze.com 2023-02-08 17:11 出处:网络
Which one is better for performance IF开发者_Python百科 EXISTS(Select null from table) or IF EXISTS(Select 1 from table)

Which one is better for performance

IF开发者_Python百科 EXISTS(Select null from table)

or

IF EXISTS(Select 1 from table)

?


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

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

That should trigger a divide by zero error, but won't.

I personally prefer using NULL because it's obvious that nothing is referenced in the table, so it's more visible to others. Selecting a value, like the INT number 1 in the second example, can lead to assumptions about what is happening if not familiar with the EXISTS clause.

0

精彩评论

暂无评论...
验证码 换一张
取 消