Commit a5b81b6f authored by Alexander Korotkov's avatar Alexander Korotkov

Fix bugs in comparison functions for multirange_bsearch_match()

Two functions multirange_range_overlaps_bsearch_comparison() and
multirange_range_contains_bsearch_comparison() contain bugs of returning -1
instead of 1.  This commit fixes these bugs and adds corresponding regression
tests.
parent 1b3433e2
...@@ -1660,7 +1660,7 @@ multirange_range_contains_bsearch_comparison(TypeCacheEntry *typcache, ...@@ -1660,7 +1660,7 @@ multirange_range_contains_bsearch_comparison(TypeCacheEntry *typcache,
if (range_cmp_bounds(typcache, keyUpper, lower) < 0) if (range_cmp_bounds(typcache, keyUpper, lower) < 0)
return -1; return -1;
if (range_cmp_bounds(typcache, keyLower, upper) > 0) if (range_cmp_bounds(typcache, keyLower, upper) > 0)
return -1; return 1;
/* /*
* At this point we found overlapping range. But we have to check if it * At this point we found overlapping range. But we have to check if it
...@@ -1825,7 +1825,7 @@ multirange_range_overlaps_bsearch_comparison(TypeCacheEntry *typcache, ...@@ -1825,7 +1825,7 @@ multirange_range_overlaps_bsearch_comparison(TypeCacheEntry *typcache,
if (range_cmp_bounds(typcache, keyUpper, lower) < 0) if (range_cmp_bounds(typcache, keyUpper, lower) < 0)
return -1; return -1;
if (range_cmp_bounds(typcache, keyLower, upper) > 0) if (range_cmp_bounds(typcache, keyLower, upper) > 0)
return -1; return 1;
*match = true; *match = true;
return 0; return 0;
......
...@@ -834,6 +834,12 @@ SELECT nummultirange(numrange(1,2), numrange(3.5,8)) && nummultirange(numrange(3 ...@@ -834,6 +834,12 @@ SELECT nummultirange(numrange(1,2), numrange(3.5,8)) && nummultirange(numrange(3
t t
(1 row) (1 row)
select '{(10,20),(30,40),(50,60)}'::nummultirange && '(42,92)'::numrange;
?column?
----------
t
(1 row)
-- contains -- contains
SELECT nummultirange() @> nummultirange(); SELECT nummultirange() @> nummultirange();
?column? ?column?
...@@ -967,6 +973,12 @@ SELECT '{[1,5), [6,9)}'::nummultirange @> '{[6,7)}'; ...@@ -967,6 +973,12 @@ SELECT '{[1,5), [6,9)}'::nummultirange @> '{[6,7)}';
t t
(1 row) (1 row)
select '{(10,20),(30,40),(50,60)}'::nummultirange @> '(52,56)'::numrange;
?column?
----------
t
(1 row)
-- is contained by -- is contained by
SELECT nummultirange() <@ nummultirange(); SELECT nummultirange() <@ nummultirange();
?column? ?column?
......
...@@ -162,6 +162,7 @@ SELECT nummultirange(numrange(1,2), numrange(7,8)) && nummultirange(numrange(3,4 ...@@ -162,6 +162,7 @@ SELECT nummultirange(numrange(1,2), numrange(7,8)) && nummultirange(numrange(3,4
SELECT nummultirange(numrange(3,4)) && nummultirange(numrange(1,2), numrange(3.5,8)); SELECT nummultirange(numrange(3,4)) && nummultirange(numrange(1,2), numrange(3.5,8));
SELECT nummultirange(numrange(1,2), numrange(3.5,8)) && numrange(3,4); SELECT nummultirange(numrange(1,2), numrange(3.5,8)) && numrange(3,4);
SELECT nummultirange(numrange(1,2), numrange(3.5,8)) && nummultirange(numrange(3,4)); SELECT nummultirange(numrange(1,2), numrange(3.5,8)) && nummultirange(numrange(3,4));
select '{(10,20),(30,40),(50,60)}'::nummultirange && '(42,92)'::numrange;
-- contains -- contains
SELECT nummultirange() @> nummultirange(); SELECT nummultirange() @> nummultirange();
...@@ -186,6 +187,7 @@ SELECT '{[-4,-2), [1,5)}'::nummultirange @> '{[1,5)}'; ...@@ -186,6 +187,7 @@ SELECT '{[-4,-2), [1,5)}'::nummultirange @> '{[1,5)}';
SELECT '{[1,5), [8,9)}'::nummultirange @> '{[1,5)}'; SELECT '{[1,5), [8,9)}'::nummultirange @> '{[1,5)}';
SELECT '{[1,5), [8,9)}'::nummultirange @> '{[6,7)}'; SELECT '{[1,5), [8,9)}'::nummultirange @> '{[6,7)}';
SELECT '{[1,5), [6,9)}'::nummultirange @> '{[6,7)}'; SELECT '{[1,5), [6,9)}'::nummultirange @> '{[6,7)}';
select '{(10,20),(30,40),(50,60)}'::nummultirange @> '(52,56)'::numrange;
-- is contained by -- is contained by
SELECT nummultirange() <@ nummultirange(); SELECT nummultirange() <@ nummultirange();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment