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

Commit 79167c3

Browse files
author
Commitfest Bot
committed
[CF 5693] v1 - Fix replica identity checks for MERGE command on published table.
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5693 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/OS3PR01MB57180C87E43A679A730482DF94B62@OS3PR01MB5718.jpnprd01.prod.outlook.com Author(s): Zhijie Hou
2 parents b006bcd + a790a11 commit 79167c3

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/backend/executor/execMain.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,11 @@ CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation,
10591059
{
10601060
case RELKIND_RELATION:
10611061
case RELKIND_PARTITIONED_TABLE:
1062-
CheckCmdReplicaIdentity(resultRel, operation);
1062+
if (operation == CMD_MERGE)
1063+
foreach_node(MergeAction, action, mergeActions)
1064+
CheckCmdReplicaIdentity(resultRel, action->commandType);
1065+
else
1066+
CheckCmdReplicaIdentity(resultRel, operation);
10631067
break;
10641068
case RELKIND_SEQUENCE:
10651069
ereport(ERROR,

src/test/regress/expected/publication.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,32 @@ DROP PUBLICATION pub1;
19241924
DROP PUBLICATION pub2;
19251925
DROP TABLE gencols;
19261926
RESET client_min_messages;
1927+
-- Test that the MERGE command correctly checks REPLICA IDENTITY when the
1928+
-- target table is published.
1929+
CREATE TABLE testpub_merge_no_ri (a int, b int);
1930+
CREATE TABLE testpub_merge_pk (a int primary key, b int);
1931+
SET client_min_messages = 'ERROR';
1932+
CREATE PUBLICATION pub1 FOR ALL TABLES;
1933+
RESET client_min_messages;
1934+
-- fail - missing REPLICA IDENTITY
1935+
MERGE INTO testpub_merge_no_ri USING testpub_merge_pk s ON s.a >= 1
1936+
WHEN MATCHED THEN UPDATE SET b = s.b;
1937+
ERROR: cannot update table "testpub_merge_no_ri" because it does not have a replica identity and publishes updates
1938+
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
1939+
-- fail - missing REPLICA IDENTITY
1940+
MERGE INTO testpub_merge_no_ri USING testpub_merge_pk s ON s.a >= 1
1941+
WHEN MATCHED THEN DELETE;
1942+
ERROR: cannot delete from table "testpub_merge_no_ri" because it does not have a replica identity and publishes deletes
1943+
HINT: To enable deleting from the table, set REPLICA IDENTITY using ALTER TABLE.
1944+
-- ok - inserts are not restricted
1945+
MERGE INTO testpub_merge_no_ri USING testpub_merge_pk s ON s.a >= 1
1946+
WHEN NOT MATCHED THEN INSERT (a, b) VALUES (0, 0);
1947+
-- ok - REPLICA IDENTITY is DEFAULT and table has a PK
1948+
MERGE INTO testpub_merge_pk USING testpub_merge_no_ri s ON s.a >= 1
1949+
WHEN MATCHED THEN UPDATE SET b = s.b;
1950+
DROP PUBLICATION pub1;
1951+
DROP TABLE testpub_merge_no_ri;
1952+
DROP TABLE testpub_merge_pk;
19271953
RESET SESSION AUTHORIZATION;
19281954
DROP ROLE regress_publication_user, regress_publication_user2;
19291955
DROP ROLE regress_publication_user_dummy;

src/test/regress/sql/publication.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,36 @@ DROP PUBLICATION pub2;
12231223
DROP TABLE gencols;
12241224

12251225
RESET client_min_messages;
1226+
1227+
-- Test that the MERGE command correctly checks REPLICA IDENTITY when the
1228+
-- target table is published.
1229+
CREATE TABLE testpub_merge_no_ri (a int, b int);
1230+
CREATE TABLE testpub_merge_pk (a int primary key, b int);
1231+
1232+
SET client_min_messages = 'ERROR';
1233+
CREATE PUBLICATION pub1 FOR ALL TABLES;
1234+
RESET client_min_messages;
1235+
1236+
-- fail - missing REPLICA IDENTITY
1237+
MERGE INTO testpub_merge_no_ri USING testpub_merge_pk s ON s.a >= 1
1238+
WHEN MATCHED THEN UPDATE SET b = s.b;
1239+
1240+
-- fail - missing REPLICA IDENTITY
1241+
MERGE INTO testpub_merge_no_ri USING testpub_merge_pk s ON s.a >= 1
1242+
WHEN MATCHED THEN DELETE;
1243+
1244+
-- ok - inserts are not restricted
1245+
MERGE INTO testpub_merge_no_ri USING testpub_merge_pk s ON s.a >= 1
1246+
WHEN NOT MATCHED THEN INSERT (a, b) VALUES (0, 0);
1247+
1248+
-- ok - REPLICA IDENTITY is DEFAULT and table has a PK
1249+
MERGE INTO testpub_merge_pk USING testpub_merge_no_ri s ON s.a >= 1
1250+
WHEN MATCHED THEN UPDATE SET b = s.b;
1251+
1252+
DROP PUBLICATION pub1;
1253+
DROP TABLE testpub_merge_no_ri;
1254+
DROP TABLE testpub_merge_pk;
1255+
12261256
RESET SESSION AUTHORIZATION;
12271257
DROP ROLE regress_publication_user, regress_publication_user2;
12281258
DROP ROLE regress_publication_user_dummy;

0 commit comments

Comments
 (0)