@@ -2703,10 +2703,10 @@ add_merged_range_bounds(int partnatts, FmgrInfo *partsupfuncs,
27032703prev_ub .lower = false;
27042704
27052705/*
2706- * We pass to partition_rbound_cmp()lower1 as false to prevent it
2707- *from considering the last upper bound to be smaller than the lower
2708- *bound of the merged partition when the values of the two range
2709- *bounds compare equal.
2706+ * We passlower1 = false to partition_rbound_cmp() to prevent it from
2707+ * considering the last upper bound to be smaller than the lower bound
2708+ * of the merged partition when the values of the two range bounds
2709+ * compare equal.
27102710 */
27112711cmpval = partition_rbound_cmp (partnatts ,partsupfuncs ,partcollations ,
27122712merged_lb -> datums ,merged_lb -> kind ,
@@ -2978,16 +2978,19 @@ check_new_partition_bound(char *relname, Relation parent,
29782978
29792979/*
29802980 * First check if the resulting range would be empty with
2981- * specified lower and upper bounds
2981+ * specified lower and upper bounds. partition_rbound_cmp
2982+ * cannot return zero here, since the lower-bound flags are
2983+ * different.
29822984 */
29832985cmpval = partition_rbound_cmp (key -> partnatts ,
29842986key -> partsupfunc ,
29852987key -> partcollation ,
29862988lower -> datums ,lower -> kind ,
29872989 true,upper );
2988- if (cmpval >=0 )
2990+ Assert (cmpval != 0 );
2991+ if (cmpval > 0 )
29892992{
2990- /*Fetch the problematic keyfrom the lower datums list. */
2993+ /*Point to problematic keyin the lower datums list. */
29912994PartitionRangeDatum * datum = list_nth (spec -> lowerdatums ,
29922995cmpval - 1 );
29932996
@@ -3057,11 +3060,11 @@ check_new_partition_bound(char *relname, Relation parent,
30573060if (cmpval < 0 )
30583061{
30593062/*
3060- *Fetch the problematic keyfrom the upper
3063+ *Point to problematic keyin the upper
30613064 * datums list.
30623065 */
30633066PartitionRangeDatum * datum =
3064- list_nth (spec -> upperdatums ,- cmpval - 1 );
3067+ list_nth (spec -> upperdatums ,Abs ( cmpval ) - 1 );
30653068
30663069/*
30673070 * The new partition overlaps with the
@@ -3083,15 +3086,11 @@ check_new_partition_bound(char *relname, Relation parent,
30833086PartitionRangeDatum * datum ;
30843087
30853088/*
3086- * Fetch the problematic key from the lower datums
3087- * list. Given the way partition_range_bsearch()
3088- * works, the new lower bound is certainly >= the
3089- * bound at offset. If the bound matches exactly, we
3090- * flag the 1st key.
3089+ * Point to problematic key in the lower datums list;
3090+ * if we have equality, point to the first one.
30913091 */
3092- Assert (cmpval >=0 );
30933092datum = cmpval == 0 ?linitial (spec -> lowerdatums ) :
3094- list_nth (spec -> lowerdatums ,cmpval - 1 );
3093+ list_nth (spec -> lowerdatums ,Abs ( cmpval ) - 1 );
30953094overlap = true;
30963095overlap_location = datum -> location ;
30973096with = boundinfo -> indexes [offset + 1 ];
@@ -3393,13 +3392,14 @@ partition_rbound_cmp(int partnatts, FmgrInfo *partsupfunc,
33933392else if (kind1 [i ]> kind2 [i ])
33943393return colnum ;
33953394else if (kind1 [i ]!= PARTITION_RANGE_DATUM_VALUE )
3396-
3395+ {
33973396/*
33983397 * The column bounds are both MINVALUE or both MAXVALUE. No later
33993398 * columns should be considered, but we still need to compare
34003399 * whether they are upper or lower bounds.
34013400 */
34023401break ;
3402+ }
34033403
34043404cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [i ],
34053405partcollation [i ],
@@ -3692,9 +3692,9 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
36923692PartitionRangeBound * b2 = (* (PartitionRangeBound * const * )b );
36933693PartitionKey key = (PartitionKey )arg ;
36943694
3695- return partition_rbound_cmp (key -> partnatts ,key -> partsupfunc ,
3696- key -> partcollation ,b1 -> datums , b1 -> kind ,
3697- b1 -> lower ,b2 );
3695+ return compare_range_bounds (key -> partnatts ,key -> partsupfunc ,
3696+ key -> partcollation ,
3697+ b1 ,b2 );
36983698}
36993699
37003700/*