From 048364f4c5a35030b292b01b1c90b9163c93fb73 Mon Sep 17 00:00:00 2001 From: Hou Zhijie Date: Thu, 4 Aug 2022 17:18:25 +0800 Subject: [PATCH v2] fix RI check for partitioned table On publisher, we will check if UPDATE or DELETE can be executed with current replica identity on the table even if it's a partitioned table. But we only need to check the replica identity for leaf partition as operations are performed on leaf partitions. So, fix it by skipping checking the the replica identity for partitioned table on publisher. --- src/backend/executor/execReplication.c | 7 +++++++ src/test/regress/expected/publication.out | 2 ++ src/test/regress/sql/publication.sql | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c index b000645..865bd7a 100644 --- a/src/backend/executor/execReplication.c +++ b/src/backend/executor/execReplication.c @@ -569,6 +569,13 @@ CheckCmdReplicaIdentity(Relation rel, CmdType cmd) { PublicationDesc pubdesc; + /* + * We only need to check the replica identity for leaf partition as + * operations are actually performed on leaf partitions. + */ + if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) + return; + /* We only need to do checks for UPDATE and DELETE. */ if (cmd != CMD_UPDATE && cmd != CMD_DELETE) return; diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out index 1df5951..6d1b743 100644 --- a/src/test/regress/expected/publication.out +++ b/src/test/regress/expected/publication.out @@ -214,6 +214,8 @@ ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted; Tables: "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 UPDATE testpub_parted1 SET a = 1; ERROR: cannot update table "testpub_parted1" because it does not have a replica identity and publishes updates diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql index 9eb86fd..a56387e 100644 --- a/src/test/regress/sql/publication.sql +++ b/src/test/regress/sql/publication.sql @@ -119,6 +119,8 @@ UPDATE testpub_parted1 SET a = 1; -- only parent is listed as being in publication, not the partition ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted; \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 UPDATE testpub_parted1 SET a = 1; ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1; -- 2.7.2.windows.1