v2-0003-ExecSetupPartitionTupleRouting-refactoring.patch
text/plain
Filename: v2-0003-ExecSetupPartitionTupleRouting-refactoring.patch
Type: text/plain
Part: 2
Patch
Format: format-patch
Series: patch v2-0003
Subject: ExecSetupPartitionTupleRouting refactoring
| File | + | − |
|---|---|---|
| src/backend/commands/copy.c | 1 | 1 |
| src/backend/executor/execPartition.c | 11 | 3 |
| src/backend/executor/nodeModifyTable.c | 1 | 3 |
| src/include/executor/execPartition.h | 1 | 2 |
From cb5aeacf77cd11dc460fe5d2e2a4398359188e43 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Tue, 19 Dec 2017 16:20:09 +0900
Subject: [PATCH v2 3/4] ExecSetupPartitionTupleRouting refactoring
---
src/backend/commands/copy.c | 2 +-
src/backend/executor/execPartition.c | 14 +++++++++++---
src/backend/executor/nodeModifyTable.c | 4 +---
src/include/executor/execPartition.h | 3 +--
4 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 8c724b8695..13f1b5b3e1 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2476,7 +2476,7 @@ CopyFrom(CopyState cstate)
mtstate->ps.state = estate;
mtstate->resultRelInfo = resultRelInfo;
proute = mtstate->mt_partition_tuple_routing =
- ExecSetupPartitionTupleRouting(mtstate, cstate->rel, 1, estate);
+ ExecSetupPartitionTupleRouting(mtstate, cstate->rel);
/*
* If we are capturing transition tuples, they may need to be
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c
index 21d230881a..be15189f1d 100644
--- a/src/backend/executor/execPartition.c
+++ b/src/backend/executor/execPartition.c
@@ -46,14 +46,15 @@ static char *ExecBuildSlotPartitionKeyDescription(Relation rel,
* RowExclusiveLock mode upon return from this function.
*/
PartitionTupleRouting *
-ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
- Relation rel, Index resultRTindex,
- EState *estate)
+ExecSetupPartitionTupleRouting(ModifyTableState *mtstate, Relation rel)
{
TupleDesc tupDesc = RelationGetDescr(rel);
List *leaf_parts;
ListCell *cell;
int i;
+ EState *estate = mtstate->ps.state;
+ ModifyTable *node = (ModifyTable *) mtstate->ps.plan;
+ Index resultRTindex = node->nominalRelation;
ResultRelInfo *leaf_part_rri;
PartitionTupleRouting *proute;
@@ -67,8 +68,15 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
RelationGetPartitionDispatchInfo(rel, &proute->num_dispatch,
&leaf_parts);
proute->num_partitions = list_length(leaf_parts);
+
+ /*
+ * Allocate an array of ResultRelInfo pointers, but actual
+ * ResultRelInfo's will be allocated if and when needed. See
+ * ExecFindPartition where it's done.
+ */
proute->partitions = (ResultRelInfo **) palloc(proute->num_partitions *
sizeof(ResultRelInfo *));
+ /* Here too, actual TupleConversionMap's will be allocated later. */
proute->partition_tupconv_maps =
(TupleConversionMap **) palloc0(proute->num_partitions *
sizeof(TupleConversionMap *));
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 9a8f667d72..0bd47ef3ab 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -1934,9 +1934,7 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
{
proute = mtstate->mt_partition_tuple_routing =
- ExecSetupPartitionTupleRouting(mtstate,
- rel, node->nominalRelation,
- estate);
+ ExecSetupPartitionTupleRouting(mtstate, rel);
num_partitions = proute->num_partitions;
}
diff --git a/src/include/executor/execPartition.h b/src/include/executor/execPartition.h
index 79dad58828..b3517e2ee0 100644
--- a/src/include/executor/execPartition.h
+++ b/src/include/executor/execPartition.h
@@ -84,8 +84,7 @@ typedef struct PartitionTupleRouting
} PartitionTupleRouting;
extern PartitionTupleRouting *ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
- Relation rel, Index resultRTindex,
- EState *estate);
+ Relation rel);
extern void ExecCleanupTupleRouting(PartitionTupleRouting *proute);
extern int ExecFindPartition(ModifyTableState *mtstate, TupleTableSlot *slot);
--
2.11.0