pgsql: Fix logical replication with lossy identity indexes.

From: Amit Kapila <akapila(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix logical replication with lossy identity indexes.
Date: 2026-10-21 03:27:15
Message-ID: E1xJMyx-000000005rL-2vfN@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix logical replication with lossy identity indexes.

A GiST index on a multirange stores only its bounding range, so different
multiranges can produce the same index key. However,
RelationFindReplTupleByIndex() and RelationFindDeletedTupleInfoByIndex()
assume that matches through a primary key or replica identity index are
exact and skip the equality check. This can cause updates or deletes to
target the wrong row, and conflict detection to report update_deleted
instead of update_missing.

Fix this by rechecking candidates when the index scan sets xs_recheck.
Compare only the index key columns, using the scan keys' equality
operators and collations to match the index's notion of key equality.

Backpatch to 18, where WITHOUT OVERLAPS was introduced. The change to
RelationFindDeletedTupleInfoByIndex() applies only to 19 and later, where
update_deleted conflict detection was added.

Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Author: Paul A. Jungwirth <pj(at)illuminatedcomputing(dot)com>
Author: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Reviewed-by: Nisha Moond <nisha(dot)moond412(at)gmail(dot)com>
Reviewed-by: kedar anavardekar <kedar(dot)anavardekar(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Discussion: https://postgr.es/m/kcyaok346iwocfdourf2oojgtz7ggxmh2ugis7qqhggs4qfzc2@cu6pkox4rfwp
Discussion: https://postgr.es/m/e5nb5jbus2oa3pffmlo7pdvdckmchd54tqld4k3n6huyg5xxqn@7rounyvufjx6
Discussion: https://postgr.es/m/CA+renyWzTBC4GetPzJM1KqrejrmOWcGnn2NaA7tpee17HFxRPw@mail.gmail.com
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/23fffd382ca06690fdce91bc4819a57017cb1dda

Modified Files
--------------
src/backend/executor/execReplication.c | 60 ++++++++++++++++++++++++++--
src/test/subscription/t/034_temporal.pl | 71 +++++++++++++++++++++++++++++++++
2 files changed, 128 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Richard Guo 2026-10-21 06:42:43 pgsql: Fix sorting a child rel by an expression containing a PlaceHolde
Previous Message Michael Paquier 2026-10-21 01:56:12 pgsql: Fix cleanup of reused pgstats entries in pgstat_release_entry_re