v28-0003-Add-parttypid-partcollation-partsupfunc-to-Parti.patch

text/plain

Filename: v28-0003-Add-parttypid-partcollation-partsupfunc-to-Parti.patch
Type: text/plain
Part: 2
Message: Re: [HACKERS] path toward faster partition pruning

Patch

Format: format-patch
Series: patch v28-0003
Subject: Add parttypid, partcollation, partsupfunc to PartitionScheme
File+
src/backend/optimizer/util/plancat.c 30 13
src/include/nodes/relation.h 9 0
From f5226fce1e7b2b9f7b37dd0a0eaf0d12d782a56f Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Fri, 9 Feb 2018 09:58:50 +0900
Subject: [PATCH v28 3/5] Add parttypid, partcollation, partsupfunc to
 PartitionScheme

---
 src/backend/optimizer/util/plancat.c | 43 +++++++++++++++++++++++++-----------
 src/include/nodes/relation.h         |  9 ++++++++
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 60f21711f4..dcfc1665a8 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -1887,22 +1887,26 @@ find_partition_scheme(PlannerInfo *root, Relation relation)
 			continue;
 
 		/* Match the partition key types. */
-		if (memcmp(partkey->partopfamily, part_scheme->partopfamily,
+		if (memcmp(partkey->parttypid, part_scheme->parttypid,
+				   sizeof(Oid) * partnatts) != 0 ||
+			memcmp(partkey->partopfamily, part_scheme->partopfamily,
 				   sizeof(Oid) * partnatts) != 0 ||
 			memcmp(partkey->partopcintype, part_scheme->partopcintype,
 				   sizeof(Oid) * partnatts) != 0 ||
-			memcmp(partkey->parttypcoll, part_scheme->parttypcoll,
+			memcmp(partkey->partcollation, part_scheme->partcollation,
 				   sizeof(Oid) * partnatts) != 0)
 			continue;
 
 		/*
-		 * Length and byval information should match when partopcintype
+		 * typlen, typbyval, typcoll information should match when typid
 		 * matches.
 		 */
 		Assert(memcmp(partkey->parttyplen, part_scheme->parttyplen,
 					  sizeof(int16) * partnatts) == 0);
 		Assert(memcmp(partkey->parttypbyval, part_scheme->parttypbyval,
 					  sizeof(bool) * partnatts) == 0);
+		Assert(memcmp(partkey->parttypcoll, part_scheme->parttypcoll,
+					  sizeof(bool) * partnatts) == 0);
 
 		/* Found matching partition scheme. */
 		return part_scheme;
@@ -1918,16 +1922,8 @@ find_partition_scheme(PlannerInfo *root, Relation relation)
 	part_scheme->strategy = partkey->strategy;
 	part_scheme->partnatts = partkey->partnatts;
 
-	part_scheme->partopfamily = (Oid *) palloc(sizeof(Oid) * partnatts);
-	memcpy(part_scheme->partopfamily, partkey->partopfamily,
-		   sizeof(Oid) * partnatts);
-
-	part_scheme->partopcintype = (Oid *) palloc(sizeof(Oid) * partnatts);
-	memcpy(part_scheme->partopcintype, partkey->partopcintype,
-		   sizeof(Oid) * partnatts);
-
-	part_scheme->parttypcoll = (Oid *) palloc(sizeof(Oid) * partnatts);
-	memcpy(part_scheme->parttypcoll, partkey->parttypcoll,
+	part_scheme->parttypid = (Oid *) palloc(sizeof(Oid) * partnatts);
+	memcpy(part_scheme->parttypid, partkey->parttypid,
 		   sizeof(Oid) * partnatts);
 
 	part_scheme->parttyplen = (int16 *) palloc(sizeof(int16) * partnatts);
@@ -1938,6 +1934,27 @@ find_partition_scheme(PlannerInfo *root, Relation relation)
 	memcpy(part_scheme->parttypbyval, partkey->parttypbyval,
 		   sizeof(bool) * partnatts);
 
+	part_scheme->parttypcoll = (Oid *) palloc(sizeof(Oid) * partnatts);
+	memcpy(part_scheme->parttypcoll, partkey->parttypcoll,
+		   sizeof(Oid) * partnatts);
+
+	part_scheme->partopfamily = (Oid *) palloc(sizeof(Oid) * partnatts);
+	memcpy(part_scheme->partopfamily, partkey->partopfamily,
+		   sizeof(Oid) * partnatts);
+
+	part_scheme->partopcintype = (Oid *) palloc(sizeof(Oid) * partnatts);
+	memcpy(part_scheme->partopcintype, partkey->partopcintype,
+		   sizeof(Oid) * partnatts);
+
+	part_scheme->partcollation = (Oid *) palloc(sizeof(Oid) * partnatts);
+	memcpy(part_scheme->partcollation, partkey->partcollation,
+		   sizeof(Oid) * partnatts);
+
+	part_scheme->partsupfunc = (FmgrInfo *)
+									palloc(sizeof(FmgrInfo) * partnatts);
+	memcpy(part_scheme->partsupfunc, partkey->partsupfunc,
+		   sizeof(FmgrInfo) * partnatts);
+
 	/* Add the partitioning scheme to PlannerInfo. */
 	root->part_schemes = lappend(root->part_schemes, part_scheme);
 
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index b1c63173c2..ce9975c620 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -15,6 +15,7 @@
 #define RELATION_H
 
 #include "access/sdir.h"
+#include "fmgr.h"
 #include "lib/stringinfo.h"
 #include "nodes/params.h"
 #include "nodes/parsenodes.h"
@@ -342,6 +343,9 @@ typedef struct PlannerInfo
  * partition bounds. Since partition key data types and the opclass declared
  * input data types are expected to be binary compatible (per ResolveOpClass),
  * both of those should have same byval and length properties.
+ *
+ * The collation of the partition key can differ from the collation of the
+ * underlying column, so we must store this separately.
  */
 typedef struct PartitionSchemeData
 {
@@ -350,10 +354,15 @@ typedef struct PartitionSchemeData
 	Oid		   *partopfamily;	/* OIDs of operator families */
 	Oid		   *partopcintype;	/* OIDs of opclass declared input data types */
 	Oid		   *parttypcoll;	/* OIDs of collations of partition keys. */
+	Oid		   *partcollation;	/* OIDs of partitioning collation */
 
 	/* Cached information about partition key data types. */
+	Oid		   *parttypid;
 	int16	   *parttyplen;
 	bool	   *parttypbyval;
+
+	/* Array of partition key comparison function pointers */
+	FmgrInfo   *partsupfunc;
 }			PartitionSchemeData;
 
 typedef struct PartitionSchemeData *PartitionScheme;
-- 
2.11.0