diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-11-14 15:15:53 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-11-14 15:15:53 -0500 |
commit | 851c83fc81917c61b063c875fc1bca489dfcc482 (patch) | |
tree | 5652e4c318aa287085e0362a096c4cb453d9c906 /src/backend | |
parent | f1585362856d4da17113ba2e4ba46cf83cba0cf2 (diff) | |
download | postgresql-851c83fc81917c61b063c875fc1bca489dfcc482.tar.gz postgresql-851c83fc81917c61b063c875fc1bca489dfcc482.zip |
Return FALSE instead of throwing error for comparisons with empty ranges.
Change range_before, range_after, range_adjacent to return false rather
than throwing an error when one or both input ranges are empty.
The original definition is unnecessarily difficult to use, and also can
result in undesirable planner failures since the planner could try to
compare an empty range to something else while deriving statistical
estimates. (This was, in fact, the cause of repeatable regression test
failures on buildfarm member jaguar, as well as intermittent failures
elsewhere.)
Also tweak rangetypes regression test to not drop all the objects it
creates, so that the final state of the regression database contains
some rangetype objects for pg_dump testing.
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/utils/adt/rangetypes.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/backend/utils/adt/rangetypes.c b/src/backend/utils/adt/rangetypes.c index f773c31813a..5c16ca1b19e 100644 --- a/src/backend/utils/adt/rangetypes.c +++ b/src/backend/utils/adt/rangetypes.c @@ -701,15 +701,11 @@ range_before(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* An empty range is neither before nor after any other range */ if (empty1 || empty2) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("input range is empty"))); - - if (range_cmp_bounds(fcinfo, &upper1, &lower2) < 0) - PG_RETURN_BOOL(true); - else PG_RETURN_BOOL(false); + + PG_RETURN_BOOL(range_cmp_bounds(fcinfo, &upper1, &lower2) < 0); } Datum @@ -732,15 +728,11 @@ range_after(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* An empty range is neither before nor after any other range */ if (empty1 || empty2) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("input range is empty"))); - - if (range_cmp_bounds(fcinfo, &lower1, &upper2) > 0) - PG_RETURN_BOOL(true); - else PG_RETURN_BOOL(false); + + PG_RETURN_BOOL(range_cmp_bounds(fcinfo, &lower1, &upper2) > 0); } Datum @@ -764,10 +756,9 @@ range_adjacent(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* An empty range is not adjacent to any other range */ if (empty1 || empty2) - ereport(ERROR, - (errcode(ERRCODE_DATA_EXCEPTION), - errmsg("undefined for empty ranges"))); + PG_RETURN_BOOL(false); /* * For two ranges to be adjacent, the lower boundary of one range has to @@ -819,6 +810,7 @@ range_overlaps(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* An empty range does not overlap any other range */ if (empty1 || empty2) PG_RETURN_BOOL(false); @@ -853,6 +845,7 @@ range_overleft(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* An empty range is neither before nor after any other range */ if (empty1 || empty2) PG_RETURN_BOOL(false); @@ -882,6 +875,7 @@ range_overright(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* An empty range is neither before nor after any other range */ if (empty1 || empty2) PG_RETURN_BOOL(false); @@ -917,6 +911,7 @@ range_minus(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* if either is empty, r1 is the correct answer */ if (empty1 || empty2) PG_RETURN_RANGE(r1); @@ -971,6 +966,7 @@ range_union(PG_FUNCTION_ARGS) range_deserialize(fcinfo, r1, &lower1, &upper1, &empty1); range_deserialize(fcinfo, r2, &lower2, &upper2, &empty2); + /* if either is empty, the other is the correct answer */ if (empty1) PG_RETURN_RANGE(r2); if (empty2) @@ -1051,6 +1047,7 @@ range_cmp(PG_FUNCTION_ARGS) lower1.rngtypid != upper2.rngtypid) elog(ERROR, "range types do not match"); + /* For b-tree use, empty ranges sort before all else */ if (empty1 && empty2) PG_RETURN_INT32(0); else if (empty1) |