diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index aafef24cf1..c711888073 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -1792,6 +1792,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) List *returningLists = NIL; List *mergeActionLists = NIL; List *rowMarks; + bool inherited_update = false; if (bms_membership(root->all_result_relids) == BMS_MULTIPLE) { @@ -1800,6 +1801,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) parse->resultRelation); int resultRelation = -1; + inherited_update = true; + /* Add only leaf children to ModifyTable. */ while ((resultRelation = bms_next_member(root->leaf_result_relids, resultRelation)) >= 0) @@ -1938,7 +1941,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) * If target is a partition root table, we need to mark the * ModifyTable node appropriately for that. */ - if (rt_fetch(parse->resultRelation, parse->rtable)->relkind == + if (inherited_update || + rt_fetch(parse->resultRelation, parse->rtable)->relkind == RELKIND_PARTITIONED_TABLE) rootRelation = parse->resultRelation; else