Hi hackers,
An inconsistency was observed when using logical replication on partitioned
tables with the option `publish_via_partition_root = true`: if REPLICA IDENTITY
FULL is set only on the parent table, but not on all partitions, logical
decoding emits UPDATE and DELETE messages with tag 'O' (old tuple) even for
partitions that do not have full replica identity. In those cases, only the
primary key columns are included in the message, which contradicts the expected
meaning of 'O' and violates the logical replication message protocol:
https://www.postgresql.org/docs/current/protocol-logicalrep-message-formats.html
This can cause issues in downstream consumers, which interpret
the 'O' tag as implying that a full tuple is present.
The attached patch resolves the inconsistency by selecting the correct tuple
type ('O' vs 'K') based on the replica identity of the actual leaf relation
being published, rather than using the setting of the root relation alone.
As a result, the format of logical replication messages aligns with
the semantics
defined by the protocol.
Steps to reproduce:
1. Create a partitioned table with REPLICA IDENTITY FULL on the parent
and only one of the partitions.
2. Create a publication with `publish_via_partition_root = true`.
3. Perform INSERT, UPDATE, DELETE operations through the root table.
4. Observe via `pg_recvlogical` that for a partition without full replica
identity, the logical replication stream contains 'O' records with
only key fields.
After applying the patch, 'O' is used only when the full row is available,
and 'K' is used otherwise - as expected.
This patch is based on the current `master` branch as of commit: b3754dcc9ff
Best regards,
Mikhail Kharitonov