pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Rescind unsafe deduplication support.
7+ messages / 1 participants
[nested] [flat]

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

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

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           | 17 +------------
doc/src/sgml/btree.sgml                   | 16 +++++++++----
src/include/catalog/catversion.h          |  2 +-
src/include/catalog/pg_amproc.dat         |  7 ------
src/test/regress/expected/btree_index.out |  2 --
src/test/regress/expected/opr_sanity.out  | 40 ++++++++++++++++---------------
src/test/regress/sql/btree_index.sql      |  3 ---
7 files changed, 35 insertions(+), 52 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/18740523a4a044a969f71a7322fb2d19ca69d00d

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           | 17 +------------
doc/src/sgml/btree.sgml                   | 16 +++++++++----
src/include/catalog/catversion.h          |  2 +-
src/include/catalog/pg_amproc.dat         |  7 ------
src/test/regress/expected/btree_index.out |  2 --
src/test/regress/expected/opr_sanity.out  | 40 ++++++++++++++++---------------
src/test/regress/sql/btree_index.sql      |  3 ---
7 files changed, 35 insertions(+), 52 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/882fd416d6ed605de09c5ae636bf753bcd5f47d0

Modified Files
--------------
contrib/amcheck/verify_nbtree.c           | 17 +----------------
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(+), 34 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_15_STABLE

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

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Rescind unsafe deduplication support.
@ 2026-10-06 22:22  Peter Geoghegan <pg@bowt.ie>
  0 siblings, 0 replies; 7+ messages in thread

From: Peter Geoghegan @ 2026-10-06 22:22 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2026-10-06 22:22 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>
2026-10-06 22:22 pgsql: Rescind unsafe deduplication support. Peter Geoghegan <pg@bowt.ie>

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