@@ -70,15 +70,12 @@ static int32 qsort_partition_list_value_cmp(const void *a, const void *b,
7070void * arg );
7171static int32 qsort_partition_rbound_cmp (const void * a ,const void * b ,
7272void * 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 );
8279static PartitionRangeBound * make_one_partition_rbound (PartitionKey key ,int index ,
8380List * datums ,bool lower );
8481static int32 partition_hbound_cmp (int modulus1 ,int remainder1 ,int modulus2 ,
@@ -169,9 +166,9 @@ get_qual_from_partbound(Relation rel, Relation parent,
169166 * current memory context.
170167 */
171168PartitionBoundInfo
172- partition_bounds_create (List * boundspecs ,PartitionKey key ,int * * mapping )
169+ partition_bounds_create (PartitionBoundSpec * * boundspecs ,int nparts ,
170+ PartitionKey key ,int * * mapping )
173171{
174- int nparts = list_length (boundspecs );
175172int i ;
176173
177174Assert (nparts > 0 );
@@ -199,13 +196,13 @@ partition_bounds_create(List *boundspecs, PartitionKey key, int **mapping)
199196switch (key -> strategy )
200197{
201198case PARTITION_STRATEGY_HASH :
202- return create_hash_bounds (boundspecs ,key ,mapping );
199+ return create_hash_bounds (boundspecs ,nparts , key ,mapping );
203200
204201case PARTITION_STRATEGY_LIST :
205- return create_list_bounds (boundspecs ,key ,mapping );
202+ return create_list_bounds (boundspecs ,nparts , key ,mapping );
206203
207204case PARTITION_STRATEGY_RANGE :
208- return create_range_bounds (boundspecs ,key ,mapping );
205+ return create_range_bounds (boundspecs ,nparts , key ,mapping );
209206
210207default :
211208elog (ERROR ,"unexpected partition strategy: %d" ,
@@ -222,13 +219,12 @@ partition_bounds_create(List *boundspecs, PartitionKey key, int **mapping)
222219 *Create a PartitionBoundInfo for a hash partitioned table
223220 */
224221static PartitionBoundInfo
225- create_hash_bounds (List * boundspecs ,PartitionKey key ,int * * mapping )
222+ create_hash_bounds (PartitionBoundSpec * * boundspecs ,int nparts ,
223+ PartitionKey key ,int * * mapping )
226224{
227225PartitionBoundInfo boundinfo ;
228226PartitionHashBound * * hbounds = NULL ;
229- ListCell * cell ;
230- int i ,
231- nparts = list_length (boundspecs );
227+ int i ;
232228int ndatums = 0 ;
233229int greatest_modulus ;
234230
@@ -244,10 +240,9 @@ create_hash_bounds(List *boundspecs, PartitionKey key, int **mapping)
244240palloc (nparts * sizeof (PartitionHashBound * ));
245241
246242/* Convert from node to the internal representation */
247- i = 0 ;
248- foreach (cell ,boundspecs )
243+ for (i = 0 ;i < nparts ;i ++ )
249244{
250- PartitionBoundSpec * spec = castNode ( PartitionBoundSpec , lfirst ( cell )) ;
245+ PartitionBoundSpec * spec = boundspecs [ i ] ;
251246
252247if (spec -> strategy != PARTITION_STRATEGY_HASH )
253248elog (ERROR ,"invalid strategy in partition bound spec" );
@@ -256,7 +251,6 @@ create_hash_bounds(List *boundspecs, PartitionKey key, int **mapping)
256251hbounds [i ]-> modulus = spec -> modulus ;
257252hbounds [i ]-> remainder = spec -> remainder ;
258253hbounds [i ]-> index = i ;
259- i ++ ;
260254}
261255
262256/* Sort all the bounds in ascending order */
@@ -307,7 +301,8 @@ create_hash_bounds(List *boundspecs, PartitionKey key, int **mapping)
307301 *Create a PartitionBoundInfo for a list partitioned table
308302 */
309303static PartitionBoundInfo
310- create_list_bounds (List * boundspecs ,PartitionKey key ,int * * mapping )
304+ create_list_bounds (PartitionBoundSpec * * boundspecs ,int nparts ,
305+ PartitionKey key ,int * * mapping )
311306{
312307PartitionBoundInfo boundinfo ;
313308PartitionListValue * * all_values = NULL ;
@@ -327,9 +322,9 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
327322boundinfo -> default_index = -1 ;
328323
329324/* Create a unified list of non-null values across all partitions. */
330- foreach ( cell , boundspecs )
325+ for ( i = 0 ; i < nparts ; i ++ )
331326{
332- PartitionBoundSpec * spec = castNode ( PartitionBoundSpec , lfirst ( cell )) ;
327+ PartitionBoundSpec * spec = boundspecs [ i ] ;
333328ListCell * c ;
334329
335330if (spec -> strategy != PARTITION_STRATEGY_LIST )
@@ -343,7 +338,6 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
343338if (spec -> is_default )
344339{
345340default_index = i ;
346- i ++ ;
347341continue ;
348342}
349343
@@ -374,8 +368,6 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
374368if (list_value )
375369non_null_values = lappend (non_null_values ,list_value );
376370}
377-
378- i ++ ;
379371}
380372
381373ndatums = list_length (non_null_values );
@@ -458,7 +450,7 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
458450}
459451
460452/* All partition must now have been assigned canonical indexes. */
461- Assert (next_index == list_length ( boundspecs ) );
453+ Assert (next_index == nparts );
462454return boundinfo ;
463455}
464456
@@ -467,16 +459,15 @@ create_list_bounds(List *boundspecs, PartitionKey key, int **mapping)
467459 *Create a PartitionBoundInfo for a range partitioned table
468460 */
469461static PartitionBoundInfo
470- create_range_bounds (List * boundspecs ,PartitionKey key ,int * * mapping )
462+ create_range_bounds (PartitionBoundSpec * * boundspecs ,int nparts ,
463+ PartitionKey key ,int * * mapping )
471464{
472465PartitionBoundInfo boundinfo ;
473466PartitionRangeBound * * rbounds = NULL ;
474467PartitionRangeBound * * all_bounds ,
475468* prev ;
476- ListCell * cell ;
477469int i ,
478- k ,
479- nparts = list_length (boundspecs );
470+ k ;
480471int ndatums = 0 ;
481472int default_index = -1 ;
482473int next_index = 0 ;
@@ -493,10 +484,10 @@ create_range_bounds(List *boundspecs, PartitionKey key, int **mapping)
493484palloc0 (2 * nparts * sizeof (PartitionRangeBound * ));
494485
495486/* 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 ++ )
498489{
499- PartitionBoundSpec * spec = castNode ( PartitionBoundSpec , lfirst ( cell )) ;
490+ PartitionBoundSpec * spec = boundspecs [ i ] ;
500491PartitionRangeBound * lower ,
501492* upper ;
502493
@@ -510,15 +501,14 @@ create_range_bounds(List *boundspecs, PartitionKey key, int **mapping)
510501 */
511502if (spec -> is_default )
512503{
513- default_index = i ++ ;
504+ default_index = i ;
514505continue ;
515506}
516507
517508lower = make_one_partition_rbound (key ,i ,spec -> lowerdatums , true);
518509upper = make_one_partition_rbound (key ,i ,spec -> upperdatums , false);
519510all_bounds [ndatums ++ ]= lower ;
520511all_bounds [ndatums ++ ]= upper ;
521- i ++ ;
522512}
523513
524514Assert (ndatums == nparts * 2 ||