1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-29 10:41:53 +03:00

Fix inherited UPDATE/DELETE with UNION ALL subqueries.

Fix an oversight in commit b3aaf9081a: 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
a7b965382c: 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.
This commit is contained in:
Tom Lane
2013-12-14 17:33:53 -05:00
parent 60eea3780c
commit c03ad5602f
4 changed files with 38 additions and 6 deletions

View File

@ -280,7 +280,8 @@ add_rtes_to_flat_rtable(PlannerInfo *root, bool recursing)
* RTEs without matching RelOptInfos, as they likewise have been
* pulled up.
*/
if (rte->rtekind == RTE_SUBQUERY && !rte->inh)
if (rte->rtekind == RTE_SUBQUERY && !rte->inh &&
rti < root->simple_rel_array_size)
{
RelOptInfo *rel = root->simple_rel_array[rti];