@@ -165,10 +165,12 @@ static PartitionRangeBound *make_one_range_bound(PartitionKey key, int index,
165165List * datums ,bool lower );
166166static int32 partition_hbound_cmp (int modulus1 ,int remainder1 ,int modulus2 ,
167167int 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 ,
172174Datum * rb_datums ,PartitionRangeDatumKind * rb_kind ,
173175Datum * tuple_datums ,int n_tuple_datums );
174176
@@ -1113,8 +1115,9 @@ check_new_partition_bound(char *relname, Relation parent,
11131115 * First check if the resulting range would be empty with
11141116 * specified lower and upper bounds
11151117 */
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 )
11181121{
11191122ereport (ERROR ,
11201123(errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
@@ -1174,7 +1177,10 @@ check_new_partition_bound(char *relname, Relation parent,
11741177kind = boundinfo -> kind [offset + 1 ];
11751178is_lower = (boundinfo -> indexes [offset + 1 ]== -1 );
11761179
1177- cmpval = partition_rbound_cmp (key ,datums ,kind ,
1180+ cmpval = partition_rbound_cmp (key -> partnatts ,
1181+ key -> partsupfunc ,
1182+ key -> partcollation ,
1183+ datums ,kind ,
11781184is_lower ,upper );
11791185if (cmpval < 0 )
11801186{
@@ -2614,10 +2620,11 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
26142620if (!range_partkey_has_null )
26152621{
26162622bound_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+
26212628/*
26222629 * The bound at bound_offset is less than or equal to the
26232630 * 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)
28112818PartitionRangeBound * b2 = (* (PartitionRangeBound * const * )b );
28122819PartitionKey key = (PartitionKey )arg ;
28132820
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 );
28152824}
28162825
28172826/*
@@ -2820,6 +2829,10 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
28202829 * Return for two range bounds whether the 1st one (specified in datums1,
28212830 * kind1, and lower1) is <, =, or > the bound specified in *b2.
28222831 *
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+ *
28232836 * Note that if the values of the two range bounds compare equal, then we take
28242837 * into account whether they are upper or lower bounds, and an upper bound is
28252838 * 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)
28282841 * two contiguous partitions.
28292842 */
28302843static int32
2831- partition_rbound_cmp (PartitionKey key ,
2844+ partition_rbound_cmp (int partnatts , FmgrInfo * partsupfunc , Oid * partcollation ,
28322845Datum * datums1 ,PartitionRangeDatumKind * kind1 ,
28332846bool lower1 ,PartitionRangeBound * b2 )
28342847{
@@ -2838,7 +2851,7 @@ partition_rbound_cmp(PartitionKey key,
28382851PartitionRangeDatumKind * kind2 = b2 -> kind ;
28392852bool lower2 = b2 -> lower ;
28402853
2841- for (i = 0 ;i < key -> partnatts ;i ++ )
2854+ for (i = 0 ;i < partnatts ;i ++ )
28422855{
28432856/*
28442857 * First, handle cases where the column is unbounded, which should not
@@ -2859,8 +2872,8 @@ partition_rbound_cmp(PartitionKey key,
28592872 */
28602873break ;
28612874
2862- cmpval = DatumGetInt32 (FunctionCall2Coll (& key -> partsupfunc [i ],
2863- key -> partcollation [i ],
2875+ cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [i ],
2876+ partcollation [i ],
28642877datums1 [i ],
28652878datums2 [i ]));
28662879if (cmpval != 0 )
@@ -2884,9 +2897,14 @@ partition_rbound_cmp(PartitionKey key,
28842897 *
28852898 * Return whether range bound (specified in rb_datums, rb_kind, and rb_lower)
28862899 * 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+ *
28872905 */
28882906static int32
2889- partition_rbound_datum_cmp (PartitionKey key ,
2907+ partition_rbound_datum_cmp (FmgrInfo * partsupfunc , Oid * partcollation ,
28902908Datum * rb_datums ,PartitionRangeDatumKind * rb_kind ,
28912909Datum * tuple_datums ,int n_tuple_datums )
28922910{
@@ -2900,8 +2918,8 @@ partition_rbound_datum_cmp(PartitionKey key,
29002918else if (rb_kind [i ]== PARTITION_RANGE_DATUM_MAXVALUE )
29012919return 1 ;
29022920
2903- cmpval = DatumGetInt32 (FunctionCall2Coll (& key -> partsupfunc [i ],
2904- key -> partcollation [i ],
2921+ cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [i ],
2922+ partcollation [i ],
29052923rb_datums [i ],
29062924tuple_datums [i ]));
29072925if (cmpval != 0 )
@@ -2978,7 +2996,8 @@ partition_range_bsearch(PartitionKey key,
29782996int32 cmpval ;
29792997
29802998mid = (lo + hi + 1 ) /2 ;
2981- cmpval = partition_rbound_cmp (key ,
2999+ cmpval = partition_rbound_cmp (key -> partnatts ,key -> partsupfunc ,
3000+ key -> partcollation ,
29823001boundinfo -> datums [mid ],
29833002boundinfo -> kind [mid ],
29843003 (boundinfo -> indexes [mid ]== -1 ),
@@ -3022,7 +3041,8 @@ partition_range_datum_bsearch(PartitionKey key,
30223041int32 cmpval ;
30233042
30243043mid = (lo + hi + 1 ) /2 ;
3025- cmpval = partition_rbound_datum_cmp (key ,
3044+ cmpval = partition_rbound_datum_cmp (key -> partsupfunc ,
3045+ key -> partcollation ,
30263046boundinfo -> datums [mid ],
30273047boundinfo -> kind [mid ],
30283048values ,