@@ -303,21 +303,18 @@ RelationBuildPartitionDesc(Relation rel)
303
303
}
304
304
else if (key -> strategy == PARTITION_STRATEGY_RANGE )
305
305
{
306
- int j ,
307
- k ;
306
+ int k ;
308
307
PartitionRangeBound * * all_bounds ,
309
308
* prev ;
310
- bool * distinct_indexes ;
311
309
312
310
all_bounds = (PartitionRangeBound * * ) palloc0 (2 * nparts *
313
311
sizeof (PartitionRangeBound * ));
314
- distinct_indexes = (bool * ) palloc (2 * nparts * sizeof (bool ));
315
312
316
313
/*
317
314
* Create a unified list of range bounds across all the
318
315
* partitions.
319
316
*/
320
- i = j = 0 ;
317
+ i = ndatums = 0 ;
321
318
foreach (cell , boundspecs )
322
319
{
323
320
PartitionBoundSpec * spec = castNode (PartitionBoundSpec ,
@@ -332,26 +329,25 @@ RelationBuildPartitionDesc(Relation rel)
332
329
true);
333
330
upper = make_one_range_bound (key , i , spec -> upperdatums ,
334
331
false);
335
- all_bounds [j ] = lower ;
336
- all_bounds [j + 1 ] = upper ;
337
- j += 2 ;
332
+ all_bounds [ndatums ++ ] = lower ;
333
+ all_bounds [ndatums ++ ] = upper ;
338
334
i ++ ;
339
335
}
340
- Assert (j == 2 * nparts );
336
+
337
+ Assert (ndatums == nparts * 2 );
341
338
342
339
/* Sort all the bounds in ascending order */
343
340
qsort_arg (all_bounds , 2 * nparts ,
344
341
sizeof (PartitionRangeBound * ),
345
342
qsort_partition_rbound_cmp ,
346
343
(void * ) key );
347
344
348
- /*
349
- * Count the number of distinct bounds to allocate an array of
350
- * that size.
351
- */
352
- ndatums = 0 ;
345
+ /* Save distinct bounds from all_bounds into rbounds. */
346
+ rbounds = (PartitionRangeBound * * )
347
+ palloc (ndatums * sizeof (PartitionRangeBound * ));
348
+ k = 0 ;
353
349
prev = NULL ;
354
- for (i = 0 ; i < 2 * nparts ; i ++ )
350
+ for (i = 0 ; i < ndatums ; i ++ )
355
351
{
356
352
PartitionRangeBound * cur = all_bounds [i ];
357
353
bool is_distinct = false;
@@ -388,34 +384,18 @@ RelationBuildPartitionDesc(Relation rel)
388
384
}
389
385
390
386
/*
391
- * Count the current bound if it is distinct from the previous
392
- * one. Also, store if the index i contains a distinct bound
393
- * that we'd like put in the relcache array.
387
+ * Only if the bound is distinct save it into a temporary
388
+ * array i.e. rbounds which is later copied into boundinfo
389
+ * datums array.
394
390
*/
395
391
if (is_distinct )
396
- {
397
- distinct_indexes [i ] = true;
398
- ndatums ++ ;
399
- }
400
- else
401
- distinct_indexes [i ] = false;
392
+ rbounds [k ++ ] = all_bounds [i ];
402
393
403
394
prev = cur ;
404
395
}
405
396
406
- /*
407
- * Finally save them in an array from where they will be copied
408
- * into the relcache.
409
- */
410
- rbounds = (PartitionRangeBound * * ) palloc (ndatums *
411
- sizeof (PartitionRangeBound * ));
412
- k = 0 ;
413
- for (i = 0 ; i < 2 * nparts ; i ++ )
414
- {
415
- if (distinct_indexes [i ])
416
- rbounds [k ++ ] = all_bounds [i ];
417
- }
418
- Assert (k == ndatums );
397
+ /* Update ndatums to hold the count of distinct datums. */
398
+ ndatums = k ;
419
399
}
420
400
else
421
401
elog (ERROR , "unexpected partition strategy: %d" ,
0 commit comments