From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: zabetak@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17623: WHERE should be evaluated after FROM clause when operators may throw
Date: Wed, 28 Sep 2022 10:37:38 -0400
Message-ID: <3945739.1664375858@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwbRN3ji2jQzPqGeSpLyYCGg3WZnheQUjvXSN52VW-YKGg@mail.gmail.com>
References: <17623-2bef2f4ff7fe8051@postgresql.org>
<CAKFQuwbRN3ji2jQzPqGeSpLyYCGg3WZnheQUjvXSN52VW-YKGg@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
>> The SQL standard (Section 7.4 general rule 1) mandates that WHERE should be
>> applied to the result of FROM so in the case above pushing filters below
>> the join seems to violate the standard.
> The failure to document such a deviation from the standard can be
> considered a bug but not the deviation itself. That is intentional. In
> terms of trade-offs the current behavior seems reasonable.
Enforcing such a restriction would be absolutely disastrous for the
performance of a large number of real-world queries. I doubt that
any other RDBMS takes that spec wording literally either.
I'd suggest something like
CASE WHEN e.empno = 0 THEN NULL ELSE 10 / e.empno END
if you need to program around the lack of guarantees about the
order of evaluation. A WITH clause can also be used as an
optimization fence when you need one.
BTW, this *is* documented, see for example
https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-EXPRESS-EVAL
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, zabetak@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17623: WHERE should be evaluated after FROM clause when operators may throw
In-Reply-To: <3945739.1664375858@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox