sql - SQL WHERE 子句是否短路计算?

标签 sql short-circuiting

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/

相关文章:

ruby - ||运算符,知道结果后返回吗?

mysql - 在特定日期添加记录时,如何显示组中所有潜在的重复匹配项

mysql - 如何查询这是MySQL?

java - 如何防止短路?

haskell - 为什么这个的第二个版本在指数时间内运行?

javascript - 短路评估令

mysql - 如何在数据集中生成值

php - 当我的语句具有正确数量的参数和值时,为什么会出现 SQL 错误?

sql - Oracle 11 中由函数引起的表变化

c# - 为什么短路不能阻止与逻辑 AND (&&) 的不可到达分支相关的 MissingMethodException?