@@ -2703,10 +2703,10 @@ add_merged_range_bounds(int partnatts, FmgrInfo *partsupfuncs,
2703
2703
prev_ub .lower = false;
2704
2704
2705
2705
/*
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 pass lower1 = 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.
2710
2710
*/
2711
2711
cmpval = partition_rbound_cmp (partnatts , partsupfuncs , partcollations ,
2712
2712
merged_lb -> datums , merged_lb -> kind ,
@@ -2978,16 +2978,19 @@ check_new_partition_bound(char *relname, Relation parent,
2978
2978
2979
2979
/*
2980
2980
* 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.
2982
2984
*/
2983
2985
cmpval = partition_rbound_cmp (key -> partnatts ,
2984
2986
key -> partsupfunc ,
2985
2987
key -> partcollation ,
2986
2988
lower -> datums , lower -> kind ,
2987
2989
true, upper );
2988
- if (cmpval >= 0 )
2990
+ Assert (cmpval != 0 );
2991
+ if (cmpval > 0 )
2989
2992
{
2990
- /* Fetch the problematic key from the lower datums list. */
2993
+ /* Point to problematic key in the lower datums list. */
2991
2994
PartitionRangeDatum * datum = list_nth (spec -> lowerdatums ,
2992
2995
cmpval - 1 );
2993
2996
@@ -3057,11 +3060,11 @@ check_new_partition_bound(char *relname, Relation parent,
3057
3060
if (cmpval < 0 )
3058
3061
{
3059
3062
/*
3060
- * Fetch the problematic key from the upper
3063
+ * Point to problematic key in the upper
3061
3064
* datums list.
3062
3065
*/
3063
3066
PartitionRangeDatum * datum =
3064
- list_nth (spec -> upperdatums , - cmpval - 1 );
3067
+ list_nth (spec -> upperdatums , Abs ( cmpval ) - 1 );
3065
3068
3066
3069
/*
3067
3070
* The new partition overlaps with the
@@ -3083,15 +3086,11 @@ check_new_partition_bound(char *relname, Relation parent,
3083
3086
PartitionRangeDatum * datum ;
3084
3087
3085
3088
/*
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.
3091
3091
*/
3092
- Assert (cmpval >= 0 );
3093
3092
datum = cmpval == 0 ? linitial (spec -> lowerdatums ) :
3094
- list_nth (spec -> lowerdatums , cmpval - 1 );
3093
+ list_nth (spec -> lowerdatums , Abs ( cmpval ) - 1 );
3095
3094
overlap = true;
3096
3095
overlap_location = datum -> location ;
3097
3096
with = boundinfo -> indexes [offset + 1 ];
@@ -3393,13 +3392,14 @@ partition_rbound_cmp(int partnatts, FmgrInfo *partsupfunc,
3393
3392
else if (kind1 [i ] > kind2 [i ])
3394
3393
return colnum ;
3395
3394
else if (kind1 [i ] != PARTITION_RANGE_DATUM_VALUE )
3396
-
3395
+ {
3397
3396
/*
3398
3397
* The column bounds are both MINVALUE or both MAXVALUE. No later
3399
3398
* columns should be considered, but we still need to compare
3400
3399
* whether they are upper or lower bounds.
3401
3400
*/
3402
3401
break ;
3402
+ }
3403
3403
3404
3404
cmpval = DatumGetInt32 (FunctionCall2Coll (& partsupfunc [i ],
3405
3405
partcollation [i ],
@@ -3692,9 +3692,9 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
3692
3692
PartitionRangeBound * b2 = (* (PartitionRangeBound * const * ) b );
3693
3693
PartitionKey key = (PartitionKey ) arg ;
3694
3694
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 );
3698
3698
}
3699
3699
3700
3700
/*
0 commit comments