public inbox for [email protected]
help / color / mirror / Atom feedFrom: Bill Kim <[email protected]>
To: Daniel Gustafsson <[email protected]>
Cc: [email protected]
Subject: Re: BUG #19524: NaN handling in btree_gist's float4/float8 opclasses
Date: Mon, 29 Jun 2026 21:04:52 +0900
Message-ID: <CAMQXxch1N=sZ1fsfx57VhTe=8qpmb1K1vnaB5WVyDbAs8bqExg@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAMQXxcgbtD2LXfX0tpgvOizxP-XxrCHV2ZDy4By_TZnJMsxXWQ@mail.gmail.com>
<[email protected]>
Hi,
contrib/btree_gist's float4/float8 GiST opclasses compared keys with
raw C operators (==, <, >). Under IEEE 754 every comparison involving
NaN returns false, so GiST disagreed with the regular btree opclass,
which uses float[4|8]_cmp_internal() (all NaNs equal, NaN sorts after
every non-NaN value).
The disagreement was reachable from SQL:
* an index scan on a GiST index over a float column returned no rows
for `WHERE a = 'NaN'`, while a sequential scan returned the NaN row;
* `EXCLUDE USING gist (a WITH =)` accepted two rows whose key was NaN,
because gbt_float8eq(NaN, NaN) was false;
* an RLS predicate `USING (a != 'NaN')` leaked NaN rows on index scan.
The fix swaps the five gbt_float{4,8}{gt,ge,eq,le,lt} comparators and
the picksplit gbt_float{4,8}key_cmp for the NaN-aware
float{4,8}_{gt,ge,eq,le,lt} / float{4,8}_cmp_internal() helpers in
utils/float.h — same total order the btree opclass already uses. No
on-disk format change.
Added regression coverage in contrib/btree_gist/sql/float{4,8}.sql for
the three scenarios above. `make check` is green: core 245/245 +
contrib btree_gist 32/32 + all 48 contrib modules.
Originally reported as BUG #19501 and BUG #19524:
https://www.postgresql.org/message-id/19501-3bff3bbc97f1e7c9%40postgresql.org
https://www.postgresql.org/message-id/19524-9559d302c8455664%40postgresql.org
I used an LLM (Claude Code) to help with the analysis and to draft the
patch. I reviewed and tested the diff myself before sending.
Regards,
Bill Kim
2026년 6월 29일 (월) 오전 3:54, Daniel Gustafsson <[email protected]>님이 작성:
> > On 28 Jun 2026, at 04:14, Bill Kim <[email protected]> wrote:
> >
> > Hi all,
> >
> > I have a patch for this and `make check` passes (core + all contrib,
> plus
> > new btree_gist NaN cases covering the three scenarios in the report).
> > Posting here first in case someone is already further along — if not,
> > I'll send it to pgsql-hackers and register it in the open CF in a
> couple
> > of days.
>
> Even if someone else is working on it, always feel free to send your patch.
> Multiple implementations of a fix is not a problem but an opportunity for
> everyone to learn from each other.
>
> --
> Daniel Gustafsson
>
>
view thread (10+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: BUG #19524: NaN handling in btree_gist's float4/float8 opclasses
In-Reply-To: <CAMQXxch1N=sZ1fsfx57VhTe=8qpmb1K1vnaB5WVyDbAs8bqExg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox