From f05920a67c272b0c8464b09cccaac3e921a2c8d7 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 14 Aug 2018 10:35:47 +0900 Subject: [PATCH v4 3/4] Prune PlanRowMark of relations that are pruned from a plan --- src/backend/optimizer/plan/planner.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 44884c29c6..b03cdb13c7 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -237,6 +237,7 @@ static void create_partitionwise_grouping_paths(PlannerInfo *root, static bool group_by_has_partkey(RelOptInfo *input_rel, List *targetList, List *groupClause); +static List *get_unpruned_rowmarks(PlannerInfo *root); /***************************************************************************** @@ -1590,7 +1591,7 @@ inheritance_planner(PlannerInfo *root) if (parse->rowMarks) rowMarks = NIL; else - rowMarks = root->rowMarks; + rowMarks = get_unpruned_rowmarks(root); /* Create Path representing a ModifyTable to do the UPDATE/DELETE work */ add_path(final_rel, (Path *) @@ -2119,11 +2120,9 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, * is what goes into the LockRows node.) */ if (parse->rowMarks) - { path = (Path *) create_lockrows_path(root, final_rel, path, - root->rowMarks, + get_unpruned_rowmarks(root), SS_assign_special_param(root)); - } /* * If there is a LIMIT/OFFSET clause, add the LIMIT node. @@ -2168,7 +2167,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, if (parse->rowMarks) rowMarks = NIL; else - rowMarks = root->rowMarks; + rowMarks = get_unpruned_rowmarks(root); path = (Path *) create_modifytable_path(root, final_rel, @@ -7162,3 +7161,25 @@ group_by_has_partkey(RelOptInfo *input_rel, return true; } + +/* + * get_unpruned_rowmarks + * Return a list of PlanRowMark's that reference unpruned relations + */ +static List * +get_unpruned_rowmarks(PlannerInfo *root) +{ + List *rowMarks = NIL; + ListCell *lc; + + foreach(lc, root->rowMarks) + { + PlanRowMark *rc = lfirst(lc); + + if (root->simple_rel_array[rc->rti] != NULL && + !IS_DUMMY_REL(root->simple_rel_array[rc->rti])) + rowMarks = lappend(rowMarks, rc); + } + + return rowMarks; +} -- 2.11.0