From 411fd0de207bfcafce517bc60940877d4bfcb99f Mon Sep 17 00:00:00 2001 From: Nisha Moond Date: Thu, 1 Oct 2026 15:25:52 +0530 Subject: [PATCH v78 4/4] top up patch fix for v77 comments --- doc/src/sgml/logical-replication.sgml | 5 +-- src/backend/replication/logical/conflict.c | 47 +++++++++++----------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 66ef045d5ba..c1b9f08d820 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -2371,7 +2371,7 @@ DETAIL: detailed_explanation[: replica_identity_full boolean - Indicates whether the conflicting relation uses REPLICA IDENTITY FULL (true) or a replica identity index (false). This is NULL when replica identity information is not applicable. + True if the conflicting local row was located using the full tuple, rather than the replica identity key of the local table. replica_identity @@ -2379,8 +2379,7 @@ DETAIL: detailed_explanation[: The replica identity key values identifying the conflicting row, as a JSON object keyed by column name; see below for how the values are represented. This is NULL when - replica_identity_full is true or - when replica identity is not applicable. + replica_identity_full is true. local_conflicts diff --git a/src/backend/replication/logical/conflict.c b/src/backend/replication/logical/conflict.c index 3848b66043e..907dc2caeaf 100644 --- a/src/backend/replication/logical/conflict.c +++ b/src/backend/replication/logical/conflict.c @@ -1297,6 +1297,7 @@ insert_conflict_log_tuple(Relation rel, XLogRecPtr remote_final_lsn; TimestampTz remote_commit_ts; bool omitted = false; + Oid replica_index; HeapTuple tuple; Assert(conflictlogrel != NULL); @@ -1339,34 +1340,32 @@ insert_conflict_log_tuple(Relation rel, else nulls[attno++] = true; - if (!TupIsNull(searchslot)) - { - Oid replica_index = GetRelationIdentityOrPK(rel); + /* + * All conflicts logged to the table are LOG-level update or delete + * conflicts, which always have a searchslot. Insert conflicts, which + * don't, are ERROR-level and never reach here. + */ + Assert(!TupIsNull(searchslot)); - /* - * If the table has a valid replica identity index, build the index - * JSON datum from key value. Otherwise, in REPLICA IDENTITY FULL - * cases, set replica_identity_full to true and leave replica_identity - * NULL to avoid serializing full tuples that could exceed memory - * allocation limits. - */ - if (OidIsValid(replica_index)) - { - values[attno++] = BoolGetDatum(false); - values[attno++] = build_index_key_json(rel, - replica_index, - searchslot, - &omitted); - } - else - { - values[attno++] = BoolGetDatum(true); - nulls[attno++] = true; - } + replica_index = GetRelationIdentityOrPK(rel); + + /* + * If the table has a valid replica identity index, build the index JSON + * datum from key value. Otherwise, in REPLICA IDENTITY FULL cases, set + * replica_identity_full to true and leave replica_identity NULL to avoid + * serializing full tuples that could exceed memory allocation limits. + */ + if (OidIsValid(replica_index)) + { + values[attno++] = BoolGetDatum(false); + values[attno++] = build_index_key_json(rel, + replica_index, + searchslot, + &omitted); } else { - nulls[attno++] = true; + values[attno++] = BoolGetDatum(true); nulls[attno++] = true; } -- 2.54.0 (Apple Git-157)