pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Geoghegan <pg@bowt.ie>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Rescind unsafe deduplication support.
Date: Tue, 06 Oct 2026 22:22:14 +0000
Message-ID: <E1xEDY6-00000000biy-4B7E@gemulon.postgresql.org> (raw)

Rescind unsafe deduplication support.

bpchar equality ignores trailing spaces, so equal values in a column
with no length specifier can have different images.  Similarly,
oidvector equality intentionally pays no attention to the array lower
bound field.  We nevertheless allowed nbtree deduplication to be used
with indexes built with bpchar_ops, bpchar_pattern_ops, or
oidvector_ops.  A posting list split could therefore place a TID in an
index tuple whose key was equal to, but not bytewise identical to, the
corresponding table value.  This allowed index-only scans to return
subtly wrong results.

To fix, drop support function 4 from the affected opclasses (we can't
change catalog contents on branches 14 through 18, so we just disable
deduplication by adding hard-coding to the relevant support functions).
Deliberately leave the oidvector opclass alone on branches 14 through
18, though.  Disallowing oidvector deduplication on these branches would
make pg_amcheck report that pg_proc_proname_args_nsp_index has a corrupt
metapage, needlessly alarming users.

System catalog oidvector values always have a lower bound of 0, so the
issue can't cause harm there; a user can only hit it by indexing an
oidvector column that stores the output of a function like trim_array().
It seems very unlikely that any user would ever do that.

Users should REINDEX any B-Tree index on a bpchar column.

Author: Shihao Zhong <zhong950419@gmail.com>
Co-authored-by: Peter Geoghegan <pg@bowt.ie>
Reported-by: Ke <kehan5800@gmail.com>
Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Bug: #19749
Discussion: https://postgr.es/m/19749-d46adf7c7d910b07@postgresql.org
Discussion: https://postgr.es/m/CAGRkXqQQ311Lg=62x5UdZtPuRFgpT6XpPMw4X9E3tgbTu162Mw@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/80c32ab93f6fb01a736afad106e45f5cfd310e1f

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           | 13 +------------
doc/src/sgml/btree.sgml                   | 16 ++++++++++++----
src/backend/utils/adt/datum.c             |  6 +++---
src/backend/utils/adt/varlena.c           |  9 ++++++++-
src/test/regress/expected/btree_index.out |  2 --
src/test/regress/sql/btree_index.sql      |  3 ---
6 files changed, 24 insertions(+), 25 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1xEDY6-00000000biy-4B7E@gemulon.postgresql.org>
Permalink:  ../E1xEDY6-00000000biy-4B7E@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xEDY6-00000000biy-4B7E@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: pg@bowt.ie
  Subject: Re: pgsql: Rescind unsafe deduplication support.
  In-Reply-To: <E1xEDY6-00000000biy-4B7E@gemulon.postgresql.org>
  References: <E1xEDY6-00000000biy-4B7E@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