From: Robert Haas Date: Fri, 27 Jul 2018 13:34:57 +0000 (-0400) Subject: Use key and partdesc from PartitionDispatch where possible. X-Git-Tag: REL_12_BETA1~1814 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e32109049142d3b6adb3b45afd0bb0dea24c23a;p=postgresql Use key and partdesc from PartitionDispatch where possible. 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 --- diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 7a4665cc4e..cd0ec08461 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -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. */