pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix BRIN minmax-multi distance calculation for OID
Date: Mon, 02 Nov 2026 22:41:52 +0000
Message-ID: <E1xO0iu-00000001r1E-1tGg@gemulon.postgresql.org> (raw)

Fix BRIN minmax-multi distance calculation for OID

The oid_minmax_multi_ops opclass simply calculated the distance using
brin_minmax_multi_distance_int4. That however interprets the values as
int32, so OIDs above PG_INT32_MAX were treated as negative values, and
ranges crossing the boundary ended with a negative distance.

With assert-enabled guild, this tripped the (a1 <= a2) check. Without
asserts, the index was less efficient.

Fix by introducing brin_minmax_multi_distance_oid, correctly treating
the OID values as unsigned.

This required a catalog change (and catversion bump), so it can't be
backpatched. It'd be possible to adjust brin_minmax_multi_distance_int4
to handle the (a1 > a2) case differently. But that'd lose the assert,
and it does not seem worth it (indexes on OIDs don't seem very common).

Author: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Discussion: https://postgr.es/m/CALdSSPgBvXz-VSF0p-5k%3D_uFfN38cWrERmm_AC4K67N6MWQhmg%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4b6735c21fa4c43be041c6c610d7be6463c2c1f9

Modified Files
--------------
src/backend/access/brin/brin_minmax_multi.c | 21 +++++++++++++++++++++
src/include/catalog/pg_amproc.dat           |  2 +-
src/include/catalog/pg_proc.dat             |  4 ++++
src/test/regress/expected/brin_multi.out    |  5 +++++
src/test/regress/sql/brin_multi.sql         |  8 ++++++++
5 files changed, 39 insertions(+), 1 deletion(-)



Message-ID: <E1xO0iu-00000001r1E-1tGg@gemulon.postgresql.org>
Permalink:  ../E1xO0iu-00000001r1E-1tGg@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xO0iu-00000001r1E-1tGg@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tomas.vondra@postgresql.org
  Subject: Re: pgsql: Fix BRIN minmax-multi distance calculation for OID
  In-Reply-To: <E1xO0iu-00000001r1E-1tGg@gemulon.postgresql.org>
  References: <E1xO0iu-00000001r1E-1tGg@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox