aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r--src/backend/optimizer/plan/planner.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 9cbbcfb19d4..5c4884f46b9 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -607,6 +607,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
plan = (Plan *) make_modifytable(root,
parse->commandType,
parse->canSetTag,
+ parse->resultRelation,
list_make1_int(parse->resultRelation),
list_make1(plan),
withCheckOptionLists,
@@ -790,6 +791,7 @@ inheritance_planner(PlannerInfo *root)
{
Query *parse = root->parse;
int parentRTindex = parse->resultRelation;
+ int nominalRelation = -1;
List *final_rtable = NIL;
int save_rel_array_size = 0;
RelOptInfo **save_rel_array = NULL;
@@ -925,6 +927,20 @@ inheritance_planner(PlannerInfo *root)
appinfo->child_relid = subroot.parse->resultRelation;
/*
+ * We'll use the first child relation (even if it's excluded) as the
+ * nominal target relation of the ModifyTable node. Because of the
+ * way expand_inherited_rtentry works, this should always be the RTE
+ * representing the parent table in its role as a simple member of the
+ * inheritance set. (It would be logically cleaner to use the
+ * inheritance parent RTE as the nominal target; but since that RTE
+ * will not be otherwise referenced in the plan, doing so would give
+ * rise to confusing use of multiple aliases in EXPLAIN output for
+ * what the user will think is the "same" table.)
+ */
+ if (nominalRelation < 0)
+ nominalRelation = appinfo->child_relid;
+
+ /*
* If this child rel was excluded by constraint exclusion, exclude it
* from the result plan.
*/
@@ -1051,6 +1067,7 @@ inheritance_planner(PlannerInfo *root)
return (Plan *) make_modifytable(root,
parse->commandType,
parse->canSetTag,
+ nominalRelation,
resultRelations,
subplans,
withCheckOptionLists,
@@ -2260,7 +2277,7 @@ preprocess_rowmarks(PlannerInfo *root)
newrc->markType = ROW_MARK_REFERENCE;
else
newrc->markType = ROW_MARK_COPY;
- newrc->waitPolicy = LockWaitBlock; /* doesn't matter */
+ newrc->waitPolicy = LockWaitBlock; /* doesn't matter */
newrc->isParent = false;
prowmarks = lappend(prowmarks, newrc);