Re: btree_gist: <-> fails on same-sign infinite intervals
Tom Lane <tgl@sss.pgh.pa.us> writes:
Agreed we should fix this, but you've not fully duplicated the
fixes from 15b3dc140: since you still use interval_mi, it's
still possible to get an overflow error. I think you need to
inline what finite_interval_mi() does and substitute infinity
in the cases where it throws an error.
Right. There was a second one too: abs_interval() negates the
difference with interval_um(), which also errors when the difference
fits but its negation doesn't. For example
'-178956970 years -7 months'::interval <-> '1 mon'::interval
subtracts to exactly INT_MIN months.
v2 subtracts the smaller input from the larger (by interval_cmp), so
the result is never negative and isn't negated, and does the
finite_interval_mi() arithmetic inline, returning +infinity when it
overflows. The tests now cover the subtraction overflow, the negation
overflow and an ORDER BY with a sort; each of the three fails with
"interval out of range" with the v1 code and passes with v2.
The master patch applies to REL_19_STABLE. REL_18_STABLE and
REL_17_STABLE differ only in the #include lines; the second
attachment is the REL_18 version, where btree_gist's tests pass and
fail the same way without the fix. I haven't built REL_17.
Regards,
Sai Pranav