@@ -174,22 +174,24 @@ static int32 partition_rbound_datum_cmp(FmgrInfo *partsupfunc,
174
174
Datum * rb_datums , PartitionRangeDatumKind * rb_kind ,
175
175
Datum * tuple_datums , int n_tuple_datums );
176
176
177
- static int partition_list_bsearch (PartitionKey key ,
177
+ static int partition_list_bsearch (FmgrInfo * partsupfunc , Oid * partcollation ,
178
178
PartitionBoundInfo boundinfo ,
179
179
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 ,
181
182
PartitionBoundInfo boundinfo ,
182
183
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 ,
184
186
PartitionBoundInfo boundinfo ,
185
187
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 ,
188
189
int modulus , int remainder );
189
190
190
191
static int get_partition_bound_num_indexes (PartitionBoundInfo b );
191
192
static 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 );
193
195
194
196
/*
195
197
* RelationBuildPartitionDesc
@@ -1004,7 +1006,7 @@ check_new_partition_bound(char *relname, Relation parent,
1004
1006
* boundinfo->datums that is less than or equal to the
1005
1007
* (spec->modulus, spec->remainder) pair.
1006
1008
*/
1007
- offset = partition_hash_bsearch (key , boundinfo ,
1009
+ offset = partition_hash_bsearch (boundinfo ,
1008
1010
spec -> modulus ,
1009
1011
spec -> remainder );
1010
1012
if (offset < 0 )
@@ -1080,7 +1082,9 @@ check_new_partition_bound(char *relname, Relation parent,
1080
1082
int offset ;
1081
1083
bool equal ;
1082
1084
1083
- offset = partition_list_bsearch (key , boundinfo ,
1085
+ offset = partition_list_bsearch (key -> partsupfunc ,
1086
+ key -> partcollation ,
1087
+ boundinfo ,
1084
1088
val -> constvalue ,
1085
1089
& equal );
1086
1090
if (offset >= 0 && equal )
@@ -1155,7 +1159,10 @@ check_new_partition_bound(char *relname, Relation parent,
1155
1159
* since the index array is initialised with an extra -1
1156
1160
* at the end.
1157
1161
*/
1158
- offset = partition_range_bsearch (key , boundinfo , lower ,
1162
+ offset = partition_range_bsearch (key -> partnatts ,
1163
+ key -> partsupfunc ,
1164
+ key -> partcollation ,
1165
+ boundinfo , lower ,
1159
1166
& equal );
1160
1167
1161
1168
if (boundinfo -> indexes [offset + 1 ] < 0 )
@@ -2574,7 +2581,9 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
2574
2581
{
2575
2582
PartitionBoundInfo boundinfo = partdesc -> boundinfo ;
2576
2583
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 );
2578
2587
2579
2588
part_index = boundinfo -> indexes [rowHash % greatest_modulus ];
2580
2589
}
@@ -2590,7 +2599,8 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
2590
2599
{
2591
2600
bool equal = false;
2592
2601
2593
- bound_offset = partition_list_bsearch (key ,
2602
+ bound_offset = partition_list_bsearch (key -> partsupfunc ,
2603
+ key -> partcollation ,
2594
2604
partdesc -> boundinfo ,
2595
2605
values [0 ], & equal );
2596
2606
if (bound_offset >= 0 && equal )
@@ -2619,7 +2629,8 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
2619
2629
2620
2630
if (!range_partkey_has_null )
2621
2631
{
2622
- bound_offset = partition_range_datum_bsearch (key ,
2632
+ bound_offset = partition_range_datum_bsearch (key -> partsupfunc ,
2633
+ key -> partcollation ,
2623
2634
partdesc -> boundinfo ,
2624
2635
key -> partnatts ,
2625
2636
values ,
@@ -2938,7 +2949,7 @@ partition_rbound_datum_cmp(FmgrInfo *partsupfunc, Oid *partcollation,
2938
2949
* to the input value.
2939
2950
*/
2940
2951
static int
2941
- partition_list_bsearch (PartitionKey key ,
2952
+ partition_list_bsearch (FmgrInfo * partsupfunc , Oid * partcollation ,
2942
2953
PartitionBoundInfo boundinfo ,
2943
2954
Datum value , bool * is_equal )
2944
2955
{
@@ -2953,8 +2964,8 @@ partition_list_bsearch(PartitionKey key,
2953
2964
int32 cmpval ;
2954
2965
2955
2966
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 ],
2958
2969
boundinfo -> datums [mid ][0 ],
2959
2970
value ));
2960
2971
if (cmpval <= 0 )
@@ -2981,7 +2992,8 @@ partition_list_bsearch(PartitionKey key,
2981
2992
* to the input range bound
2982
2993
*/
2983
2994
static int
2984
- partition_range_bsearch (PartitionKey key ,
2995
+ partition_range_bsearch (int partnatts , FmgrInfo * partsupfunc ,
2996
+ Oid * partcollation ,
2985
2997
PartitionBoundInfo boundinfo ,
2986
2998
PartitionRangeBound * probe , bool * is_equal )
2987
2999
{
@@ -2996,8 +3008,7 @@ partition_range_bsearch(PartitionKey key,
2996
3008
int32 cmpval ;
2997
3009
2998
3010
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 ,
3001
3012
boundinfo -> datums [mid ],
3002
3013
boundinfo -> kind [mid ],
3003
3014
(boundinfo -> indexes [mid ] == -1 ),
@@ -3026,7 +3037,7 @@ partition_range_bsearch(PartitionKey key,
3026
3037
* to the input tuple.
3027
3038
*/
3028
3039
static int
3029
- partition_range_datum_bsearch (PartitionKey key ,
3040
+ partition_range_datum_bsearch (FmgrInfo * partsupfunc , Oid * partcollation ,
3030
3041
PartitionBoundInfo boundinfo ,
3031
3042
int nvalues , Datum * values , bool * is_equal )
3032
3043
{
@@ -3041,8 +3052,8 @@ partition_range_datum_bsearch(PartitionKey key,
3041
3052
int32 cmpval ;
3042
3053
3043
3054
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 ,
3046
3057
boundinfo -> datums [mid ],
3047
3058
boundinfo -> kind [mid ],
3048
3059
values ,
@@ -3069,8 +3080,7 @@ partition_range_datum_bsearch(PartitionKey key,
3069
3080
* all of them are greater
3070
3081
*/
3071
3082
static int
3072
- partition_hash_bsearch (PartitionKey key ,
3073
- PartitionBoundInfo boundinfo ,
3083
+ partition_hash_bsearch (PartitionBoundInfo boundinfo ,
3074
3084
int modulus , int remainder )
3075
3085
{
3076
3086
int lo ,
@@ -3268,27 +3278,27 @@ get_greatest_modulus(PartitionBoundInfo bound)
3268
3278
* Compute the hash value for given not null partition key values.
3269
3279
*/
3270
3280
static uint64
3271
- compute_hash_value (PartitionKey key , Datum * values , bool * isnull )
3281
+ compute_hash_value (int partnatts , FmgrInfo * partsupfunc ,
3282
+ Datum * values , bool * isnull )
3272
3283
{
3273
3284
int i ;
3274
- int nkeys = key -> partnatts ;
3275
3285
uint64 rowHash = 0 ;
3276
3286
Datum seed = UInt64GetDatum (HASH_PARTITION_SEED );
3277
3287
3278
- for (i = 0 ; i < nkeys ; i ++ )
3288
+ for (i = 0 ; i < partnatts ; i ++ )
3279
3289
{
3280
3290
if (!isnull [i ])
3281
3291
{
3282
3292
Datum hash ;
3283
3293
3284
- Assert (OidIsValid (key -> partsupfunc [i ].fn_oid ));
3294
+ Assert (OidIsValid (partsupfunc [i ].fn_oid ));
3285
3295
3286
3296
/*
3287
3297
* Compute hash for each datum value by calling respective
3288
3298
* datatype-specific hash functions of each partition key
3289
3299
* attribute.
3290
3300
*/
3291
- hash = FunctionCall2 (& key -> partsupfunc [i ], values [i ], seed );
3301
+ hash = FunctionCall2 (& partsupfunc [i ], values [i ], seed );
3292
3302
3293
3303
/* Form a single 64-bit hash value */
3294
3304
rowHash = hash_combine64 (rowHash , DatumGetUInt64 (hash ));
0 commit comments