Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 032f9ae

Browse files
author
Etsuro Fujita
committed
Avoid redundant checks in partition_bounds_copy().
Previously, partition_bounds_copy() checked whether the strategy for the given partition bounds was hash or not, and then determined the number of elements in the datums in the datums array for the partition bounds, on each iteration of the loop for copying the datums array, but there is no need to do that. Perform the checks only once before the loop iteration. Author: Etsuro Fujita Reported-by: Amit Langote and Julien Rouhaud Discussion: https://postgr.es/m/CAPmGK14Rvxrm8DHWvCjdoks6nwZuHBPvMnWZ6rkEx2KhFeEoPQ@mail.gmail.com
1 parent 9573384 commit 032f9ae

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/backend/partitioning/partbounds.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ partition_bounds_copy(PartitionBoundInfo src,
789789
int ndatums;
790790
int partnatts;
791791
int num_indexes;
792+
bool hash_part;
793+
int natts;
792794

793795
dest = (PartitionBoundInfo) palloc(sizeof(PartitionBoundInfoData));
794796

@@ -819,17 +821,17 @@ partition_bounds_copy(PartitionBoundInfo src,
819821
else
820822
dest->kind = NULL;
821823

824+
/*
825+
* For hash partitioning, datums array will have two elements - modulus and
826+
* remainder.
827+
*/
828+
hash_part = (key->strategy == PARTITION_STRATEGY_HASH);
829+
natts = hash_part ? 2 : partnatts;
830+
822831
for (i = 0; i < ndatums; i++)
823832
{
824833
int j;
825834

826-
/*
827-
* For a corresponding hash partition, datums array will have two
828-
* elements - modulus and remainder.
829-
*/
830-
bool hash_part = (key->strategy == PARTITION_STRATEGY_HASH);
831-
int natts = hash_part ? 2 : partnatts;
832-
833835
dest->datums[i] = (Datum *) palloc(sizeof(Datum) * natts);
834836

835837
for (j = 0; j < natts; j++)

0 commit comments

Comments
 (0)