@@ -70,15 +70,12 @@ static int32 qsort_partition_list_value_cmp(const void *a, const void *b,
70
70
void * arg );
71
71
static int32 qsort_partition_rbound_cmp (const void * a , const void * b ,
72
72
void * arg );
73
- static PartitionBoundInfo create_hash_bounds (List * boundspecs ,
74
- PartitionKey key ,
75
- int * * mapping );
76
- static PartitionBoundInfo create_list_bounds (List * boundspecs ,
77
- PartitionKey key ,
78
- int * * mapping );
79
- static PartitionBoundInfo create_range_bounds (List * boundspecs ,
80
- PartitionKey key ,
81
- int * * mapping );
73
+ static PartitionBoundInfo create_hash_bounds (PartitionBoundSpec * * boundspecs ,
74
+ int nparts , PartitionKey key , int * * mapping );
75
+ static PartitionBoundInfo create_list_bounds (PartitionBoundSpec * * boundspecs ,
76
+ int nparts , PartitionKey key , int * * mapping );
77
+ static PartitionBoundInfo create_range_bounds (PartitionBoundSpec * * boundspecs ,
78
+ int nparts , PartitionKey key , int * * mapping );
82
79
static PartitionRangeBound * make_one_partition_rbound (PartitionKey key , int index ,
83
80
List * datums , bool lower );
84
81
static int32 partition_hbound_cmp (int modulus1 , int remainder1 , int modulus2 ,
@@ -169,9 +166,9 @@ get_qual_from_partbound(Relation rel, Relation parent,
169
166
* current memory context.
170
167
*/
171
168
PartitionBoundInfo
172
- partition_bounds_create (List * boundspecs , PartitionKey key , int * * mapping )
169
+ partition_bounds_create (PartitionBoundSpec * * boundspecs , int nparts ,
170
+ PartitionKey key , int * * mapping )
173
171
{
174
- int nparts = list_length (boundspecs );
175
172
int i ;
176
173
177
174
Assert (nparts > 0 );
@@ -199,13 +196,13 @@ partition_bounds_create(List *boundspecs, PartitionKey key, int **mapping)
199
196
switch (key -> strategy )
200
197
{
201
198
case PARTITION_STRATEGY_HASH :
202
- return create_hash_bounds (boundspecs , key , mapping );
199
+ return create_hash_bounds (boundspecs , nparts , key , mapping );
203
200
204
201
case PARTITION_STRATEGY_LIST :
205
- return create_list_bounds (boundspecs , key , mapping );
202
+ return create_list_bounds (boundspecs , nparts , key , mapping );
206
203
207
204
case PARTITION_STRATEGY_RANGE :
208
- return create_range_bounds (boundspecs , key , mapping );
205
+ return create_range_bounds (boundspecs , nparts , key , mapping );
209
206
210
207
default :
211
208
elog (ERROR , "unexpected partition strategy: %d" ,
@@ -222,13 +219,12 @@ partition_bounds_create(List *boundspecs, PartitionKey key, int **mapping)
222
219
* Create a PartitionBoundInfo for a hash partitioned table
223
220
*/
224
221
static PartitionBoundInfo
225
- create_hash_bounds (List * boundspecs , PartitionKey key , int * * mapping )
222
+ create_hash_bounds (PartitionBoundSpec * * boundspecs , int nparts ,
223
+ PartitionKey key , int * * mapping )
226
224
{
227
225
PartitionBoundInfo boundinfo ;
228
226
PartitionHashBound * * hbounds = NULL ;
229
- ListCell * cell ;
230
- int i ,
231
- nparts = list_length (boundspecs );
227
+ int i ;
232
228
int ndatums = 0 ;
233
229
int greatest_modulus ;
234
230
@@ -244,10 +240,9 @@ create_hash_bounds(List *boundspecs, PartitionKey key, int **mapping)
244
240
palloc (nparts * sizeof (PartitionHashBound * ));
245
241
246
242
/* Convert from node to the internal representation */
247
- i = 0 ;
248
- foreach (cell , boundspecs )
243
+ for (i = 0 ; i < nparts ; i ++ )
249
244
{
250
- PartitionBoundSpec * spec = castNode ( PartitionBoundSpec , lfirst ( cell )) ;
245
+ PartitionBoundSpec * spec = boundspecs [ i ] ;
251
246
252
247
if (spec -> strategy != PARTITION_STRATEGY_HASH )
253
248
elog (ERROR , "invalid strategy in partition bound spec" );
@@ -256,7 +251,6 @@ create_hash_bounds(List *boundspecs, PartitionKey key, int **mapping)
256
251
hbounds [i ]-> modulus = spec -> modulus ;
257
252
hbounds [i ]-> remainder = spec -> remainder ;
258
253
hbounds [i ]-> index = i ;
259
- i ++ ;
260
254
}
261
255
262
256
/* Sort all the bounds in ascending order */
@@ -307,7 +301,8 @@ create_hash_bounds(List *boundspecs, PartitionKey key, int **mapping)
307
301
* Create a PartitionBoundInfo for a list partitioned table
308
302
*/
309
303
static PartitionBoundInfo
310
- create_list_bounds (List * boundspecs , PartitionKey key , int * * mapping )
304
+ create_list_bounds (PartitionBoundSpec * * boundspecs , int nparts ,
305
+ PartitionKey key , int * * mapping )
311
306
{
312
307
PartitionBoundInfo boundinfo ;
313
308
PartitionListValue * * all_values = NULL ;
@@ -327,9 +322,9 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
327
322
boundinfo -> default_index = -1 ;
328
323
329
324
/* Create a unified list of non-null values across all partitions. */
330
- foreach ( cell , boundspecs )
325
+ for ( i = 0 ; i < nparts ; i ++ )
331
326
{
332
- PartitionBoundSpec * spec = castNode ( PartitionBoundSpec , lfirst ( cell )) ;
327
+ PartitionBoundSpec * spec = boundspecs [ i ] ;
333
328
ListCell * c ;
334
329
335
330
if (spec -> strategy != PARTITION_STRATEGY_LIST )
@@ -343,7 +338,6 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
343
338
if (spec -> is_default )
344
339
{
345
340
default_index = i ;
346
- i ++ ;
347
341
continue ;
348
342
}
349
343
@@ -374,8 +368,6 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
374
368
if (list_value )
375
369
non_null_values = lappend (non_null_values , list_value );
376
370
}
377
-
378
- i ++ ;
379
371
}
380
372
381
373
ndatums = list_length (non_null_values );
@@ -458,7 +450,7 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
458
450
}
459
451
460
452
/* All partition must now have been assigned canonical indexes. */
461
- Assert (next_index == list_length ( boundspecs ) );
453
+ Assert (next_index == nparts );
462
454
return boundinfo ;
463
455
}
464
456
@@ -467,16 +459,15 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
467
459
* Create a PartitionBoundInfo for a range partitioned table
468
460
*/
469
461
static PartitionBoundInfo
470
- create_range_bounds (List * boundspecs , PartitionKey key , int * * mapping )
462
+ create_range_bounds (PartitionBoundSpec * * boundspecs , int nparts ,
463
+ PartitionKey key , int * * mapping )
471
464
{
472
465
PartitionBoundInfo boundinfo ;
473
466
PartitionRangeBound * * rbounds = NULL ;
474
467
PartitionRangeBound * * all_bounds ,
475
468
* prev ;
476
- ListCell * cell ;
477
469
int i ,
478
- k ,
479
- nparts = list_length (boundspecs );
470
+ k ;
480
471
int ndatums = 0 ;
481
472
int default_index = -1 ;
482
473
int next_index = 0 ;
@@ -493,10 +484,10 @@ create_range_bounds(List *boundspecs, PartitionKey key, int **mapping)
493
484
palloc0 (2 * nparts * sizeof (PartitionRangeBound * ));
494
485
495
486
/* Create a unified list of range bounds across all the partitions. */
496
- i = ndatums = 0 ;
497
- foreach ( cell , boundspecs )
487
+ ndatums = 0 ;
488
+ for ( i = 0 ; i < nparts ; i ++ )
498
489
{
499
- PartitionBoundSpec * spec = castNode ( PartitionBoundSpec , lfirst ( cell )) ;
490
+ PartitionBoundSpec * spec = boundspecs [ i ] ;
500
491
PartitionRangeBound * lower ,
501
492
* upper ;
502
493
@@ -510,15 +501,14 @@ create_range_bounds(List *boundspecs, PartitionKey key, int **mapping)
510
501
*/
511
502
if (spec -> is_default )
512
503
{
513
- default_index = i ++ ;
504
+ default_index = i ;
514
505
continue ;
515
506
}
516
507
517
508
lower = make_one_partition_rbound (key , i , spec -> lowerdatums , true);
518
509
upper = make_one_partition_rbound (key , i , spec -> upperdatums , false);
519
510
all_bounds [ndatums ++ ] = lower ;
520
511
all_bounds [ndatums ++ ] = upper ;
521
- i ++ ;
522
512
}
523
513
524
514
Assert (ndatums == nparts * 2 ||
0 commit comments