@@ -174,22 +174,24 @@ static int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc,
174174 Datum * rb_datums , PartitionRangeDatumKind * rb_kind ,
175175 Datum * tuple_datums , int n_tuple_datums );
176176
177- static int partition_list_bsearch (PartitionKey key ,
177+ static int partition_list_bsearch (FmgrInfo * partsupfunc , Oid * partcollation ,
178178 PartitionBoundInfo boundinfo ,
179179 Datum value , bool * is_equal );
180- static int partition_range_bsearch (PartitionKey key ,
180+ static int partition_range_bsearch (int partnatts , FmgrInfo * partsupfunc ,
181+ Oid * partcollation ,
181182 PartitionBoundInfo boundinfo ,
182183 PartitionRangeBound * probe , bool * is_equal );
183- static int partition_range_datum_bsearch (PartitionKey key ,
184+ static int partition_range_datum_bsearch (FmgrInfo * partsupfunc ,
185+ Oid * partcollation ,
184186 PartitionBoundInfo boundinfo ,
185187 int nvalues , Datum * values , bool * is_equal );
186- static int partition_hash_bsearch (PartitionKey key ,
187- PartitionBoundInfo boundinfo ,
188+ static int partition_hash_bsearch (PartitionBoundInfo boundinfo ,
188189 int modulus , int remainder );
189190
190191static int get_partition_bound_num_indexes (PartitionBoundInfo b );
191192static int get_greatest_modulus (PartitionBoundInfo b );
192- static uint64 compute_hash_value (PartitionKey key , Datum * values , bool * isnull );
193+ static uint64 compute_hash_value (int partnatts , FmgrInfo * partsupfunc ,
194+ Datum * values , bool * isnull );
193195
194196/*
195197 * RelationBuildPartitionDesc
@@ -1004,7 +1006,7 @@ check_new_partition_bound(char *relname, Relation parent,
10041006 * boundinfo->datums that is less than or equal to the
10051007 * (spec->modulus, spec->remainder) pair.
10061008 */
1007- offset = partition_hash_bsearch (key , boundinfo ,
1009+ offset = partition_hash_bsearch (boundinfo ,
10081010 spec -> modulus ,
10091011 spec -> remainder );
10101012 if (offset < 0 )
@@ -1080,7 +1082,9 @@ check_new_partition_bound(char *relname, Relation parent,
10801082 int offset ;
10811083 bool equal ;
10821084
1083- offset = partition_list_bsearch (key , boundinfo ,
1085+ offset = partition_list_bsearch (key -> partsupfunc ,
1086+ key -> partcollation ,
1087+ boundinfo ,
10841088 val -> constvalue ,
10851089 & equal );
10861090 if (offset >= 0 && equal )
@@ -1155,7 +1159,10 @@ check_new_partition_bound(char *relname, Relation parent,
11551159 * since the index array is initialised with an extra -1
11561160 * at the end.
11571161 */
1158- offset = partition_range_bsearch (key , boundinfo , lower ,
1162+ offset = partition_range_bsearch (key -> partnatts ,
1163+ key -> partsupfunc ,
1164+ key -> partcollation ,
1165+ boundinfo , lower ,
11591166 & equal );
11601167
11611168 if (boundinfo -> indexes [offset + 1 ] < 0 )
@@ -2574,7 +2581,9 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
25742581 {
25752582 PartitionBoundInfo boundinfo = partdesc -> boundinfo ;
25762583 int greatest_modulus = get_greatest_modulus (boundinfo );
2577- uint64 rowHash = compute_hash_value (key , values , isnull );
2584+ uint64 rowHash = compute_hash_value (key -> partnatts ,
2585+ key -> partsupfunc ,
2586+ values , isnull );
25782587
25792588 part_index = boundinfo -> indexes [rowHash % greatest_modulus ];
25802589 }
@@ -2590,7 +2599,8 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
25902599 {
25912600 bool equal = false;
25922601
2593- bound_offset = partition_list_bsearch (key ,
2602+ bound_offset = partition_list_bsearch (key -> partsupfunc ,
2603+ key -> partcollation ,
25942604 partdesc -> boundinfo ,
25952605 values [0 ], & equal );
25962606 if (bound_offset >= 0 && equal )
@@ -2619,7 +2629,8 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
26192629
26202630 if (!range_partkey_has_null )
26212631 {
2622- bound_offset = partition_range_datum_bsearch (key ,
2632+ bound_offset = partition_range_datum_bsearch (key -> partsupfunc ,
2633+ key -> partcollation ,
26232634 partdesc -> boundinfo ,
26242635 key -> partnatts ,
26252636 values ,
@@ -2938,7 +2949,7 @@ partition_rbound_datum_cmp(FmgrInfo *partsupfunc, Oid *partcollation,
29382949 * to the input value.
29392950 */
29402951static int
2941- partition_list_bsearch (PartitionKey key ,
2952+ partition_list_bsearch (FmgrInfo * partsupfunc , Oid * partcollation ,
29422953 PartitionBoundInfo boundinfo ,
29432954 Datum value , bool * is_equal )
29442955{
@@ -2953,8 +2964,8 @@ partition_list_bsearch(PartitionKey key,
29532964 int32 cmpval ;
29542965
29552966 mid = (lo + hi + 1 ) / 2 ;
2956- cmpval = DatumGetInt32 (FunctionCall2Coll (& key -> partsupfunc [0 ],
2957- key -> partcollation [0 ],
2967+ cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [0 ],
2968+ partcollation [0 ],
29582969 boundinfo -> datums [mid ][0 ],
29592970 value ));
29602971 if (cmpval <= 0 )
@@ -2981,7 +2992,8 @@ partition_list_bsearch(PartitionKey key,
29812992 * to the input range bound
29822993 */
29832994static int
2984- partition_range_bsearch (PartitionKey key ,
2995+ partition_range_bsearch (int partnatts , FmgrInfo * partsupfunc ,
2996+ Oid * partcollation ,
29852997 PartitionBoundInfo boundinfo ,
29862998 PartitionRangeBound * probe , bool * is_equal )
29872999{
@@ -2996,8 +3008,7 @@ partition_range_bsearch(PartitionKey key,
29963008 int32 cmpval ;
29973009
29983010 mid = (lo + hi + 1 ) / 2 ;
2999- cmpval = partition_rbound_cmp (key -> partnatts , key -> partsupfunc ,
3000- key -> partcollation ,
3011+ cmpval = partition_rbound_cmp (partnatts , partsupfunc , partcollation ,
30013012 boundinfo -> datums [mid ],
30023013 boundinfo -> kind [mid ],
30033014 (boundinfo -> indexes [mid ] == -1 ),
@@ -3026,7 +3037,7 @@ partition_range_bsearch(PartitionKey key,
30263037 * to the input tuple.
30273038 */
30283039static int
3029- partition_range_datum_bsearch (PartitionKey key ,
3040+ partition_range_datum_bsearch (FmgrInfo * partsupfunc , Oid * partcollation ,
30303041 PartitionBoundInfo boundinfo ,
30313042 int nvalues , Datum * values , bool * is_equal )
30323043{
@@ -3041,8 +3052,8 @@ partition_range_datum_bsearch(PartitionKey key,
30413052 int32 cmpval ;
30423053
30433054 mid = (lo + hi + 1 ) / 2 ;
3044- cmpval = partition_rbound_datum_cmp (key -> partsupfunc ,
3045- key -> partcollation ,
3055+ cmpval = partition_rbound_datum_cmp (partsupfunc ,
3056+ partcollation ,
30463057 boundinfo -> datums [mid ],
30473058 boundinfo -> kind [mid ],
30483059 values ,
@@ -3069,8 +3080,7 @@ partition_range_datum_bsearch(PartitionKey key,
30693080 * all of them are greater
30703081 */
30713082static int
3072- partition_hash_bsearch (PartitionKey key ,
3073- PartitionBoundInfo boundinfo ,
3083+ partition_hash_bsearch (PartitionBoundInfo boundinfo ,
30743084 int modulus , int remainder )
30753085{
30763086 int lo ,
@@ -3268,27 +3278,27 @@ get_greatest_modulus(PartitionBoundInfo bound)
32683278 * Compute the hash value for given not null partition key values.
32693279 */
32703280static uint64
3271- compute_hash_value (PartitionKey key , Datum * values , bool * isnull )
3281+ compute_hash_value (int partnatts , FmgrInfo * partsupfunc ,
3282+ Datum * values , bool * isnull )
32723283{
32733284 int i ;
3274- int nkeys = key -> partnatts ;
32753285 uint64 rowHash = 0 ;
32763286 Datum seed = UInt64GetDatum (HASH_PARTITION_SEED );
32773287
3278- for (i = 0 ; i < nkeys ; i ++ )
3288+ for (i = 0 ; i < partnatts ; i ++ )
32793289 {
32803290 if (!isnull [i ])
32813291 {
32823292 Datum hash ;
32833293
3284- Assert (OidIsValid (key -> partsupfunc [i ].fn_oid ));
3294+ Assert (OidIsValid (partsupfunc [i ].fn_oid ));
32853295
32863296 /*
32873297 * Compute hash for each datum value by calling respective
32883298 * datatype-specific hash functions of each partition key
32893299 * attribute.
32903300 */
3291- hash = FunctionCall2 (& key -> partsupfunc [i ], values [i ], seed );
3301+ hash = FunctionCall2 (& partsupfunc [i ], values [i ], seed );
32923302
32933303 /* Form a single 64-bit hash value */
32943304 rowHash = hash_combine64 (rowHash , DatumGetUInt64 (hash ));
0 commit comments