]> granicus.if.org Git - postgresql/commitdiff
Use key and partdesc from PartitionDispatch where possible.
authorRobert Haas <rhaas@postgresql.org>
Fri, 27 Jul 2018 13:34:57 +0000 (09:34 -0400)
committerRobert Haas <rhaas@postgresql.org>
Fri, 27 Jul 2018 13:40:52 +0000 (09:40 -0400)
Instead of repeatedly fishing the data out of the relcache entry,
let's use the version that we cached in the PartitionDispatch.  We
could alternatively rip out the PartitionDispatch fields altogether,
but it doesn't make much sense to have them and not use them; before
this patch, partdesc was set but altogether unused.  Amit Langote and
I both thought using them was a litle better than removing them, so
this patch takes that approach.

Discussion: http://postgr.es/m/CA+TgmobFnxcaW-Co-XO8=yhJ5pJXoNkCj6Z7jm9Mwj9FGv-D7w@mail.gmail.com

src/backend/executor/execPartition.c

index 7a4665cc4ee39a7078ee41f95a9092f5abe89a04..cd0ec0846167dbaa20818a942486391fc8c88b6b 100644 (file)
@@ -41,7 +41,7 @@ static void FormPartitionKeyDatum(PartitionDispatch pd,
                                          EState *estate,
                                          Datum *values,
                                          bool *isnull);
-static int get_partition_for_tuple(Relation relation, Datum *values,
+static int get_partition_for_tuple(PartitionDispatch pd, Datum *values,
                                                bool *isnull);
 static char *ExecBuildSlotPartitionKeyDescription(Relation rel,
                                                                         Datum *values,
@@ -208,13 +208,11 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
        parent = pd[0];
        while (true)
        {
-               PartitionDesc partdesc;
                TupleTableSlot *myslot = parent->tupslot;
                TupleConversionMap *map = parent->tupmap;
                int                     cur_index = -1;
 
                rel = parent->reldesc;
-               partdesc = RelationGetPartitionDesc(rel);
 
                /*
                 * Convert the tuple to this parent's layout so that we can do certain
@@ -245,13 +243,13 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
                 * Nothing for get_partition_for_tuple() to do if there are no
                 * partitions to begin with.
                 */
-               if (partdesc->nparts == 0)
+               if (parent->partdesc->nparts == 0)
                {
                        result = -1;
                        break;
                }
 
-               cur_index = get_partition_for_tuple(rel, values, isnull);
+               cur_index = get_partition_for_tuple(parent, values, isnull);
 
                /*
                 * cur_index < 0 means we failed to find a partition of this parent.
@@ -1079,12 +1077,12 @@ FormPartitionKeyDatum(PartitionDispatch pd,
  * found or -1 if none found.
  */
 static int
-get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
+get_partition_for_tuple(PartitionDispatch pd, Datum *values, bool *isnull)
 {
        int                     bound_offset;
        int                     part_index = -1;
-       PartitionKey key = RelationGetPartitionKey(relation);
-       PartitionDesc partdesc = RelationGetPartitionDesc(relation);
+       PartitionKey key = pd->key;
+       PartitionDesc partdesc = pd->partdesc;
        PartitionBoundInfo boundinfo = partdesc->boundinfo;
 
        /* Route as appropriate based on partitioning strategy. */