pgsql: Fix BRIN minmax-multi distance for tid values

From: Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix BRIN minmax-multi distance for tid values
Date: 2026-11-02 21:08:42
Message-ID: E1xNzGk-00000001qPV-0cHD@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix BRIN minmax-multi distance for tid values

The distance function for tid values maps item pointers to float8 as

(block * MaxHeapTuplesPerPage + offset)

but the multiplication was done in uint32 arithmetic, so for high block
values (above 14759338, ~112GB) the result wrapped around. The distance
would then be very inaccurate (possibly negative), resulting in a less
efficient index.

Fix by doing the arithmetics in double.

It's also possible the (user-supplied) item pointers have offsets
greater than MaxHeapTuplesPerPage, confusing the mapping to double
value. This commit does not try to address that, it's not clear what
would be a better mapping.

Author: Tomas Vondra <tomas(at)vondra(dot)me>
Backpatch-through: 14
Discussion: https://postgr.es/m/CALdSSPgBvXz-VSF0p-5k%3D_uFfN38cWrERmm_AC4K67N6MWQhmg%40mail.gmail.com

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6a770f537fcebc0fb7276c676223abdca96dd5e1

Modified Files
--------------
src/backend/access/brin/brin_minmax_multi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2026-11-02 21:08:49 pgsql: Fix BRIN minmax-multi distance for tid values
Previous Message Tomas Vondra 2026-11-02 21:08:33 pgsql: Fix BRIN minmax-multi distance for tid values