From 96f0b1fed760e8b921f2d1e5be72ad864f9dd3f6 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 19 Dec 2017 13:56:25 +0900 Subject: [PATCH v4 2/3] ExecFindPartition refactoring --- src/backend/commands/copy.c | 5 +---- src/backend/executor/execPartition.c | 17 +++++++++-------- src/backend/executor/nodeModifyTable.c | 5 +---- src/include/executor/execPartition.h | 5 +---- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 251676b321..2096a52cea 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2588,10 +2588,7 @@ CopyFrom(CopyState cstate) * will get us the ResultRelInfo and TupleConversionMap for the * partition, respectively. */ - leaf_part_index = ExecFindPartition(resultRelInfo, - proute->partition_dispatch_info, - slot, - estate); + leaf_part_index = ExecFindPartition(mtstate, slot); Assert(leaf_part_index >= 0 && leaf_part_index < proute->num_partitions); diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 106a96d910..947adf3032 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -227,11 +227,7 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate, } /* - * ExecFindPartition -- Find a leaf partition in the partition tree rooted - * at parent, for the heap tuple contained in *slot - * - * estate must be non-NULL; we'll need it to compute any expressions in the - * partition key(s) + * ExecFindPartition -- Find a leaf partition for tuple contained in slot * * If no leaf partition is found, this routine errors out with the appropriate * error message, else it returns the leaf partition sequence number @@ -239,14 +235,19 @@ ExecSetupPartitionTupleRouting(ModifyTableState *mtstate, * the partition tree. */ int -ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd, - TupleTableSlot *slot, EState *estate) +ExecFindPartition(ModifyTableState *mtstate, TupleTableSlot *slot) { + EState *estate = mtstate->ps.state; int result; Datum values[PARTITION_MAX_KEYS]; bool isnull[PARTITION_MAX_KEYS]; Relation rel; - PartitionDispatch parent; + PartitionTupleRouting *proute = mtstate->mt_partition_tuple_routing; + PartitionDispatch *pd = proute->partition_dispatch_info, + parent; + ResultRelInfo *resultRelInfo = (mtstate->rootResultRelInfo != NULL) + ? mtstate->rootResultRelInfo + : mtstate->resultRelInfo; ExprContext *ecxt = GetPerTupleExprContext(estate); TupleTableSlot *ecxt_scantuple_old = ecxt->ecxt_scantuple; diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 828e1b0015..d2df9e94cf 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -297,10 +297,7 @@ ExecInsert(ModifyTableState *mtstate, * get us the ResultRelInfo and TupleConversionMap for the partition, * respectively. */ - leaf_part_index = ExecFindPartition(resultRelInfo, - proute->partition_dispatch_info, - slot, - estate); + leaf_part_index = ExecFindPartition(mtstate, slot); Assert(leaf_part_index >= 0 && leaf_part_index < proute->num_partitions); diff --git a/src/include/executor/execPartition.h b/src/include/executor/execPartition.h index 3df9c498bb..7373f60ffb 100644 --- a/src/include/executor/execPartition.h +++ b/src/include/executor/execPartition.h @@ -105,10 +105,6 @@ typedef struct PartitionTupleRouting extern PartitionTupleRouting *ExecSetupPartitionTupleRouting(ModifyTableState *mtstate, Relation rel, Index resultRTindex, EState *estate); -extern int ExecFindPartition(ResultRelInfo *resultRelInfo, - PartitionDispatch *pd, - TupleTableSlot *slot, - EState *estate); extern void ExecSetupChildParentMapForLeaf(PartitionTupleRouting *proute); extern TupleConversionMap *TupConvMapForLeaf(PartitionTupleRouting *proute, ResultRelInfo *rootRelInfo, int leaf_index); @@ -117,5 +113,6 @@ extern HeapTuple ConvertPartitionTupleSlot(TupleConversionMap *map, TupleTableSlot *new_slot, TupleTableSlot **p_my_slot); extern void ExecCleanupTupleRouting(PartitionTupleRouting *proute); +extern int ExecFindPartition(ModifyTableState *mtstate, TupleTableSlot *slot); #endif /* EXECPARTITION_H */ -- 2.11.0