Is the SQL WHERE clause short-circuit evaluated?

前端 未结 14 2655
时光取名叫无心
时光取名叫无心 2020-11-22 04:31

Are boolean expressions in SQL WHERE clauses short-circuit evaluated ?

For example:

SELECT * 
FROM Table t 
WHERE @key IS NULL OR (@key IS NOT NULL          


        
14条回答
  •  情话喂你
    2020-11-22 04:43

    ANSI SQL Draft 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.

提交回复
热议问题