pgsql: Fix tuple search during apply after concurrent index DDL.

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix tuple search during apply after concurrent index DDL.
Date: 2026-09-28 11:24:01
Message-ID: E1xB9Sj-00000001ayd-1UVF@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix tuple search during apply after concurrent index DDL.

When searching the local relation by index, the apply worker can use the
first match only if the index is the relation's replica identity or
primary key. Otherwise, every match must be compared with the search slot.

Only the index OID was saved in the relation map, so this was determined
again during the search. Concurrent DROP INDEX or REINDEX can change the
index status between these two checks, causing the tuple search to fail
and the change to be silently skipped as an update_missing conflict.

Fix this by recording the answer as idxisreplident in the relation map
entry and avoid getting it second time in FindReplTupleInLocalRel() and
RelationFindReplTupleByIndex().

Oversight in 89e46da5e5.

Author: Mikhail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Author: vignesh C <vignesh21(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Reviewed-by: Zhijie Hou <houzj(dot)fnst(at)fujitsu(dot)com>
Discussion: https://postgr.es/m/CADzfLwUJovFcnknCC9wjZKECX9xecgnGzC2r2TMV8h4QDD_jwQ@mail.gmail.com
Backpatch-through: 16, where it was introduced

Branch
------
master

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

Modified Files
--------------
src/backend/executor/execReplication.c | 18 +--
src/backend/replication/logical/conflict.c | 4 +
src/backend/replication/logical/relation.c | 18 ++-
src/backend/replication/logical/worker.c | 94 +++++++++------
src/include/executor/executor.h | 2 +
src/include/replication/logicalrelation.h | 4 +
src/test/subscription/t/032_subscribe_use_index.pl | 127 +++++++++++++++++++++
7 files changed, 217 insertions(+), 50 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Amit Kapila 2026-09-28 12:52:35 pgsql: Update .abi-compliance-history for change in struct LogicalRepRe
Previous Message Fujii Masao 2026-09-28 09:54:52 pgsql: Prevent remote notices from repeating local query details in log