SQL WHERE 子句中是否有 bool 表达式 short-circuit evaluated ?
例如:
SELECT *
FROM Table t
WHERE @key IS NULL OR (@key IS NOT NULL AND @key = t.Key)
如果@key IS NULL
计算结果为 true
,是@key IS NOT NULL AND @key = t.Key
评价?
如果没有,为什么不呢?
如果是的话,有保证吗?它是 ANSI SQL 的一部分还是特定于数据库?
如果特定数据库,SQLServer?甲骨文? MySQL?
最佳答案
ANSI SQL 草案 2003 5WD-01-Framework-2003-09.pdf
6.3.3.3 Rule evaluation order
[...]
Where the precedence is not determined by the Formats or by parentheses, effective evaluation of expressions is generally performed from left to right. However, it is implementation-dependent whether expressions are actually evaluated left to right, particularly when operands or operators might cause conditions to be raised or if the results of the expressions can be determined without completely evaluating all parts of the expression.
关于sql - SQL WHERE 子句是否短路计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/789231/