本文介绍了性能比较sql SELECT NULL和SELECT 1之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪一个更适合性能
如果EXISTS(从表中选择null)
或
如果EXISTS从表)
?
方案
两者执行相同,因为EXISTS中的SELECT子句从不评估。您可以使用:
... EXISTS(SELECT 1/0 FROM TABLE)
这应该触发除以零错误,但不会。
个人更喜欢使用NULL,因为很明显,表中没有引用任何内容,所以它对其他人更可见。选择一个值,例如第二个例子中的INT数字1,可以导致假设如果不熟悉EXISTS子句,会发生什么。
Which one is better for performance
IF 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.
这篇关于性能比较sql SELECT NULL和SELECT 1之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!