@@ -303,21 +303,18 @@ RelationBuildPartitionDesc(Relation rel)
303303}
304304else if (key -> strategy == PARTITION_STRATEGY_RANGE )
305305{
306- int j ,
307- k ;
306+ int k ;
308307PartitionRangeBound * * all_bounds ,
309308* prev ;
310- bool * distinct_indexes ;
311309
312310all_bounds = (PartitionRangeBound * * )palloc0 (2 * nparts *
313311sizeof (PartitionRangeBound * ));
314- distinct_indexes = (bool * )palloc (2 * nparts * sizeof (bool ));
315312
316313/*
317314 * Create a unified list of range bounds across all the
318315 * partitions.
319316 */
320- i = j = 0 ;
317+ i = ndatums = 0 ;
321318foreach (cell ,boundspecs )
322319{
323320PartitionBoundSpec * spec = castNode (PartitionBoundSpec ,
@@ -332,26 +329,25 @@ RelationBuildPartitionDesc(Relation rel)
332329 true);
333330upper = make_one_range_bound (key ,i ,spec -> upperdatums ,
334331 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 ;
338334i ++ ;
339335}
340- Assert (j == 2 * nparts );
336+
337+ Assert (ndatums == nparts * 2 );
341338
342339/* Sort all the bounds in ascending order */
343340qsort_arg (all_bounds ,2 * nparts ,
344341sizeof (PartitionRangeBound * ),
345342qsort_partition_rbound_cmp ,
346343 (void * )key );
347344
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 ;
353349prev = NULL ;
354- for (i = 0 ;i < 2 * nparts ;i ++ )
350+ for (i = 0 ;i < ndatums ;i ++ )
355351{
356352PartitionRangeBound * cur = all_bounds [i ];
357353bool is_distinct = false;
@@ -388,34 +384,18 @@ RelationBuildPartitionDesc(Relation rel)
388384}
389385
390386/*
391- *Count thecurrent boundif it is distinctfrom 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 distinctsave it into a temporary
388+ *array i.e. rbounds which is later copied into boundinfo
389+ *datums array.
394390 */
395391if (is_distinct )
396- {
397- distinct_indexes [i ]= true;
398- ndatums ++ ;
399- }
400- else
401- distinct_indexes [i ]= false;
392+ rbounds [k ++ ]= all_bounds [i ];
402393
403394prev = cur ;
404395}
405396
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 ;
419399}
420400else
421401elog (ERROR ,"unexpected partition strategy: %d" ,