Commit 52ed730d authored by Tom Lane's avatar Tom Lane

Remove some unnecessary fields from Plan trees.

In the wake of commit f2343653, we no longer need some fields that
were used before to control executor lock acquisitions:

* PlannedStmt.nonleafResultRelations can go away entirely.

* partitioned_rels can go away from Append, MergeAppend, and ModifyTable.
However, ModifyTable still needs to know the RT index of the partition
root table if any, which was formerly kept in the first entry of that
list.  Add a new field "rootRelation" to remember that.  rootRelation is
partly redundant with nominalRelation, in that if it's set it will have
the same value as nominalRelation.  However, the latter field has a
different purpose so it seems best to keep them distinct.

Amit Langote, reviewed by David Rowley and Jesper Pedersen,
and whacked around a bit more by me

Discussion: https://postgr.es/m/468c85d9-540e-66a2-1dde-fec2b741e688@lab.ntt.co.jp
parent 39808e88
...@@ -2050,7 +2050,7 @@ postgresBeginForeignInsert(ModifyTableState *mtstate, ...@@ -2050,7 +2050,7 @@ postgresBeginForeignInsert(ModifyTableState *mtstate,
* Vars contained in those expressions. * Vars contained in those expressions.
*/ */
if (plan && plan->operation == CMD_UPDATE && if (plan && plan->operation == CMD_UPDATE &&
resultRelation == plan->nominalRelation) resultRelation == plan->rootRelation)
resultRelation = mtstate->resultRelInfo[0].ri_RangeTableIndex; resultRelation = mtstate->resultRelInfo[0].ri_RangeTableIndex;
} }
......
...@@ -183,7 +183,6 @@ ExecSerializePlan(Plan *plan, EState *estate) ...@@ -183,7 +183,6 @@ ExecSerializePlan(Plan *plan, EState *estate)
pstmt->planTree = plan; pstmt->planTree = plan;
pstmt->rtable = estate->es_range_table; pstmt->rtable = estate->es_range_table;
pstmt->resultRelations = NIL; pstmt->resultRelations = NIL;
pstmt->nonleafResultRelations = NIL;
/* /*
* Transfer only parallel-safe subplans, leaving a NULL "hole" in the list * Transfer only parallel-safe subplans, leaving a NULL "hole" in the list
......
...@@ -355,7 +355,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, ...@@ -355,7 +355,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
leaf_part_rri = makeNode(ResultRelInfo); leaf_part_rri = makeNode(ResultRelInfo);
InitResultRelInfo(leaf_part_rri, InitResultRelInfo(leaf_part_rri,
partrel, partrel,
node ? node->nominalRelation : 1, node ? node->rootRelation : 1,
rootrel, rootrel,
estate->es_instrument); estate->es_instrument);
......
...@@ -91,7 +91,6 @@ _copyPlannedStmt(const PlannedStmt *from) ...@@ -91,7 +91,6 @@ _copyPlannedStmt(const PlannedStmt *from)
COPY_NODE_FIELD(planTree); COPY_NODE_FIELD(planTree);
COPY_NODE_FIELD(rtable); COPY_NODE_FIELD(rtable);
COPY_NODE_FIELD(resultRelations); COPY_NODE_FIELD(resultRelations);
COPY_NODE_FIELD(nonleafResultRelations);
COPY_NODE_FIELD(rootResultRelations); COPY_NODE_FIELD(rootResultRelations);
COPY_NODE_FIELD(subplans); COPY_NODE_FIELD(subplans);
COPY_BITMAPSET_FIELD(rewindPlanIDs); COPY_BITMAPSET_FIELD(rewindPlanIDs);
...@@ -204,7 +203,7 @@ _copyModifyTable(const ModifyTable *from) ...@@ -204,7 +203,7 @@ _copyModifyTable(const ModifyTable *from)
COPY_SCALAR_FIELD(operation); COPY_SCALAR_FIELD(operation);
COPY_SCALAR_FIELD(canSetTag); COPY_SCALAR_FIELD(canSetTag);
COPY_SCALAR_FIELD(nominalRelation); COPY_SCALAR_FIELD(nominalRelation);
COPY_NODE_FIELD(partitioned_rels); COPY_SCALAR_FIELD(rootRelation);
COPY_SCALAR_FIELD(partColsUpdated); COPY_SCALAR_FIELD(partColsUpdated);
COPY_NODE_FIELD(resultRelations); COPY_NODE_FIELD(resultRelations);
COPY_SCALAR_FIELD(resultRelIndex); COPY_SCALAR_FIELD(resultRelIndex);
...@@ -244,7 +243,6 @@ _copyAppend(const Append *from) ...@@ -244,7 +243,6 @@ _copyAppend(const Append *from)
*/ */
COPY_NODE_FIELD(appendplans); COPY_NODE_FIELD(appendplans);
COPY_SCALAR_FIELD(first_partial_plan); COPY_SCALAR_FIELD(first_partial_plan);
COPY_NODE_FIELD(partitioned_rels);
COPY_NODE_FIELD(part_prune_info); COPY_NODE_FIELD(part_prune_info);
return newnode; return newnode;
...@@ -266,7 +264,6 @@ _copyMergeAppend(const MergeAppend *from) ...@@ -266,7 +264,6 @@ _copyMergeAppend(const MergeAppend *from)
/* /*
* copy remainder of node * copy remainder of node
*/ */
COPY_NODE_FIELD(partitioned_rels);
COPY_NODE_FIELD(mergeplans); COPY_NODE_FIELD(mergeplans);
COPY_SCALAR_FIELD(numCols); COPY_SCALAR_FIELD(numCols);
COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber)); COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
......
...@@ -280,7 +280,6 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node) ...@@ -280,7 +280,6 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node)
WRITE_NODE_FIELD(planTree); WRITE_NODE_FIELD(planTree);
WRITE_NODE_FIELD(rtable); WRITE_NODE_FIELD(rtable);
WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(resultRelations);
WRITE_NODE_FIELD(nonleafResultRelations);
WRITE_NODE_FIELD(rootResultRelations); WRITE_NODE_FIELD(rootResultRelations);
WRITE_NODE_FIELD(subplans); WRITE_NODE_FIELD(subplans);
WRITE_BITMAPSET_FIELD(rewindPlanIDs); WRITE_BITMAPSET_FIELD(rewindPlanIDs);
...@@ -376,7 +375,7 @@ _outModifyTable(StringInfo str, const ModifyTable *node) ...@@ -376,7 +375,7 @@ _outModifyTable(StringInfo str, const ModifyTable *node)
WRITE_ENUM_FIELD(operation, CmdType); WRITE_ENUM_FIELD(operation, CmdType);
WRITE_BOOL_FIELD(canSetTag); WRITE_BOOL_FIELD(canSetTag);
WRITE_UINT_FIELD(nominalRelation); WRITE_UINT_FIELD(nominalRelation);
WRITE_NODE_FIELD(partitioned_rels); WRITE_UINT_FIELD(rootRelation);
WRITE_BOOL_FIELD(partColsUpdated); WRITE_BOOL_FIELD(partColsUpdated);
WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(resultRelations);
WRITE_INT_FIELD(resultRelIndex); WRITE_INT_FIELD(resultRelIndex);
...@@ -405,7 +404,6 @@ _outAppend(StringInfo str, const Append *node) ...@@ -405,7 +404,6 @@ _outAppend(StringInfo str, const Append *node)
WRITE_NODE_FIELD(appendplans); WRITE_NODE_FIELD(appendplans);
WRITE_INT_FIELD(first_partial_plan); WRITE_INT_FIELD(first_partial_plan);
WRITE_NODE_FIELD(partitioned_rels);
WRITE_NODE_FIELD(part_prune_info); WRITE_NODE_FIELD(part_prune_info);
} }
...@@ -418,7 +416,6 @@ _outMergeAppend(StringInfo str, const MergeAppend *node) ...@@ -418,7 +416,6 @@ _outMergeAppend(StringInfo str, const MergeAppend *node)
_outPlanInfo(str, (const Plan *) node); _outPlanInfo(str, (const Plan *) node);
WRITE_NODE_FIELD(partitioned_rels);
WRITE_NODE_FIELD(mergeplans); WRITE_NODE_FIELD(mergeplans);
WRITE_INT_FIELD(numCols); WRITE_INT_FIELD(numCols);
...@@ -2179,7 +2176,7 @@ _outModifyTablePath(StringInfo str, const ModifyTablePath *node) ...@@ -2179,7 +2176,7 @@ _outModifyTablePath(StringInfo str, const ModifyTablePath *node)
WRITE_ENUM_FIELD(operation, CmdType); WRITE_ENUM_FIELD(operation, CmdType);
WRITE_BOOL_FIELD(canSetTag); WRITE_BOOL_FIELD(canSetTag);
WRITE_UINT_FIELD(nominalRelation); WRITE_UINT_FIELD(nominalRelation);
WRITE_NODE_FIELD(partitioned_rels); WRITE_UINT_FIELD(rootRelation);
WRITE_BOOL_FIELD(partColsUpdated); WRITE_BOOL_FIELD(partColsUpdated);
WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(resultRelations);
WRITE_NODE_FIELD(subpaths); WRITE_NODE_FIELD(subpaths);
...@@ -2259,7 +2256,6 @@ _outPlannerGlobal(StringInfo str, const PlannerGlobal *node) ...@@ -2259,7 +2256,6 @@ _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
WRITE_NODE_FIELD(finalrtable); WRITE_NODE_FIELD(finalrtable);
WRITE_NODE_FIELD(finalrowmarks); WRITE_NODE_FIELD(finalrowmarks);
WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(resultRelations);
WRITE_NODE_FIELD(nonleafResultRelations);
WRITE_NODE_FIELD(rootResultRelations); WRITE_NODE_FIELD(rootResultRelations);
WRITE_NODE_FIELD(relationOids); WRITE_NODE_FIELD(relationOids);
WRITE_NODE_FIELD(invalItems); WRITE_NODE_FIELD(invalItems);
......
...@@ -1504,7 +1504,6 @@ _readPlannedStmt(void) ...@@ -1504,7 +1504,6 @@ _readPlannedStmt(void)
READ_NODE_FIELD(planTree); READ_NODE_FIELD(planTree);
READ_NODE_FIELD(rtable); READ_NODE_FIELD(rtable);
READ_NODE_FIELD(resultRelations); READ_NODE_FIELD(resultRelations);
READ_NODE_FIELD(nonleafResultRelations);
READ_NODE_FIELD(rootResultRelations); READ_NODE_FIELD(rootResultRelations);
READ_NODE_FIELD(subplans); READ_NODE_FIELD(subplans);
READ_BITMAPSET_FIELD(rewindPlanIDs); READ_BITMAPSET_FIELD(rewindPlanIDs);
...@@ -1598,7 +1597,7 @@ _readModifyTable(void) ...@@ -1598,7 +1597,7 @@ _readModifyTable(void)
READ_ENUM_FIELD(operation, CmdType); READ_ENUM_FIELD(operation, CmdType);
READ_BOOL_FIELD(canSetTag); READ_BOOL_FIELD(canSetTag);
READ_UINT_FIELD(nominalRelation); READ_UINT_FIELD(nominalRelation);
READ_NODE_FIELD(partitioned_rels); READ_UINT_FIELD(rootRelation);
READ_BOOL_FIELD(partColsUpdated); READ_BOOL_FIELD(partColsUpdated);
READ_NODE_FIELD(resultRelations); READ_NODE_FIELD(resultRelations);
READ_INT_FIELD(resultRelIndex); READ_INT_FIELD(resultRelIndex);
...@@ -1632,7 +1631,6 @@ _readAppend(void) ...@@ -1632,7 +1631,6 @@ _readAppend(void)
READ_NODE_FIELD(appendplans); READ_NODE_FIELD(appendplans);
READ_INT_FIELD(first_partial_plan); READ_INT_FIELD(first_partial_plan);
READ_NODE_FIELD(partitioned_rels);
READ_NODE_FIELD(part_prune_info); READ_NODE_FIELD(part_prune_info);
READ_DONE(); READ_DONE();
...@@ -1648,7 +1646,6 @@ _readMergeAppend(void) ...@@ -1648,7 +1646,6 @@ _readMergeAppend(void)
ReadCommonPlan(&local_node->plan); ReadCommonPlan(&local_node->plan);
READ_NODE_FIELD(partitioned_rels);
READ_NODE_FIELD(mergeplans); READ_NODE_FIELD(mergeplans);
READ_INT_FIELD(numCols); READ_INT_FIELD(numCols);
READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols); READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
......
...@@ -124,7 +124,6 @@ static BitmapHeapScan *create_bitmap_scan_plan(PlannerInfo *root, ...@@ -124,7 +124,6 @@ static BitmapHeapScan *create_bitmap_scan_plan(PlannerInfo *root,
static Plan *create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual, static Plan *create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
List **qual, List **indexqual, List **indexECs); List **qual, List **indexqual, List **indexECs);
static void bitmap_subplan_mark_shared(Plan *plan); static void bitmap_subplan_mark_shared(Plan *plan);
static List *flatten_partitioned_rels(List *partitioned_rels);
static TidScan *create_tidscan_plan(PlannerInfo *root, TidPath *best_path, static TidScan *create_tidscan_plan(PlannerInfo *root, TidPath *best_path,
List *tlist, List *scan_clauses); List *tlist, List *scan_clauses);
static SubqueryScan *create_subqueryscan_plan(PlannerInfo *root, static SubqueryScan *create_subqueryscan_plan(PlannerInfo *root,
...@@ -203,8 +202,7 @@ static NamedTuplestoreScan *make_namedtuplestorescan(List *qptlist, List *qpqual ...@@ -203,8 +202,7 @@ static NamedTuplestoreScan *make_namedtuplestorescan(List *qptlist, List *qpqual
static WorkTableScan *make_worktablescan(List *qptlist, List *qpqual, static WorkTableScan *make_worktablescan(List *qptlist, List *qpqual,
Index scanrelid, int wtParam); Index scanrelid, int wtParam);
static Append *make_append(List *appendplans, int first_partial_plan, static Append *make_append(List *appendplans, int first_partial_plan,
List *tlist, List *partitioned_rels, List *tlist, PartitionPruneInfo *partpruneinfo);
PartitionPruneInfo *partpruneinfo);
static RecursiveUnion *make_recursive_union(List *tlist, static RecursiveUnion *make_recursive_union(List *tlist,
Plan *lefttree, Plan *lefttree,
Plan *righttree, Plan *righttree,
...@@ -280,7 +278,7 @@ static Result *make_result(List *tlist, Node *resconstantqual, Plan *subplan); ...@@ -280,7 +278,7 @@ static Result *make_result(List *tlist, Node *resconstantqual, Plan *subplan);
static ProjectSet *make_project_set(List *tlist, Plan *subplan); static ProjectSet *make_project_set(List *tlist, Plan *subplan);
static ModifyTable *make_modifytable(PlannerInfo *root, static ModifyTable *make_modifytable(PlannerInfo *root,
CmdType operation, bool canSetTag, CmdType operation, bool canSetTag,
Index nominalRelation, List *partitioned_rels, Index nominalRelation, Index rootRelation,
bool partColsUpdated, bool partColsUpdated,
List *resultRelations, List *subplans, List *subroots, List *resultRelations, List *subplans, List *subroots,
List *withCheckOptionLists, List *returningLists, List *withCheckOptionLists, List *returningLists,
...@@ -1110,8 +1108,7 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path) ...@@ -1110,8 +1108,7 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path)
*/ */
plan = make_append(subplans, best_path->first_partial_path, plan = make_append(subplans, best_path->first_partial_path,
tlist, best_path->partitioned_rels, tlist, partpruneinfo);
partpruneinfo);
copy_generic_path_info(&plan->plan, (Path *) best_path); copy_generic_path_info(&plan->plan, (Path *) best_path);
...@@ -1253,8 +1250,6 @@ create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path) ...@@ -1253,8 +1250,6 @@ create_merge_append_plan(PlannerInfo *root, MergeAppendPath *best_path)
prunequal); prunequal);
} }
node->partitioned_rels =
flatten_partitioned_rels(best_path->partitioned_rels);
node->mergeplans = subplans; node->mergeplans = subplans;
node->part_prune_info = partpruneinfo; node->part_prune_info = partpruneinfo;
...@@ -2411,7 +2406,7 @@ create_modifytable_plan(PlannerInfo *root, ModifyTablePath *best_path) ...@@ -2411,7 +2406,7 @@ create_modifytable_plan(PlannerInfo *root, ModifyTablePath *best_path)
best_path->operation, best_path->operation,
best_path->canSetTag, best_path->canSetTag,
best_path->nominalRelation, best_path->nominalRelation,
best_path->partitioned_rels, best_path->rootRelation,
best_path->partColsUpdated, best_path->partColsUpdated,
best_path->resultRelations, best_path->resultRelations,
subplans, subplans,
...@@ -5005,27 +5000,6 @@ bitmap_subplan_mark_shared(Plan *plan) ...@@ -5005,27 +5000,6 @@ bitmap_subplan_mark_shared(Plan *plan)
elog(ERROR, "unrecognized node type: %d", nodeTag(plan)); elog(ERROR, "unrecognized node type: %d", nodeTag(plan));
} }
/*
* flatten_partitioned_rels
* Convert List of Lists into a single List with all elements from the
* sub-lists.
*/
static List *
flatten_partitioned_rels(List *partitioned_rels)
{
List *newlist = NIL;
ListCell *lc;
foreach(lc, partitioned_rels)
{
List *sublist = lfirst(lc);
newlist = list_concat(newlist, list_copy(sublist));
}
return newlist;
}
/***************************************************************************** /*****************************************************************************
* *
* PLAN NODE BUILDING ROUTINES * PLAN NODE BUILDING ROUTINES
...@@ -5368,8 +5342,7 @@ make_foreignscan(List *qptlist, ...@@ -5368,8 +5342,7 @@ make_foreignscan(List *qptlist,
static Append * static Append *
make_append(List *appendplans, int first_partial_plan, make_append(List *appendplans, int first_partial_plan,
List *tlist, List *partitioned_rels, List *tlist, PartitionPruneInfo *partpruneinfo)
PartitionPruneInfo *partpruneinfo)
{ {
Append *node = makeNode(Append); Append *node = makeNode(Append);
Plan *plan = &node->plan; Plan *plan = &node->plan;
...@@ -5380,7 +5353,6 @@ make_append(List *appendplans, int first_partial_plan, ...@@ -5380,7 +5353,6 @@ make_append(List *appendplans, int first_partial_plan,
plan->righttree = NULL; plan->righttree = NULL;
node->appendplans = appendplans; node->appendplans = appendplans;
node->first_partial_plan = first_partial_plan; node->first_partial_plan = first_partial_plan;
node->partitioned_rels = flatten_partitioned_rels(partitioned_rels);
node->part_prune_info = partpruneinfo; node->part_prune_info = partpruneinfo;
return node; return node;
} }
...@@ -6509,7 +6481,7 @@ make_project_set(List *tlist, ...@@ -6509,7 +6481,7 @@ make_project_set(List *tlist,
static ModifyTable * static ModifyTable *
make_modifytable(PlannerInfo *root, make_modifytable(PlannerInfo *root,
CmdType operation, bool canSetTag, CmdType operation, bool canSetTag,
Index nominalRelation, List *partitioned_rels, Index nominalRelation, Index rootRelation,
bool partColsUpdated, bool partColsUpdated,
List *resultRelations, List *subplans, List *subroots, List *resultRelations, List *subplans, List *subroots,
List *withCheckOptionLists, List *returningLists, List *withCheckOptionLists, List *returningLists,
...@@ -6538,7 +6510,7 @@ make_modifytable(PlannerInfo *root, ...@@ -6538,7 +6510,7 @@ make_modifytable(PlannerInfo *root,
node->operation = operation; node->operation = operation;
node->canSetTag = canSetTag; node->canSetTag = canSetTag;
node->nominalRelation = nominalRelation; node->nominalRelation = nominalRelation;
node->partitioned_rels = flatten_partitioned_rels(partitioned_rels); node->rootRelation = rootRelation;
node->partColsUpdated = partColsUpdated; node->partColsUpdated = partColsUpdated;
node->resultRelations = resultRelations; node->resultRelations = resultRelations;
node->resultRelIndex = -1; /* will be set correctly in setrefs.c */ node->resultRelIndex = -1; /* will be set correctly in setrefs.c */
......
...@@ -303,7 +303,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) ...@@ -303,7 +303,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
glob->finalrtable = NIL; glob->finalrtable = NIL;
glob->finalrowmarks = NIL; glob->finalrowmarks = NIL;
glob->resultRelations = NIL; glob->resultRelations = NIL;
glob->nonleafResultRelations = NIL;
glob->rootResultRelations = NIL; glob->rootResultRelations = NIL;
glob->relationOids = NIL; glob->relationOids = NIL;
glob->invalItems = NIL; glob->invalItems = NIL;
...@@ -503,7 +502,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) ...@@ -503,7 +502,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
Assert(glob->finalrtable == NIL); Assert(glob->finalrtable == NIL);
Assert(glob->finalrowmarks == NIL); Assert(glob->finalrowmarks == NIL);
Assert(glob->resultRelations == NIL); Assert(glob->resultRelations == NIL);
Assert(glob->nonleafResultRelations == NIL);
Assert(glob->rootResultRelations == NIL); Assert(glob->rootResultRelations == NIL);
top_plan = set_plan_references(root, top_plan); top_plan = set_plan_references(root, top_plan);
/* ... and the subplans (both regular subplans and initplans) */ /* ... and the subplans (both regular subplans and initplans) */
...@@ -530,7 +528,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) ...@@ -530,7 +528,6 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
result->planTree = top_plan; result->planTree = top_plan;
result->rtable = glob->finalrtable; result->rtable = glob->finalrtable;
result->resultRelations = glob->resultRelations; result->resultRelations = glob->resultRelations;
result->nonleafResultRelations = glob->nonleafResultRelations;
result->rootResultRelations = glob->rootResultRelations; result->rootResultRelations = glob->rootResultRelations;
result->subplans = glob->subplans; result->subplans = glob->subplans;
result->rewindPlanIDs = glob->rewindPlanIDs; result->rewindPlanIDs = glob->rewindPlanIDs;
...@@ -1170,6 +1167,7 @@ inheritance_planner(PlannerInfo *root) ...@@ -1170,6 +1167,7 @@ inheritance_planner(PlannerInfo *root)
Bitmapset *subqueryRTindexes; Bitmapset *subqueryRTindexes;
Bitmapset *modifiableARIindexes; Bitmapset *modifiableARIindexes;
int nominalRelation = -1; int nominalRelation = -1;
Index rootRelation = 0;
List *final_rtable = NIL; List *final_rtable = NIL;
int save_rel_array_size = 0; int save_rel_array_size = 0;
RelOptInfo **save_rel_array = NULL; RelOptInfo **save_rel_array = NULL;
...@@ -1184,8 +1182,6 @@ inheritance_planner(PlannerInfo *root) ...@@ -1184,8 +1182,6 @@ inheritance_planner(PlannerInfo *root)
ListCell *lc; ListCell *lc;
Index rti; Index rti;
RangeTblEntry *parent_rte; RangeTblEntry *parent_rte;
Relids partitioned_relids = NULL;
List *partitioned_rels = NIL;
PlannerInfo *parent_root; PlannerInfo *parent_root;
Query *parent_parse; Query *parent_parse;
Bitmapset *parent_relids = bms_make_singleton(top_parentRTindex); Bitmapset *parent_relids = bms_make_singleton(top_parentRTindex);
...@@ -1249,24 +1245,16 @@ inheritance_planner(PlannerInfo *root) ...@@ -1249,24 +1245,16 @@ inheritance_planner(PlannerInfo *root)
/* /*
* If the parent RTE is a partitioned table, we should use that as the * If the parent RTE is a partitioned table, we should use that as the
* nominal relation, because the RTEs added for partitioned tables * nominal target relation, because the RTEs added for partitioned tables
* (including the root parent) as child members of the inheritance set do * (including the root parent) as child members of the inheritance set do
* not appear anywhere else in the plan. The situation is exactly the * not appear anywhere else in the plan, so the confusion explained below
* opposite in the case of non-partitioned inheritance parent as described * for non-partitioning inheritance cases is not possible.
* below. For the same reason, collect the list of descendant partitioned
* tables to be saved in ModifyTable node, so that executor can lock those
* as well.
*/ */
parent_rte = rt_fetch(top_parentRTindex, root->parse->rtable); parent_rte = rt_fetch(top_parentRTindex, root->parse->rtable);
if (parent_rte->relkind == RELKIND_PARTITIONED_TABLE) if (parent_rte->relkind == RELKIND_PARTITIONED_TABLE)
{ {
nominalRelation = top_parentRTindex; nominalRelation = top_parentRTindex;
rootRelation = top_parentRTindex;
/*
* Root parent's RT index is always present in the partitioned_rels of
* the ModifyTable node, if one is needed at all.
*/
partitioned_relids = bms_make_singleton(top_parentRTindex);
} }
/* /*
...@@ -1338,7 +1326,7 @@ inheritance_planner(PlannerInfo *root) ...@@ -1338,7 +1326,7 @@ inheritance_planner(PlannerInfo *root)
* inheritance parent. * inheritance parent.
*/ */
subroot->inhTargetKind = subroot->inhTargetKind =
partitioned_relids ? INHKIND_PARTITIONED : INHKIND_INHERITED; (rootRelation != 0) ? INHKIND_PARTITIONED : INHKIND_INHERITED;
/* /*
* If this child is further partitioned, remember it as a parent. * If this child is further partitioned, remember it as a parent.
...@@ -1364,13 +1352,13 @@ inheritance_planner(PlannerInfo *root) ...@@ -1364,13 +1352,13 @@ inheritance_planner(PlannerInfo *root)
/* /*
* Set the nominal target relation of the ModifyTable node if not * Set the nominal target relation of the ModifyTable node if not
* already done. We use the inheritance parent RTE as the nominal * already done. If the target is a partitioned table, we already set
* target relation if it's a partitioned table (see just above this * nominalRelation to refer to the partition root, above. For
* loop). In the non-partitioned parent case, we'll use the first * non-partitioned inheritance cases, we'll use the first child
* child relation (even if it's excluded) as the nominal target * relation (even if it's excluded) as the nominal target relation.
* relation. Because of the way expand_inherited_rtentry works, the * Because of the way expand_inherited_rtentry works, that should be
* latter should be the RTE representing the parent table in its role * the RTE representing the parent table in its role as a simple
* as a simple member of the inheritance set. * member of the inheritance set.
* *
* It would be logically cleaner to *always* use the inheritance * It would be logically cleaner to *always* use the inheritance
* parent RTE as the nominal relation; but that RTE is not otherwise * parent RTE as the nominal relation; but that RTE is not otherwise
...@@ -1508,15 +1496,6 @@ inheritance_planner(PlannerInfo *root) ...@@ -1508,15 +1496,6 @@ inheritance_planner(PlannerInfo *root)
if (IS_DUMMY_PATH(subpath)) if (IS_DUMMY_PATH(subpath))
continue; continue;
/*
* Add the current parent's RT index to the partitioned_relids set if
* we're creating the ModifyTable path for a partitioned root table.
* (We only care about parents of non-excluded children.)
*/
if (partitioned_relids)
partitioned_relids = bms_add_member(partitioned_relids,
appinfo->parent_relid);
/* /*
* If this is the first non-excluded child, its post-planning rtable * If this is the first non-excluded child, its post-planning rtable
* becomes the initial contents of final_rtable; otherwise, append * becomes the initial contents of final_rtable; otherwise, append
...@@ -1620,29 +1599,13 @@ inheritance_planner(PlannerInfo *root) ...@@ -1620,29 +1599,13 @@ inheritance_planner(PlannerInfo *root)
else else
rowMarks = root->rowMarks; rowMarks = root->rowMarks;
if (partitioned_relids)
{
int i;
i = -1;
while ((i = bms_next_member(partitioned_relids, i)) >= 0)
partitioned_rels = lappend_int(partitioned_rels, i);
/*
* If we're going to create ModifyTable at all, the list should
* contain at least one member, that is, the root parent's index.
*/
Assert(list_length(partitioned_rels) >= 1);
partitioned_rels = list_make1(partitioned_rels);
}
/* Create Path representing a ModifyTable to do the UPDATE/DELETE work */ /* Create Path representing a ModifyTable to do the UPDATE/DELETE work */
add_path(final_rel, (Path *) add_path(final_rel, (Path *)
create_modifytable_path(root, final_rel, create_modifytable_path(root, final_rel,
parse->commandType, parse->commandType,
parse->canSetTag, parse->canSetTag,
nominalRelation, nominalRelation,
partitioned_rels, rootRelation,
root->partColsUpdated, root->partColsUpdated,
resultRelations, resultRelations,
subpaths, subpaths,
...@@ -2186,10 +2149,21 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, ...@@ -2186,10 +2149,21 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
*/ */
if (parse->commandType != CMD_SELECT && !inheritance_update) if (parse->commandType != CMD_SELECT && !inheritance_update)
{ {
Index rootRelation;
List *withCheckOptionLists; List *withCheckOptionLists;
List *returningLists; List *returningLists;
List *rowMarks; List *rowMarks;
/*
* 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 ==
RELKIND_PARTITIONED_TABLE)
rootRelation = parse->resultRelation;
else
rootRelation = 0;
/* /*
* Set up the WITH CHECK OPTION and RETURNING lists-of-lists, if * Set up the WITH CHECK OPTION and RETURNING lists-of-lists, if
* needed. * needed.
...@@ -2219,7 +2193,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, ...@@ -2219,7 +2193,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update,
parse->commandType, parse->commandType,
parse->canSetTag, parse->canSetTag,
parse->resultRelation, parse->resultRelation,
NIL, rootRelation,
false, false,
list_make1_int(parse->resultRelation), list_make1_int(parse->resultRelation),
list_make1(path), list_make1(path),
......
...@@ -848,12 +848,10 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) ...@@ -848,12 +848,10 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
} }
splan->nominalRelation += rtoffset; splan->nominalRelation += rtoffset;
if (splan->rootRelation)
splan->rootRelation += rtoffset;
splan->exclRelRTI += rtoffset; splan->exclRelRTI += rtoffset;
foreach(l, splan->partitioned_rels)
{
lfirst_int(l) += rtoffset;
}
foreach(l, splan->resultRelations) foreach(l, splan->resultRelations)
{ {
lfirst_int(l) += rtoffset; lfirst_int(l) += rtoffset;
...@@ -884,24 +882,17 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) ...@@ -884,24 +882,17 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
list_copy(splan->resultRelations)); list_copy(splan->resultRelations));
/* /*
* If the main target relation is a partitioned table, the * If the main target relation is a partitioned table, also
* following list contains the RT indexes of partitioned child * add the partition root's RT index to rootResultRelations,
* relations including the root, which are not included in the * and remember its index in that list in rootResultRelIndex.
* above list. We also keep RT indexes of the roots
* separately to be identified as such during the executor
* initialization.
*/ */
if (splan->partitioned_rels != NIL) if (splan->rootRelation)
{ {
root->glob->nonleafResultRelations =
list_concat(root->glob->nonleafResultRelations,
list_copy(splan->partitioned_rels));
/* Remember where this root will be in the global list. */
splan->rootResultRelIndex = splan->rootResultRelIndex =
list_length(root->glob->rootResultRelations); list_length(root->glob->rootResultRelations);
root->glob->rootResultRelations = root->glob->rootResultRelations =
lappend_int(root->glob->rootResultRelations, lappend_int(root->glob->rootResultRelations,
linitial_int(splan->partitioned_rels)); splan->rootRelation);
} }
} }
break; break;
...@@ -915,10 +906,6 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) ...@@ -915,10 +906,6 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
*/ */
set_dummy_tlist_references(plan, rtoffset); set_dummy_tlist_references(plan, rtoffset);
Assert(splan->plan.qual == NIL); Assert(splan->plan.qual == NIL);
foreach(l, splan->partitioned_rels)
{
lfirst_int(l) += rtoffset;
}
foreach(l, splan->appendplans) foreach(l, splan->appendplans)
{ {
lfirst(l) = set_plan_refs(root, lfirst(l) = set_plan_refs(root,
...@@ -952,10 +939,6 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) ...@@ -952,10 +939,6 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
*/ */
set_dummy_tlist_references(plan, rtoffset); set_dummy_tlist_references(plan, rtoffset);
Assert(splan->plan.qual == NIL); Assert(splan->plan.qual == NIL);
foreach(l, splan->partitioned_rels)
{
lfirst_int(l) += rtoffset;
}
foreach(l, splan->mergeplans) foreach(l, splan->mergeplans)
{ {
lfirst(l) = set_plan_refs(root, lfirst(l) = set_plan_refs(root,
......
...@@ -3292,9 +3292,7 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, ...@@ -3292,9 +3292,7 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel,
* 'operation' is the operation type * 'operation' is the operation type
* 'canSetTag' is true if we set the command tag/es_processed * 'canSetTag' is true if we set the command tag/es_processed
* 'nominalRelation' is the parent RT index for use of EXPLAIN * 'nominalRelation' is the parent RT index for use of EXPLAIN
* 'partitioned_rels' is an integer list of RT indexes of non-leaf tables in * 'rootRelation' is the partitioned table root RT index, or 0 if none
* the partition tree, if this is an UPDATE/DELETE to a partitioned table.
* Otherwise NIL.
* 'partColsUpdated' is true if any partitioning columns are being updated, * 'partColsUpdated' is true if any partitioning columns are being updated,
* either from the target relation or a descendent partitioned table. * either from the target relation or a descendent partitioned table.
* 'resultRelations' is an integer list of actual RT indexes of target rel(s) * 'resultRelations' is an integer list of actual RT indexes of target rel(s)
...@@ -3309,7 +3307,7 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, ...@@ -3309,7 +3307,7 @@ create_lockrows_path(PlannerInfo *root, RelOptInfo *rel,
ModifyTablePath * ModifyTablePath *
create_modifytable_path(PlannerInfo *root, RelOptInfo *rel, create_modifytable_path(PlannerInfo *root, RelOptInfo *rel,
CmdType operation, bool canSetTag, CmdType operation, bool canSetTag,
Index nominalRelation, List *partitioned_rels, Index nominalRelation, Index rootRelation,
bool partColsUpdated, bool partColsUpdated,
List *resultRelations, List *subpaths, List *resultRelations, List *subpaths,
List *subroots, List *subroots,
...@@ -3377,7 +3375,7 @@ create_modifytable_path(PlannerInfo *root, RelOptInfo *rel, ...@@ -3377,7 +3375,7 @@ create_modifytable_path(PlannerInfo *root, RelOptInfo *rel,
pathnode->operation = operation; pathnode->operation = operation;
pathnode->canSetTag = canSetTag; pathnode->canSetTag = canSetTag;
pathnode->nominalRelation = nominalRelation; pathnode->nominalRelation = nominalRelation;
pathnode->partitioned_rels = list_copy(partitioned_rels); pathnode->rootRelation = rootRelation;
pathnode->partColsUpdated = partColsUpdated; pathnode->partColsUpdated = partColsUpdated;
pathnode->resultRelations = resultRelations; pathnode->resultRelations = resultRelations;
pathnode->subpaths = subpaths; pathnode->subpaths = subpaths;
......
...@@ -69,15 +69,8 @@ typedef struct PlannedStmt ...@@ -69,15 +69,8 @@ typedef struct PlannedStmt
List *resultRelations; /* integer list of RT indexes, or NIL */ List *resultRelations; /* integer list of RT indexes, or NIL */
/* /*
* rtable indexes of non-leaf target relations for UPDATE/DELETE on all * rtable indexes of partitioned table roots that are UPDATE/DELETE
* the partitioned tables mentioned in the query. * targets; needed for trigger firing.
*/
List *nonleafResultRelations;
/*
* rtable indexes of root target relations for UPDATE/DELETE; this list
* maintains a subset of the RT indexes in nonleafResultRelations,
* indicating the roots of the respective partition hierarchies.
*/ */
List *rootResultRelations; List *rootResultRelations;
...@@ -210,6 +203,12 @@ typedef struct ProjectSet ...@@ -210,6 +203,12 @@ typedef struct ProjectSet
* Apply rows produced by subplan(s) to result table(s), * Apply rows produced by subplan(s) to result table(s),
* by inserting, updating, or deleting. * by inserting, updating, or deleting.
* *
* If the originally named target table is a partitioned table, both
* nominalRelation and rootRelation contain the RT index of the partition
* root, which is not otherwise mentioned in the plan. Otherwise rootRelation
* is zero. However, nominalRelation will always be set, as it's the rel that
* EXPLAIN should claim is the INSERT/UPDATE/DELETE target.
*
* Note that rowMarks and epqParam are presumed to be valid for all the * Note that rowMarks and epqParam are presumed to be valid for all the
* subplan(s); they can't contain any info that varies across subplans. * subplan(s); they can't contain any info that varies across subplans.
* ---------------- * ----------------
...@@ -220,8 +219,7 @@ typedef struct ModifyTable ...@@ -220,8 +219,7 @@ typedef struct ModifyTable
CmdType operation; /* INSERT, UPDATE, or DELETE */ CmdType operation; /* INSERT, UPDATE, or DELETE */
bool canSetTag; /* do we set the command tag/es_processed? */ bool canSetTag; /* do we set the command tag/es_processed? */
Index nominalRelation; /* Parent RT index for use of EXPLAIN */ Index nominalRelation; /* Parent RT index for use of EXPLAIN */
/* RT indexes of non-leaf tables in a partition tree */ Index rootRelation; /* Root RT index, if target is partitioned */
List *partitioned_rels;
bool partColsUpdated; /* some part key in hierarchy updated */ bool partColsUpdated; /* some part key in hierarchy updated */
List *resultRelations; /* integer list of RT indexes */ List *resultRelations; /* integer list of RT indexes */
int resultRelIndex; /* index of first resultRel in plan's list */ int resultRelIndex; /* index of first resultRel in plan's list */
...@@ -259,9 +257,6 @@ typedef struct Append ...@@ -259,9 +257,6 @@ typedef struct Append
*/ */
int first_partial_plan; int first_partial_plan;
/* RT indexes of non-leaf tables in a partition tree */
List *partitioned_rels;
/* Info for run-time subplan pruning; NULL if we're not doing that */ /* Info for run-time subplan pruning; NULL if we're not doing that */
struct PartitionPruneInfo *part_prune_info; struct PartitionPruneInfo *part_prune_info;
} Append; } Append;
...@@ -274,10 +269,8 @@ typedef struct Append ...@@ -274,10 +269,8 @@ typedef struct Append
typedef struct MergeAppend typedef struct MergeAppend
{ {
Plan plan; Plan plan;
/* RT indexes of non-leaf tables in a partition tree */
List *partitioned_rels;
List *mergeplans; List *mergeplans;
/* remaining fields are just like the sort-key info in struct Sort */ /* these fields are just like the sort-key info in struct Sort: */
int numCols; /* number of sort-key columns */ int numCols; /* number of sort-key columns */
AttrNumber *sortColIdx; /* their indexes in the target list */ AttrNumber *sortColIdx; /* their indexes in the target list */
Oid *sortOperators; /* OIDs of operators to sort them by */ Oid *sortOperators; /* OIDs of operators to sort them by */
......
...@@ -121,7 +121,6 @@ typedef struct PlannerGlobal ...@@ -121,7 +121,6 @@ typedef struct PlannerGlobal
List *resultRelations; /* "flat" list of integer RT indexes */ List *resultRelations; /* "flat" list of integer RT indexes */
List *nonleafResultRelations; /* "flat" list of integer RT indexes */
List *rootResultRelations; /* "flat" list of integer RT indexes */ List *rootResultRelations; /* "flat" list of integer RT indexes */
List *relationOids; /* OIDs of relations the plan depends on */ List *relationOids; /* OIDs of relations the plan depends on */
...@@ -1717,8 +1716,7 @@ typedef struct ModifyTablePath ...@@ -1717,8 +1716,7 @@ typedef struct ModifyTablePath
CmdType operation; /* INSERT, UPDATE, or DELETE */ CmdType operation; /* INSERT, UPDATE, or DELETE */
bool canSetTag; /* do we set the command tag/es_processed? */ bool canSetTag; /* do we set the command tag/es_processed? */
Index nominalRelation; /* Parent RT index for use of EXPLAIN */ Index nominalRelation; /* Parent RT index for use of EXPLAIN */
/* RT indexes of non-leaf tables in a partition tree */ Index rootRelation; /* Root RT index, if target is partitioned */
List *partitioned_rels;
bool partColsUpdated; /* some part key in hierarchy updated */ bool partColsUpdated; /* some part key in hierarchy updated */
List *resultRelations; /* integer list of RT indexes */ List *resultRelations; /* integer list of RT indexes */
List *subpaths; /* Path(s) producing source data */ List *subpaths; /* Path(s) producing source data */
......
...@@ -238,7 +238,7 @@ extern LockRowsPath *create_lockrows_path(PlannerInfo *root, RelOptInfo *rel, ...@@ -238,7 +238,7 @@ extern LockRowsPath *create_lockrows_path(PlannerInfo *root, RelOptInfo *rel,
extern ModifyTablePath *create_modifytable_path(PlannerInfo *root, extern ModifyTablePath *create_modifytable_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
CmdType operation, bool canSetTag, CmdType operation, bool canSetTag,
Index nominalRelation, List *partitioned_rels, Index nominalRelation, Index rootRelation,
bool partColsUpdated, bool partColsUpdated,
List *resultRelations, List *subpaths, List *resultRelations, List *subpaths,
List *subroots, List *subroots,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment