Skip to content

Commit 0d5bd3a

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 f4c32cd commit 0d5bd3a

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
@@ -569,6 +569,13 @@ CheckCmdReplicaIdentity(Relation rel, CmdType cmd)
569569
{
570570
PublicationDesc pubdesc;
571571

572+
/*
573+
* Skip checking the replica identity for partitioned tables, because the
574+
* operations are actually performed on the leaf partitions.
575+
*/
576+
if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
577+
return;
578+
572579
/* We only need to do checks for UPDATE and DELETE. */
573580
if (cmd != CMD_UPDATE && cmd != CMD_DELETE)
574581
return;

src/test/regress/expected/publication.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
214214
Tables:
215215
"public.testpub_parted"
216216

217+
-- works despite missing REPLICA IDENTITY, because no actual update happened
218+
UPDATE testpub_parted SET a = 1 WHERE false;
217219
-- should now fail, because parent's publication replicates updates
218220
UPDATE testpub_parted1 SET a = 1;
219221
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
@@ -119,6 +119,8 @@ UPDATE testpub_parted1 SET a = 1;
119119
-- only parent is listed as being in publication, not the partition
120120
ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
121121
\dRp+ testpub_forparted
122+
-- works despite missing REPLICA IDENTITY, because no actual update happened
123+
UPDATE testpub_parted SET a = 1 WHERE false;
122124
-- should now fail, because parent's publication replicates updates
123125
UPDATE testpub_parted1 SET a = 1;
124126
ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy