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:49
Message-ID: E1xNzGr-00000001qQY-3wDz@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_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c48577385d15245691dbbff3bf25f1a1b58fe70e

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 Masahiko Sawada 2026-11-02 21:23:22 pgsql: Make parallel vacuum processes share the cost limit.
Previous Message Tomas Vondra 2026-11-02 21:08:42 pgsql: Fix BRIN minmax-multi distance for tid values