postgresql/src
Tom Lane 341757bdcb Prevent pushing down WHERE clauses into unsafe UNION/INTERSECT nests.
The planner is aware that it mustn't push down upper-level quals into
subqueries if the quals reference subquery output columns that contain
set-returning functions or volatile functions, or are non-DISTINCT outputs
of a DISTINCT ON subquery.  However, it missed making this check when
there were one or more levels of UNION or INTERSECT above the dangerous
expression.  This could lead to "set-valued function called in context that
cannot accept a set" errors, as seen in bug #8213 from Eric Soroos, or to
silently wrong answers in the other cases.

To fix, refactor the checks so that we make the column-is-unsafe checks
during subquery_is_pushdown_safe(), which already has to recursively
inspect all arms of a set-operation tree.  This makes
qual_is_pushdown_safe() considerably simpler, at the cost that we will
spend some cycles checking output columns that possibly aren't referenced
in any upper qual.  But the cases where this code gets executed at all
are already nontrivial queries, so it's unlikely anybody will notice any
slowdown of planning.

This has been broken since commit 05f916e6ad,
which makes the bug over ten years old.  A bit surprising nobody noticed it
before now.
2013-06-05 23:44:08 -04:00
..
backend Prevent pushing down WHERE clauses into unsafe UNION/INTERSECT nests. 2013-06-05 23:44:08 -04:00
bin Ensure that user created rows in extension tables get dumped if the table is explicitly requested, either with a -t/--table switch of the table itself, or by -n/--schema switch of the schema containing the extension table. Patch reviewed by Vibhor Kumar and Dimitri Fontaine. 2013-04-26 12:03:00 -07:00
include Add ARM64 (aarch64) support to s_lock.h. 2013-06-04 15:42:21 -04:00
interfaces Stamp 9.2.4. 2013-04-01 14:20:36 -04:00
makefiles Make pgxs build executables with the right suffix. 2013-01-19 14:54:29 -05:00
pl Add semicolons to eval'd strings to hide a minor Perl behavioral change. 2013-06-03 14:19:32 -04:00
port Stamp 9.2.4. 2013-04-01 14:20:36 -04:00
template Remove BSD/OS (BSDi) port. There are no known users upgrading to 2012-05-03 10:58:44 -04:00
test Prevent pushing down WHERE clauses into unsafe UNION/INTERSECT nests. 2013-06-05 23:44:08 -04:00
timezone Update time zone data files to tzdata release 2013b. 2013-03-28 15:25:54 -04:00
tools Avoid renaming data directory during MSVC upgrade testing. 2013-03-23 16:31:01 -04:00
tutorial Modernize string literal syntax in tutorial example. 2013-01-19 17:20:56 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Fix some oversights in distprep and maintainer-clean targets. 2011-03-10 00:04:05 -05:00
Makefile.global.in Add mode where contrib installcheck runs each module in a separately named database. 2012-12-11 11:52:23 -05:00
Makefile.shlib Remove BSD/OS (BSDi) port. There are no known users upgrading to 2012-05-03 10:58:44 -04:00
nls-global.mk Lots of doc corrections. 2012-04-23 22:43:09 -04:00
win32.mak Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00