0002-remove-merged-flag.patch

text/x-patch

Filename: 0002-remove-merged-flag.patch
Type: text/x-patch
Part: 0
Message: Re: [HACKERS] advanced partition matching algorithm for partition-wise join

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch 0002
Subject: remove merged flag
File+
src/backend/optimizer/path/joinrels.c 5 6
src/backend/partitioning/partbounds.c 7 5
From 59a3bd7b33fcf9c89ea46c4efe3e4912477236fb Mon Sep 17 00:00:00 2001
From: Tomas Vondra <tv@fuzzy.cz>
Date: Thu, 26 Mar 2020 00:48:46 +0100
Subject: [PATCH 2/5] remove merged flag

---
 src/backend/optimizer/path/joinrels.c | 11 +++++------
 src/backend/partitioning/partbounds.c | 12 +++++++-----
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/backend/optimizer/path/joinrels.c b/src/backend/optimizer/path/joinrels.c
index 530ebed245..0b082fc915 100644
--- a/src/backend/optimizer/path/joinrels.c
+++ b/src/backend/optimizer/path/joinrels.c
@@ -1360,7 +1360,6 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 {
 	bool		rel1_is_simple = IS_SIMPLE_REL(rel1);
 	bool		rel2_is_simple = IS_SIMPLE_REL(rel2);
-	bool		merged = false;
 	List	   *parts1 = NIL;
 	List	   *parts2 = NIL;
 	ListCell   *lcr1 = NULL;
@@ -1397,6 +1396,8 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 	Assert(joinrel->part_scheme == rel1->part_scheme &&
 		   joinrel->part_scheme == rel2->part_scheme);
 
+	Assert(!(joinrel->merged && (joinrel->nparts <= 0)));
+
 	/*
 	 * If we don't have the partition bounds for the join rel yet, try to
 	 * compute those along with pairs of partitions to be joined.
@@ -1446,12 +1447,11 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 				return;
 			}
 			nparts = list_length(parts1);
-			merged = true;
+			joinrel->merged = true;
 		}
 
 		Assert(nparts > 0);
 		joinrel->boundinfo = boundinfo;
-		joinrel->merged = merged;
 		joinrel->nparts = nparts;
 		joinrel->part_rels =
 			(RelOptInfo **) palloc0(sizeof(RelOptInfo *) * nparts);
@@ -1475,11 +1475,10 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 									&parts1, &parts2);
 			Assert(list_length(parts1) == joinrel->nparts);
 			Assert(list_length(parts2) == joinrel->nparts);
-			merged = true;
 		}
 	}
 
-	if (merged)
+	if (joinrel->merged)
 	{
 		lcr1 = list_head(parts1);
 		lcr2 = list_head(parts2);
@@ -1503,7 +1502,7 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
 		AppendRelInfo **appinfos;
 		int			nappinfos;
 
-		if (merged)
+		if (joinrel->merged)
 		{
 			child_rel1 = lfirst_node(RelOptInfo, lcr1);
 			child_rel2 = lfirst_node(RelOptInfo, lcr2);
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 24dbc2c8f3..ae426c1a30 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -1018,24 +1018,25 @@ partition_bounds_merge(int partnatts,
 {
 	PartitionBoundInfo outer_binfo = outer_rel->boundinfo;
 	PartitionBoundInfo inner_binfo = inner_rel->boundinfo;
-	char		strategy;
 
 	/*
 	 * Currently, this function is called only from try_partitionwise_join(),
 	 * so the join type should be INNER, LEFT, FULL, SEMI, or ANTI.
+	 *
+	 * XXX Maybe an assert would be more appropriate? Or maybe just
+	 * bail out by returning NULL? Not sure.
 	 */
 	if (jointype != JOIN_INNER && jointype != JOIN_LEFT && 
 		jointype != JOIN_FULL && jointype != JOIN_SEMI &&
 		jointype != JOIN_ANTI)
-		elog(ERROR, "unrecognized join type: %d", (int) jointype);
+		elog(ERROR, "unexpected join type: %d", (int) jointype);
 
 	/* Bail out if the partitioning strategies are different. */
 	if (outer_binfo->strategy != inner_binfo->strategy)
 		return NULL;
 
-	strategy = outer_binfo->strategy;
 	*outer_parts = *inner_parts = NIL;
-	switch (strategy)
+	switch (outer_binfo->strategy)
 	{
 		case PARTITION_STRATEGY_HASH:
 
@@ -1075,7 +1076,8 @@ partition_bounds_merge(int partnatts,
 									  inner_parts);
 
 		default:
-			elog(ERROR, "unexpected partition strategy: %d", (int) strategy);
+			elog(ERROR, "unexpected partition strategy: %d",
+				 (int) outer_binfo->strategy);
 			return NULL;				/* keep compiler quiet */
 	}
 }
-- 
2.17.1