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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
Cc: reshkekirill(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: btree_gist: <-> fails on same-sign infinite intervals
Date: 2026-12-01 16:42:59
Message-ID: 1575070.1796143379@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Raja Sai pranav <rajasaipranav0(at)gmail(dot)com> writes:
> Thanks, I see the same on master (ea39d58e4b). I think the index scan
> has the right row, though: '178956971 days -2147483647 hours' is
> 2147483657 hours long, so it is 10 hours from '2147483647 hours'. The
> time fields have opposite signs and their difference overflows, and
> c1dd701f turns any field overflow into infinity. That's my mistake.

> Your patch makes the index agree with the operator, but both then
> report infinity for a 10-hour gap. The attached patch fixes the
> operator instead: when a field overflows, it computes the difference
> in the linear form interval_cmp uses (int128) and returns it as a
> time-only interval if that fits, and +infinity only if it doesn't.
> With it, both your queries return "cancellation | 10:00:00".

Yeah, I'd had an itchy feeling about whether there was some edge
case of this sort. I think your fix for interval_dist() is good,
but I believe that Kirill has identified an independent problem:
intr2num() and its callers haven't been modernized to handle
infinite intervals. I don't like the details of what he did though.
I prefer something more like the attached.

regards, tom lane

PS: please fix your mail agent to include In-reply-to/References
headers. Right now, every message you send starts a new thread,
which is annoying for people trying to read the conversation
with thread-aware mailers, and it messes up our mail archives too.

Attachment Content-Type Size
0002-fix-intr2num-for-infinities.patch text/x-diff 1.8 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Matthias van de Meent 2026-12-01 16:48:04 Re: BUG #19519: REPACK can fail due to missing chunk for toast value
Previous Message Ishjaap Singh 2026-12-01 16:22:57 Re: BUG #19936: Planning is slower on 19.0 with many partial indexes on a SQL function