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

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: Kirill Reshke <reshkekirill(at)gmail(dot)com>
Cc: shihao zhong <zhong950419(at)gmail(dot)com>, 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-22 12:37:03
Message-ID: 6CB2D9A8-B554-48FB-8902-F279336D3AEF@yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 22 Sep 2026, Kirill Reshke wrote:
> Yes, but for HEAD it's OK and will be an idiomatic way to fix.

I found two false negatives with v2, on fresh indexes.

1. A BRIN range containing just one non-NULL NaN box never calls
box_mergeable(). brin_inclusion_add_value() copies the first value and
returns at "if (new)", leaving INCLUSION_UNMERGEABLE false:

CREATE TABLE b (v box);
INSERT INTO b VALUES ('(NaN,NaN),(0,0)');
CREATE INDEX bi ON b USING brin (v);
SET enable_seqscan = off;
SELECT * FROM b WHERE v ~= box '(NaN,NaN),(0,0)';

This returns no rows, versus one with a seq scan. Adding a finite box
to the range makes the NaN row findable. We need to cover the initial
value too, not just merges.

2. GiST still loses the NaN row for the same equality predicate. With
1000 finite boxes and one NaN box, I get one row via seq scan and none
via GiST. rtree_internal_consistent() implements RTSameStrategyNumber
using box_contain(), which rejects a NaN query even when the stored
bound is infinite.

Thank you!

Best regards, Andrey Borodin.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-09-22 16:01:34 BUG #19713: WindowAgg qual pushdown gives wrong partition count when scale(numeric) distinguishes equal values
Previous Message Kirill Reshke 2026-09-22 12:12:56 Re: BUG #19705: One NaN box makes a BRIN box_inclusion_ops index omit unrelated rows