v8-0003-Prune-PlanRowMark-of-relations-that-are-pruned-fr.patch

text/plain

Filename: v8-0003-Prune-PlanRowMark-of-relations-that-are-pruned-fr.patch
Type: text/plain
Part: 2
Message: Re: executor relation handling

Patch

Format: format-patch
Series: patch v8-0003
Subject: Prune PlanRowMark of relations that are pruned from a plan
File+
src/backend/optimizer/plan/planner.c 26 6
From 67f72dc024244bd4c36d865bb0b5dd350c7f1c82 Mon Sep 17 00:00:00 2001
From: "dgrowley@gmail.com" <dgrowley@gmail.com>
Date: Thu, 27 Sep 2018 13:31:11 +1200
Subject: [PATCH v8 3/4] Prune PlanRowMark of relations that are pruned from a
 plan

---
 src/backend/optimizer/plan/planner.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a927c0a1db..074ec9bf55 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -248,7 +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 +1595,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 +2124,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 +2171,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,
@@ -7219,3 +7217,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