Re: BUG #19705: One NaN box makes a BRIN box_inclusion_ops index omit unrelated rows

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Cc: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, kehan5800(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19705: One NaN box makes a BRIN box_inclusion_ops index omit unrelated rows
Date: 2026-09-24 02:43:58
Message-ID: CAGRkXqQ7q0U3jmitwOjPY2BNBkxWsnyahgoYyMs4H=hwVtPFgw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Kirill,

Agreed on all four. v4 attached, split into BRIN and GiST.

0001 is BRIN, master only. bound_box() is untouched. The consistent
function also scans a range whose union is not mergeable with itself,
so old NaN summaries work without REINDEX. Needs a catversion bump.

0002 is GiST, back to 14. Old internal keys with a NaN match every
search and get KNN distance zero. Without the distance part, KNN on old
indexes returned rows out of order. 0002 also fixes point ~= with a NaN
query, which lost rows even on a fresh index. The leaf check used
FPeq(), but point_eq() compares exactly when there is a NaN.

The .nocfbot file is BRIN for the back branches, against REL_18. It
needs no catalog change. Consistent scans a range whose union does not
contain itself, using the existing contains support function. A NaN box
fails that, and any sane union passes. Nothing on disk changes, so old
indexes work without REINDEX after a minor upgrade. The code applies to
14 and later, the test hunk needs a small rebase on 14 to 16. This check
would also work on master, if we want one fix everywhere.

I checked 0001 and 0002 with indexes built by unpatched master, then
pg_upgraded, no REINDEX. The back branch patch got the same check on
REL_18, with a minor upgrade.

Thanks,
Shihao

Attachment Content-Type Size
v4-REL_18-0001-Fix-BRIN-box_inclusion_ops-hiding-rows-next-to-a-.patch.nocfbot application/octet-stream 5.6 KB
v4-0002-Fix-GiST-box-indexes-hiding-rows-next-to-a-NaN-bo.patch application/octet-stream 13.8 KB
v4-0001-Fix-BRIN-box_inclusion_ops-hiding-rows-next-to-a-.patch application/octet-stream 13.0 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ayush Tiwari 2026-09-24 02:47:10 Re: BUG #19687: ALTER SEQUENCE provokes error XX001 could not read blocks
Previous Message Michael Paquier 2026-09-24 01:19:58 Re: BUG #19687: ALTER SEQUENCE provokes error XX001 could not read blocks