pgsql: Fix inherited UPDATE/DELETE with UNION ALL subqueries. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix inherited UPDATE/DELETE with UNION ALL subqueries.
Date
Msg-id E1Vrxmu-0001y4-IA@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix inherited UPDATE/DELETE with UNION ALL subqueries.

Fix an oversight in commit b3aaf9081a1a95c245fd605dcf02c91b3a5c3a29: we do
indeed need to process the planner's append_rel_list when copying RTE
subqueries, because if any of them were flattenable UNION ALL subqueries,
the append_rel_list shows which subquery RTEs were pulled up out of which
other ones.  Without this, UNION ALL subqueries aren't correctly inserted
into the update plans for inheritance child tables after the first one,
typically resulting in no update happening for those child table(s).
Per report from Victor Yegorov.

Experimentation with this case also exposed a fault in commit
a7b965382cf0cb30aeacb112572718045e6d4be7: if an inherited UPDATE/DELETE
was proven totally dummy by constraint exclusion, we might arrive at
add_rtes_to_flat_rtable with root->simple_rel_array being NULL.  This
should be interpreted as not having any RelOptInfos.  I chose to code
the guard as a check against simple_rel_array_size, so as to also
provide some protection against indexing off the end of the array.

Back-patch to 9.2 where the faulty code was added.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/c03ad5602f529787968fa3201b35c119bbc6d782

Modified Files
--------------
src/backend/optimizer/plan/planner.c  |    9 ++++++++-
src/backend/optimizer/plan/setrefs.c  |    3 ++-
src/test/regress/expected/inherit.out |   21 +++++++++++++++++++--
src/test/regress/sql/inherit.sql      |   11 +++++++++--
4 files changed, 38 insertions(+), 6 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix inherited UPDATE/DELETE with UNION ALL subqueries.
Next
From: Tom Lane
Date:
Subject: pgsql: Fix inherited UPDATE/DELETE with UNION ALL subqueries.