@@ -165,10 +165,12 @@ static PartitionRangeBound *make_one_range_bound(PartitionKey key, int index,
165
165
List * datums , bool lower );
166
166
static int32 partition_hbound_cmp (int modulus1 , int remainder1 , int modulus2 ,
167
167
int remainder2 );
168
- static int32 partition_rbound_cmp (PartitionKey key ,
169
- Datum * datums1 , PartitionRangeDatumKind * kind1 ,
170
- bool lower1 , PartitionRangeBound * b2 );
171
- static int32 partition_rbound_datum_cmp (PartitionKey key ,
168
+ static int32 partition_rbound_cmp (int partnatts , FmgrInfo * partsupfunc ,
169
+ Oid * partcollation , Datum * datums1 ,
170
+ PartitionRangeDatumKind * kind1 , bool lower1 ,
171
+ PartitionRangeBound * b2 );
172
+ static int32 partition_rbound_datum_cmp (FmgrInfo * partsupfunc ,
173
+ Oid * partcollation ,
172
174
Datum * rb_datums , PartitionRangeDatumKind * rb_kind ,
173
175
Datum * tuple_datums , int n_tuple_datums );
174
176
@@ -1113,8 +1115,9 @@ check_new_partition_bound(char *relname, Relation parent,
1113
1115
* First check if the resulting range would be empty with
1114
1116
* specified lower and upper bounds
1115
1117
*/
1116
- if (partition_rbound_cmp (key , lower -> datums , lower -> kind , true,
1117
- upper ) >= 0 )
1118
+ if (partition_rbound_cmp (key -> partnatts , key -> partsupfunc ,
1119
+ key -> partcollation , lower -> datums ,
1120
+ lower -> kind , true, upper ) >= 0 )
1118
1121
{
1119
1122
ereport (ERROR ,
1120
1123
(errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
@@ -1174,7 +1177,10 @@ check_new_partition_bound(char *relname, Relation parent,
1174
1177
kind = boundinfo -> kind [offset + 1 ];
1175
1178
is_lower = (boundinfo -> indexes [offset + 1 ] == -1 );
1176
1179
1177
- cmpval = partition_rbound_cmp (key , datums , kind ,
1180
+ cmpval = partition_rbound_cmp (key -> partnatts ,
1181
+ key -> partsupfunc ,
1182
+ key -> partcollation ,
1183
+ datums , kind ,
1178
1184
is_lower , upper );
1179
1185
if (cmpval < 0 )
1180
1186
{
@@ -2614,10 +2620,11 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
2614
2620
if (!range_partkey_has_null )
2615
2621
{
2616
2622
bound_offset = partition_range_datum_bsearch (key ,
2617
- partdesc -> boundinfo ,
2618
- key -> partnatts ,
2619
- values ,
2620
- & equal );
2623
+ partdesc -> boundinfo ,
2624
+ key -> partnatts ,
2625
+ values ,
2626
+ & equal );
2627
+
2621
2628
/*
2622
2629
* The bound at bound_offset is less than or equal to the
2623
2630
* tuple value, so the bound at offset+1 is the upper
@@ -2811,7 +2818,9 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
2811
2818
PartitionRangeBound * b2 = (* (PartitionRangeBound * const * ) b );
2812
2819
PartitionKey key = (PartitionKey ) arg ;
2813
2820
2814
- return partition_rbound_cmp (key , b1 -> datums , b1 -> kind , b1 -> lower , b2 );
2821
+ return partition_rbound_cmp (key -> partnatts , key -> partsupfunc ,
2822
+ key -> partcollation , b1 -> datums , b1 -> kind ,
2823
+ b1 -> lower , b2 );
2815
2824
}
2816
2825
2817
2826
/*
@@ -2820,6 +2829,10 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
2820
2829
* Return for two range bounds whether the 1st one (specified in datums1,
2821
2830
* kind1, and lower1) is <, =, or > the bound specified in *b2.
2822
2831
*
2832
+ * partnatts, partsupfunc and partcollation give the number of attributes in the
2833
+ * bounds to be compared, comparison function to be used and the collations of
2834
+ * attributes, respectively.
2835
+ *
2823
2836
* Note that if the values of the two range bounds compare equal, then we take
2824
2837
* into account whether they are upper or lower bounds, and an upper bound is
2825
2838
* considered to be smaller than a lower bound. This is important to the way
@@ -2828,7 +2841,7 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
2828
2841
* two contiguous partitions.
2829
2842
*/
2830
2843
static int32
2831
- partition_rbound_cmp (PartitionKey key ,
2844
+ partition_rbound_cmp (int partnatts , FmgrInfo * partsupfunc , Oid * partcollation ,
2832
2845
Datum * datums1 , PartitionRangeDatumKind * kind1 ,
2833
2846
bool lower1 , PartitionRangeBound * b2 )
2834
2847
{
@@ -2838,7 +2851,7 @@ partition_rbound_cmp(PartitionKey key,
2838
2851
PartitionRangeDatumKind * kind2 = b2 -> kind ;
2839
2852
bool lower2 = b2 -> lower ;
2840
2853
2841
- for (i = 0 ; i < key -> partnatts ; i ++ )
2854
+ for (i = 0 ; i < partnatts ; i ++ )
2842
2855
{
2843
2856
/*
2844
2857
* First, handle cases where the column is unbounded, which should not
@@ -2859,8 +2872,8 @@ partition_rbound_cmp(PartitionKey key,
2859
2872
*/
2860
2873
break ;
2861
2874
2862
- cmpval = DatumGetInt32 (FunctionCall2Coll (& key -> partsupfunc [i ],
2863
- key -> partcollation [i ],
2875
+ cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [i ],
2876
+ partcollation [i ],
2864
2877
datums1 [i ],
2865
2878
datums2 [i ]));
2866
2879
if (cmpval != 0 )
@@ -2884,9 +2897,14 @@ partition_rbound_cmp(PartitionKey key,
2884
2897
*
2885
2898
* Return whether range bound (specified in rb_datums, rb_kind, and rb_lower)
2886
2899
* is <, =, or > partition key of tuple (tuple_datums)
2900
+ *
2901
+ * n_tuple_datums, partsupfunc and partcollation give number of attributes in
2902
+ * the bounds to be compared, comparison function to be used and the collations
2903
+ * of attributes resp.
2904
+ *
2887
2905
*/
2888
2906
static int32
2889
- partition_rbound_datum_cmp (PartitionKey key ,
2907
+ partition_rbound_datum_cmp (FmgrInfo * partsupfunc , Oid * partcollation ,
2890
2908
Datum * rb_datums , PartitionRangeDatumKind * rb_kind ,
2891
2909
Datum * tuple_datums , int n_tuple_datums )
2892
2910
{
@@ -2900,8 +2918,8 @@ partition_rbound_datum_cmp(PartitionKey key,
2900
2918
else if (rb_kind [i ] == PARTITION_RANGE_DATUM_MAXVALUE )
2901
2919
return 1 ;
2902
2920
2903
- cmpval = DatumGetInt32 (FunctionCall2Coll (& key -> partsupfunc [i ],
2904
- key -> partcollation [i ],
2921
+ cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [i ],
2922
+ partcollation [i ],
2905
2923
rb_datums [i ],
2906
2924
tuple_datums [i ]));
2907
2925
if (cmpval != 0 )
@@ -2978,7 +2996,8 @@ partition_range_bsearch(PartitionKey key,
2978
2996
int32 cmpval ;
2979
2997
2980
2998
mid = (lo + hi + 1 ) / 2 ;
2981
- cmpval = partition_rbound_cmp (key ,
2999
+ cmpval = partition_rbound_cmp (key -> partnatts , key -> partsupfunc ,
3000
+ key -> partcollation ,
2982
3001
boundinfo -> datums [mid ],
2983
3002
boundinfo -> kind [mid ],
2984
3003
(boundinfo -> indexes [mid ] == -1 ),
@@ -3022,7 +3041,8 @@ partition_range_datum_bsearch(PartitionKey key,
3022
3041
int32 cmpval ;
3023
3042
3024
3043
mid = (lo + hi + 1 ) / 2 ;
3025
- cmpval = partition_rbound_datum_cmp (key ,
3044
+ cmpval = partition_rbound_datum_cmp (key -> partsupfunc ,
3045
+ key -> partcollation ,
3026
3046
boundinfo -> datums [mid ],
3027
3047
boundinfo -> kind [mid ],
3028
3048
values ,
0 commit comments