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 <[email protected]>
Co-authored-by: Peter Geoghegan <[email protected]>
Reported-by: Ke <[email protected]>
Reported-by: Tom Lane <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Bug: #19749
Discussion: https://postgr.es/m/[email protected]
Discussion: 
https://postgr.es/m/CAGRkXqQQ311Lg=62x5udztpurfgpt6xppmw4x9e3tgbtu16...@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4697138049a18feac4e961e0f75cd6c828f9c04f

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(-)

Reply via email to