Re: wierd AND condition evaluation for plpgsql - Mailing list pgsql-hackers

From Tom Lane
Subject Re: wierd AND condition evaluation for plpgsql
Date
Msg-id 17638.1022626569@sss.pgh.pa.us
Whole thread Raw
In response to Re: wierd AND condition evaluation for plpgsql  (Hannu Krosing <hannu@tm.ee>)
List pgsql-hackers
Hannu Krosing <hannu@tm.ee> writes:
> Are these intricacies of SQL standardised anywhere ?

SQL92 section 3.3.4.4, "rule evaluation order" appears to sanction PG's
behavior.  In particular note the part that says syntax rules and access
rules are "effectively applied at the same time" (ie, this checking is
done before execution starts --- that legitimizes the error originally
complained of) and the parts that say that inessential portions of
expressions need not be evaluated and that implementations are not
required to perform evaluations strictly left-to-right.
        3.3.4.4  Rule evaluation order
        A conforming implementation is not required to perform the exact        sequence of actions defined in the
GeneralRules, but shall achieve        the same effect on SQL-data and schemas as that sequence. The term
effectivelyis used to emphasize actions whose effect might be        achieved in other ways by an implementation.
 
        The Syntax Rules and Access Rules for contained syntactic elements        are effectively applied at the same
timeas the Syntax Rules and        Access Rules for the containing syntactic elements. The General        Rules for
containedsyntactic elements are effectively applied be-        fore the General Rules for the containing syntactic
elements.Where        the precedence of operators is determined by the Formats of this        International Standard or
byparentheses, those operators are ef-        fectively applied in the order specified by that precedence. Where
theprecedence is not determined by the Formats or by parentheses,        effective evaluation of expressions is
generallyperformed from        left to right. However, it is implementation-dependent whether ex-        pressions are
actuallyevaluated 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.In general, if some syn-        tactic element contains more than one other syntactic element, then
theGeneral Rules for contained elements that appear earlier in the        production for the containing syntactic
elementare applied before        the General Rules for contained elements that appear later.
 
        For example, in the production:
           <A> ::= <B> <C>
        the Syntax Rules and Access Rules for <A>, <B>, and <C> are ef-        fectively applied simultaneously. The
GeneralRules for <B> are        applied before the General Rules for <C>, and the General Rules for        <A> are
appliedafter the General Rules for both <B> and <C>.
 
        If the result of an expression or search condition can be deter-        mined without completely evaluating all
partsof the expression or        search condition, then the parts of the expression or search condi-        tion whose
evaluationis not necessary are called the inessential        parts. If the Access Rules pertaining to inessential parts
arenot        satisfied, then the syntax error or access rule violation exception        condition is raised regardless
ofwhether or not the inessential        parts are actually evaluated. If evaluation of the inessential        parts
wouldcause an exception condition to be raised, then it is        implementation-dependent whether or not that
exceptioncondition is        raised.
 
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Null values in indexes
Next
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] Re : Solaris Performance - 64 bit puzzle