From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Prevent pushing down WHERE clauses into unsafe UNION/INTERSECT n |
Date: | 2013-06-06 03:45:33 |
Message-ID: | E1UkR8n-0004tl-UZ@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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 05f916e6add9726bf4ee046e4060c1b03c9961f2,
which makes the bug over ten years old. A bit surprising nobody noticed it
before now.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/964c0d0f80e485dd3a4073e073ddfd9bfdda90b2
Modified Files
--------------
src/backend/optimizer/path/allpaths.c | 216 +++++++++++++++++++--------------
src/test/regress/expected/union.out | 88 ++++++++++++++
src/test/regress/sql/union.sql | 42 +++++++
3 files changed, 255 insertions(+), 91 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2013-06-06 03:45:34 | pgsql: Prevent pushing down WHERE clauses into unsafe UNION/INTERSECT n |
Previous Message | Peter Eisentraut | 2013-06-06 02:10:17 | pgsql: Update SQL features list |