Commit 02f8d68a authored by Amit Kapila's avatar Amit Kapila

Fix replica identity check for a partitioned table.

The current publisher code checks if UPDATE or DELETE can be executed with
the replica identity of the table even if it's a partitioned table. We can
skip checking the replica identity for partitioned tables because the
operations are actually performed on the leaf partitions (not the
partitioned table).

Reported-by: Brad Nicholson
Author: Hou Zhijie
Reviewed-by: Peter Smith, Amit Kapila
Backpatch-through: 13
Discussion: https://postgr.es/m/CAMMnM%3D8i5DohH%3DYKzV0_wYuYSYvuOJoL9F5nzXTc%2ByzsG1f6rg%40mail.gmail.com
parent a1a5e6d9
...@@ -569,6 +569,13 @@ CheckCmdReplicaIdentity(Relation rel, CmdType cmd) ...@@ -569,6 +569,13 @@ CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
{ {
PublicationActions *pubactions; PublicationActions *pubactions;
/*
* Skip checking the replica identity for partitioned tables, because the
* operations are actually performed on the leaf partitions.
*/
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
return;
/* We only need to do checks for UPDATE and DELETE. */ /* We only need to do checks for UPDATE and DELETE. */
if (cmd != CMD_UPDATE && cmd != CMD_DELETE) if (cmd != CMD_UPDATE && cmd != CMD_DELETE)
return; return;
......
...@@ -140,6 +140,8 @@ ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted; ...@@ -140,6 +140,8 @@ ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
Tables: Tables:
"public.testpub_parted" "public.testpub_parted"
-- works despite missing REPLICA IDENTITY, because no actual update happened
UPDATE testpub_parted SET a = 1 WHERE false;
-- should now fail, because parent's publication replicates updates -- should now fail, because parent's publication replicates updates
UPDATE testpub_parted1 SET a = 1; UPDATE testpub_parted1 SET a = 1;
ERROR: cannot update table "testpub_parted1" because it does not have a replica identity and publishes updates ERROR: cannot update table "testpub_parted1" because it does not have a replica identity and publishes updates
......
...@@ -85,6 +85,8 @@ UPDATE testpub_parted1 SET a = 1; ...@@ -85,6 +85,8 @@ UPDATE testpub_parted1 SET a = 1;
-- only parent is listed as being in publication, not the partition -- only parent is listed as being in publication, not the partition
ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted; ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
\dRp+ testpub_forparted \dRp+ testpub_forparted
-- works despite missing REPLICA IDENTITY, because no actual update happened
UPDATE testpub_parted SET a = 1 WHERE false;
-- should now fail, because parent's publication replicates updates -- should now fail, because parent's publication replicates updates
UPDATE testpub_parted1 SET a = 1; UPDATE testpub_parted1 SET a = 1;
ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1; ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment