Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1df86aa

Browse files
author
Amit Kapila
committed
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
1 parent dc9ed21 commit 1df86aa

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/backend/executor/execReplication.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,13 @@ CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
565565
{
566566
PublicationActions *pubactions;
567567

568+
/*
569+
* Skip checking the replica identity for partitioned tables, because the
570+
* operations are actually performed on the leaf partitions.
571+
*/
572+
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
573+
return;
574+
568575
/* We only need to do checks for UPDATE and DELETE. */
569576
if (cmd != CMD_UPDATE && cmd != CMD_DELETE)
570577
return;

src/test/regress/expected/publication.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
140140
Tables:
141141
"public.testpub_parted"
142142

143+
-- works despite missing REPLICA IDENTITY, because no actual update happened
144+
UPDATE testpub_parted SET a = 1 WHERE false;
143145
-- should now fail, because parent's publication replicates updates
144146
UPDATE testpub_parted1 SET a = 1;
145147
ERROR: cannot update table "testpub_parted1" because it does not have a replica identity and publishes updates

src/test/regress/sql/publication.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ UPDATE testpub_parted1 SET a = 1;
8585
-- only parent is listed as being in publication, not the partition
8686
ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
8787
\dRp+ testpub_forparted
88+
-- works despite missing REPLICA IDENTITY, because no actual update happened
89+
UPDATE testpub_parted SET a = 1 WHERE false;
8890
-- should now fail, because parent's publication replicates updates
8991
UPDATE testpub_parted1 SET a = 1;
9092
ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1;

0 commit comments

Comments
 (0)