0002-Teach-expand_inherited_rtentry-to-use-partition-boun.patch
text/plain
Filename: 0002-Teach-expand_inherited_rtentry-to-use-partition-boun.patch
Type: text/plain
Part: 1
Patch
Format: format-patch
Series: patch 0002
Subject: Teach expand_inherited_rtentry to use partition bound order
| File | + | − |
|---|---|---|
| src/backend/optimizer/prep/prepunion.c | 33 | 0 |
From 593b8dba9e859344bb3402786014201a3fa1e363 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Wed, 9 Aug 2017 15:52:36 +0900
Subject: [PATCH 2/2] Teach expand_inherited_rtentry to use partition bound
order
After locking the child tables using find_all_inheritors, we discard
the list of child table OIDs that it generates and rebuild the same
using the information returned by RelationGetPartitionDispatchInfo.
---
src/backend/optimizer/prep/prepunion.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index f43c3f3007..dad6892c4d 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -33,6 +33,7 @@
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
+#include "catalog/partition.h"
#include "catalog/pg_inherits_fn.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
@@ -1452,6 +1453,38 @@ expand_inherited_rtentry(PlannerInfo *root, RangeTblEntry *rte, Index rti)
*/
oldrelation = heap_open(parentOID, NoLock);
+ /*
+ * For partitioned tables, we arrange the child table OIDs such that they
+ * appear in the partition bound order.
+ */
+ if (rte->relkind == RELKIND_PARTITIONED_TABLE)
+ {
+ List *leaf_part_oids,
+ *ptinfos;
+
+ /* Discard the original list. */
+ list_free(inhOIDs);
+ inhOIDs = NIL;
+
+ /* Request partitioning information. */
+ RelationGetPartitionDispatchInfo(oldrelation, &ptinfos,
+ &leaf_part_oids);
+
+ /*
+ * First collect the partitioned child table OIDs, which includes the
+ * root parent at the head.
+ */
+ foreach(l, ptinfos)
+ {
+ PartitionedTableInfo *ptinfo = lfirst(l);
+
+ inhOIDs = lappend_oid(inhOIDs, ptinfo->relid);
+ }
+
+ /* Concatenate the leaf partition OIDs. */
+ inhOIDs = list_concat(inhOIDs, leaf_part_oids);
+ }
+
/* Scan the inheritance set and expand it */
appinfos = NIL;
has_child = false;
--
2.11.0