pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't choose an invalid index for REPLICA IDENTITY FULL lookups.
Date: Thu, 27 Aug 2026 04:50:12 +0000
Message-ID: <E1wzS42-00000002IDT-3zpq@gemulon.postgresql.org> (raw)

Don't choose an invalid index for REPLICA IDENTITY FULL lookups.

For a REPLICA IDENTITY FULL remote relation whose local counterpart has
no primary key or replica identity, FindUsableIndexForReplicaIdentityFull()
chooses the first index of a suitable shape from RelationGetIndexList().
That list excludes only indexes that are not indislive, so an invalid
index left behind by a failed CREATE INDEX CONCURRENTLY can be selected.

Such an index need not contain every row. Consequently, changes for rows
that it fails to find can be silently dropped as missing-tuple conflicts.
If the index contains no rows at all, the scan can instead error out and
cause the apply worker to exit.

Skip invalid indexes, as the planner does.

Author: Mikhail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: MiƂosz Bieniek <bieniek.milosz@proton.me>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Shlok Kyal <shlok.kyal.oss@gmail.com>
Reviewed-by: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Ajin Cherian <itsajin@gmail.com>
Discussion: https://postgr.es/m/CADzfLwWuubcbJBDRZ_J1SSqHDNjNmUYSAgf5y=17LxmP401xbw@mail.gmail.com
Backpatch-through: 16, where it was introduced

Branch
------
REL_16_STABLE

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

Modified Files
--------------
src/backend/replication/logical/relation.c         | 16 +++++-
src/test/subscription/t/032_subscribe_use_index.pl | 59 ++++++++++++++++++++++
2 files changed, 74 insertions(+), 1 deletion(-)



view thread (5+ messages)

Message-ID: <E1wzS42-00000002IDT-3zpq@gemulon.postgresql.org>
Permalink:  ../E1wzS42-00000002IDT-3zpq@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wzS42-00000002IDT-3zpq@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akapila@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Don't choose an invalid index for REPLICA IDENTITY FULL lookups.
  In-Reply-To: <E1wzS42-00000002IDT-3zpq@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