From 8e9f0d3422453bd19b897d4212498f62855f6304 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 14 Aug 2018 10:35:47 +0900 Subject: [PATCH v3 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 bc4f02fbf6..4cd3b9b902 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); /***************************************************************************** @@ -1587,7 +1588,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 *) @@ -2116,11 +2117,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. @@ -2165,7 +2164,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, @@ -7159,3 +7158,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