From 9d8782e0213fea5d677a00abe78bd406bfc231fa Mon Sep 17 00:00:00 2001 From: Nitin Date: Tue, 18 May 2021 22:40:04 +0530 Subject: [PATCH 3/5] Same-for-create_hash_bounds-PartitionHashBound --- src/backend/partitioning/partbounds.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index f91efba..5cf7672 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -358,7 +358,7 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, PartitionKey key, int **mapping) { PartitionBoundInfo boundinfo; - PartitionHashBound **hbounds = NULL; + PartitionHashBound *hbounds; int i; int ndatums = 0; int greatest_modulus; @@ -371,8 +371,8 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, boundinfo->default_index = -1; ndatums = nparts; - hbounds = (PartitionHashBound **) - palloc(nparts * sizeof(PartitionHashBound *)); + hbounds = (PartitionHashBound *) + palloc(nparts * sizeof(PartitionHashBound)); /* Convert from node to the internal representation */ for (i = 0; i < nparts; i++) @@ -382,18 +382,17 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, if (spec->strategy != PARTITION_STRATEGY_HASH) elog(ERROR, "invalid strategy in partition bound spec"); - hbounds[i] = (PartitionHashBound *) palloc(sizeof(PartitionHashBound)); - hbounds[i]->modulus = spec->modulus; - hbounds[i]->remainder = spec->remainder; - hbounds[i]->index = i; + hbounds[i].modulus = spec->modulus; + hbounds[i].remainder = spec->remainder; + hbounds[i].index = i; } /* Sort all the bounds in ascending order */ - qsort(hbounds, nparts, sizeof(PartitionHashBound *), + qsort(hbounds, nparts, sizeof(PartitionHashBound), qsort_partition_hbound_cmp); /* After sorting, moduli are now stored in ascending order. */ - greatest_modulus = hbounds[ndatums - 1]->modulus; + greatest_modulus = hbounds[ndatums - 1].modulus; boundinfo->ndatums = ndatums; boundinfo->datums = (Datum **) palloc0(ndatums * sizeof(Datum *)); @@ -409,8 +408,8 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, */ for (i = 0; i < nparts; i++) { - int modulus = hbounds[i]->modulus; - int remainder = hbounds[i]->remainder; + int modulus = hbounds[i].modulus; + int remainder = hbounds[i].remainder; boundinfo->datums[i] = (Datum *) palloc(2 * sizeof(Datum)); boundinfo->datums[i][0] = Int32GetDatum(modulus); @@ -424,8 +423,7 @@ create_hash_bounds(PartitionBoundSpec **boundspecs, int nparts, remainder += modulus; } - (*mapping)[hbounds[i]->index] = i; - pfree(hbounds[i]); + (*mapping)[hbounds[i].index] = i; } pfree(hbounds); @@ -3676,8 +3674,8 @@ partition_hash_bsearch(PartitionBoundInfo boundinfo, static int32 qsort_partition_hbound_cmp(const void *a, const void *b) { - PartitionHashBound *h1 = (*(PartitionHashBound *const *) a); - PartitionHashBound *h2 = (*(PartitionHashBound *const *) b); + PartitionHashBound *const h1 = (PartitionHashBound *const) a; + PartitionHashBound *const h2 = (PartitionHashBound *const) b; return partition_hbound_cmp(h1->modulus, h1->remainder, h2->modulus, h2->remainder); -- 1.8.3.1