btree_gist: <-> fails on same-sign infinite intervals

Started by Raja Sai pranav3 days ago2 messagesbugs

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1Raja Sai pranav
rajasaipranav0@gmail.com

Hi,

Commit 15b3dc140d (bug #19761) made same-sign infinities zero distance
apart in btree_gist's date and timestamp opclasses. The interval opclass
still fails:

CREATE EXTENSION btree_gist;
SELECT 'infinity'::interval <-> 'infinity'::interval;
ERROR: interval out of range

interval_dist() computes the result with interval_mi(), which rejects
the difference of two same-sign infinities. So ORDER BY a <-> 'infinity'
(or '-infinity') on an interval column that holds that value fails,
with a KNN index scan as well as with a sort. I see it on master and
18.7; infinite intervals exist since v17.

The attached patch does what ts_dist() now does: same-sign infinities
are zero apart, any other infinite input is infinitely far. It adds
tests to the interval test, which fail without the code change. It
applies to master, REL_18_STABLE and REL_17_STABLE.

Regards,
Sai Pranav

Attachments:

t259862_1
v1-0001-btree_gist-Don-t-report-overflow-for-on-same-sign.patchtext/x-patch; charset=UTF-8; name=v1-0001-btree_gist-Don-t-report-overflow-for-on-same-sign.patchDownload+80-4
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Raja Sai pranav (#1)
Re: btree_gist: <-> fails on same-sign infinite intervals

Raja Sai pranav <rajasaipranav0@gmail.com> writes:

The attached patch does what ts_dist() now does: same-sign infinities
are zero apart, any other infinite input is infinitely far. It adds
tests to the interval test, which fail without the code change. It
applies to master, REL_18_STABLE and REL_17_STABLE.

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.

regards, tom lane