pgsql: Rescind unsafe deduplication support. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Rescind unsafe deduplication support.
Date
Msg-id E1xEDY6-00000000biv-43i2@gemulon.postgresql.org
Whole thread
List pgsql-committers
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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/74f26a193417093ac5caff2da6a7b8ac69b16254

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           | 13 +------------
doc/src/sgml/btree.sgml                   | 16 ++++++++++++----
src/backend/utils/adt/datum.c             | 14 ++++++--------
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, 27 insertions(+), 30 deletions(-)


pgsql-committers by date:

Previous
From: Nathan Bossart
Date:
Subject: pgsql: Use a non-locking initial test in TAS_SPIN on AArch64.
Next
From: Peter Geoghegan
Date:
Subject: pgsql: Rescind unsafe deduplication support.