From f48e6b91cebe393da71d6412b07f00cc65758bc4 Mon Sep 17 00:00:00 2001 From: "dgrowley@gmail.com" Date: Thu, 27 Sep 2018 13:31:11 +1200 Subject: [PATCH v12 5/5] 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 6a5d2f9d99..83e1021d12 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -248,6 +248,7 @@ static bool group_by_has_partkey(RelOptInfo *input_rel, List *targetList, List *groupClause); static int common_prefix_cmp(const void *a, const void *b); +static List *get_nondummy_rowmarks(PlannerInfo *root); /***************************************************************************** @@ -1595,7 +1596,7 @@ inheritance_planner(PlannerInfo *root) if (parse->rowMarks) rowMarks = NIL; else - rowMarks = root->rowMarks; + rowMarks = get_nondummy_rowmarks(root); /* Create Path representing a ModifyTable to do the UPDATE/DELETE work */ add_path(final_rel, (Path *) @@ -2124,11 +2125,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_nondummy_rowmarks(root), SS_assign_special_param(root)); - } /* * If there is a LIMIT/OFFSET clause, add the LIMIT node. @@ -2173,7 +2172,7 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, if (parse->rowMarks) rowMarks = NIL; else - rowMarks = root->rowMarks; + rowMarks = get_nondummy_rowmarks(root); path = (Path *) create_modifytable_path(root, final_rel, @@ -7221,3 +7220,25 @@ group_by_has_partkey(RelOptInfo *input_rel, return true; } + +/* + * get_nondummy_rowmarks + * Return a list of PlanRowMark's that reference non-dummy relations + */ +static List * +get_nondummy_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