diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 559458a7191f8e103bbc6620e9297e83bd7745f0..ac43be6a6e5783522585957a38dde6f5de7f0f38 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -781,6 +781,13 @@ inheritance_planner(PlannerInfo *root) */ subroot.rowMarks = (List *) copyObject(root->rowMarks); + /* + * The append_rel_list likewise might contain references to subquery + * RTEs (if any subqueries were flattenable UNION ALLs). So prepare + * to apply ChangeVarNodes to that, too. + */ + subroot.append_rel_list = (List *) copyObject(root->append_rel_list); + /* * Add placeholders to the child Query's rangetable list to fill the * RT indexes already reserved for subqueries in previous children. @@ -821,6 +828,7 @@ inheritance_planner(PlannerInfo *root) newrti = list_length(subroot.parse->rtable) + 1; ChangeVarNodes((Node *) subroot.parse, rti, newrti, 0); ChangeVarNodes((Node *) subroot.rowMarks, rti, newrti, 0); + ChangeVarNodes((Node *) subroot.append_rel_list, rti, newrti, 0); rte = copyObject(rte); subroot.parse->rtable = lappend(subroot.parse->rtable, rte); @@ -829,7 +837,6 @@ inheritance_planner(PlannerInfo *root) } } - /* We needn't modify the child's append_rel_list */ /* There shouldn't be any OJ info to translate, as yet */ Assert(subroot.join_info_list == NIL); /* and we haven't created PlaceHolderInfos, either */ diff --git a/src/test/regress/expected/inherit.out b/src/test/regress/expected/inherit.out index 08a25c42e448350fa315ac5608a2ce74d4bd6908..145715101142c6345b69faf622675ffde3b2ce8c 100644 --- a/src/test/regress/expected/inherit.out +++ b/src/test/regress/expected/inherit.out @@ -558,8 +558,7 @@ insert into bar2 values(2,2,2); insert into bar2 values(3,3,3); insert into bar2 values(4,4,4); update bar set f2 = f2 + 100 where f1 in (select f1 from foo); -SELECT relname, bar.* FROM bar, pg_class where bar.tableoid = pg_class.oid -order by 1,2; +select tableoid::regclass::text as relname, bar.* from bar order by 1,2; relname | f1 | f2 ---------+----+----- bar | 1 | 101 @@ -572,6 +571,24 @@ order by 1,2; bar2 | 4 | 4 (8 rows) +-- Check UPDATE with inherited target and an appendrel subquery +update bar set f2 = f2 + 100 +from + ( select f1 from foo union all select f1+3 from foo ) ss +where bar.f1 = ss.f1; +select tableoid::regclass::text as relname, bar.* from bar order by 1,2; + relname | f1 | f2 +---------+----+----- + bar | 1 | 201 + bar | 2 | 202 + bar | 3 | 203 + bar | 4 | 104 + bar2 | 1 | 201 + bar2 | 2 | 202 + bar2 | 3 | 203 + bar2 | 4 | 104 +(8 rows) + /* Test multiple inheritance of column defaults */ CREATE TABLE firstparent (tomorrow date default now()::date + 1); CREATE TABLE secondparent (tomorrow date default now() :: date + 1); diff --git a/src/test/regress/sql/inherit.sql b/src/test/regress/sql/inherit.sql index 1914bdea9b50403434f99e2c350d98cdbab1f385..c85931c1f2c17d9fce1e2068547d33cf07bf775f 100644 --- a/src/test/regress/sql/inherit.sql +++ b/src/test/regress/sql/inherit.sql @@ -118,8 +118,15 @@ insert into bar2 values(4,4,4); update bar set f2 = f2 + 100 where f1 in (select f1 from foo); -SELECT relname, bar.* FROM bar, pg_class where bar.tableoid = pg_class.oid -order by 1,2; +select tableoid::regclass::text as relname, bar.* from bar order by 1,2; + +-- Check UPDATE with inherited target and an appendrel subquery +update bar set f2 = f2 + 100 +from + ( select f1 from foo union all select f1+3 from foo ) ss +where bar.f1 = ss.f1; + +select tableoid::regclass::text as relname, bar.* from bar order by 1,2; /* Test multiple inheritance of column defaults */