pgsql: Fix pushing of index-expression qualifications through UNION ALL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix pushing of index-expression qualifications through UNION ALL
Date: 2012-01-29 21:32:07
Message-ID: E1RrcM3-00073E-P3@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix pushing of index-expression qualifications through UNION ALL.

In commit 57664ed25e5dea117158a2e663c29e60b3546e1c, I made the planner
wrap non-simple-variable outputs of appendrel children (IOW, child SELECTs
of UNION ALL subqueries) inside PlaceHolderVars, in order to solve some
issues with EquivalenceClass processing. However, this means that any
upper-level WHERE clauses mentioning such outputs will now contain
PlaceHolderVars after they're pushed down into the appendrel child,
and that prevents indxpath.c from recognizing that they could be matched
to index expressions. To fix, add explicit stripping of PlaceHolderVars
from index operands, same as we have long done for RelabelType nodes.
Add a regression test covering both this and the plain-UNION case (which
is a totally different code path, but should also be able to do it).

Per bug #6416 from Matteo Beccati. Back-patch to 9.1, same as the
previous change.

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/106123fa269de39e5215eb8808889a78c9a45fe7

Modified Files
--------------
src/backend/optimizer/path/indxpath.c | 9 ++++++
src/backend/optimizer/plan/createplan.c | 5 ++-
src/test/regress/expected/union.out | 48 +++++++++++++++++++++++++++++++
src/test/regress/sql/union.sql | 33 +++++++++++++++++++++
4 files changed, 94 insertions(+), 1 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2012-01-29 23:38:44 pgsql: Tweak index costing for problems with partial indexes.
Previous Message Tom Lane 2012-01-29 02:07:04 pgsql: Add caution about multiple unique indexes breaking plpgsql upser