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

From: Manu <manuelreyesbravo(at)gmail(dot)com>
To: shihao zhong <zhong950419(at)gmail(dot)com>, Greg Burd <greg(at)burd(dot)me>
Cc: John Naylor <johncnaylorls(at)gmail(dot)com>, Tomas Vondra <tomas(at)vondra(dot)me>, Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, 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-12-05 22:29:33
Message-ID: 179650977339.644500.2140146284928380768@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Greg, Shihao,

I tested the order Shihao chose, v6 first and then Greg's v2, on
76ac7f718d8 with assertions enabled. It works as Greg describes, and
the other order gives the same tree. One step of the rebase is easy
to miss.

On Sat, Dec 5, 2026 at 1:32 AM shihao zhong wrote:
> Your v2 on
> top then only drops distance_has_nan() and the dist_bp() call, as you
> described.

Git marks only one hunk, in gist_bbox_distance(). The two pieces v2
drops, distance_has_nan() in gist_point_distance() and the dist_bp()
call at the end of gist_box_distance(), merge without a conflict
marker and stay unless they are removed by hand. Leaving them in
changed no result in my tests: after v2's computeDistance() change
they are dead code. With the gist.out row Greg describes updated,
make check passes.

On Fri, Dec 4, 2026 at 4:52 PM Greg Burd <greg(at)burd(dot)me> wrote:
> In my
> index-versus-seq-scan comparison, v6 leaves 36 failures, all SP-GiST;
> with both patches 4 remain, the all-NaN polygon case from
> point_inside().

On a grid built from your info.txt, with my own special rows, I get 40
and 7. The 7 are the same cells as with v2 alone, a subset of v6's
and of master's, and none is new. Five are the all-NaN polygon: your
four points plus (Infinity,0). The other two are SP-GiST poly_ops
over 3000 polygons like ((g,g),(g+1,NaN),(g+1,g+1)), queried at
(22.5,22.5) and (99,99), and they fail the same way on master, v6, v2
and both. Those polygons have a finite <-> and a NaN in the bounding
box. From reading geo_spgist.c, the inner-node bound in
pointToRectBoxDistance() looks like the cause, but I have not checked
that in a debugger. Neither patch touches it.

Shihao's circle fails on master too, so it predates v2. Polygons
without NaN hit the same thing through point_inside()'s EPSILON:
(0.9999996,2) and (1e-300,-1e-300) over a grid of unit squares give
"index returned tuples in wrong order" with GiST and SP-GiST
poly_ops, on master as well. So the commit message's sentence about
bounding boxes being a lower bound needs to change for polygons, and
not only because of rounding.

> Mine changes the operator's result for NaN boxes, so I'd keep it to
> master; for the back branches v6-0004 as it stands is the fix.

With v6 alone, the p1 rows in an SP-GiST index still raise
"index returned tuples in wrong order". The bound part of v2 does not
need the operator change. As a measurement only, I applied v6-0004's
rule to SP-GiST and left <-> alone: 0 for a bounding key with a NaN,
the operator for a box_ops leaf with a NaN. It is about 26 lines and
changes no expected output. On master it fixes the p1 SP-GiST errors
and gives exactly the same result as v6 plus v2 on a 6769-check matrix
over every ordering and search operator of these opclasses. On the
grid it leaves two more cells than v6 plus v2: the inner-node case
above with NaN boxes, which v2 hides by making their distance NaN. I
have not tried it on the back branches. I can post the diff if it
helps you decide the split.

Regards,
Manu

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Ishjaap Singh 2026-12-05 23:14:10 Re: BUG #19936: Planning is slower on 19.0 with many partial indexes on a SQL function
Previous Message Zsolt Parragi 2026-12-05 22:17:47 Re: BUG #19519: REPACK can fail due to missing chunk for toast value