Skip to content

Commit 70ae82b

Browse files
committed
Fix assertion with relation using REPLICA IDENTITY FULL in subscriber
In a logical replication subscriber, a table using REPLICA IDENTITY FULL which has a primary key would try to use the primary key's index available to scan for a tuple, but an assertion only assumed as correct the case of an index associated to REPLICA IDENTITY USING INDEX. This commit corrects the assertion so as the use of a primary key index is a valid case. Reported-by: Dilip Kumar Analyzed-by: Dilip Kumar Author: Euler Taveira Reviewed-by: Michael Paquier, Masahiko Sawada Discussion: https://postgr.es/m/CAFiTN-u64S5bUiPL1q5kwpHNd0hRnf1OE-bzxNiOs5zo84i51w@mail.gmail.com Backpatch-through: 10
1 parent ee39a4b commit 70ae82b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/backend/executor/execReplication.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
5555
int2vector *indkey = &idxrel->rd_index->indkey;
5656
bool hasnulls = false;
5757

58-
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel));
58+
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel) ||
59+
RelationGetPrimaryKeyIndex(rel) == RelationGetRelid(idxrel));
5960

6061
indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
6162
Anum_pg_index_indclass, &isnull);

src/test/subscription/t/001_rep_changes.pl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
$node_publisher->safe_psql('postgres',
3535
"CREATE TABLE tab_include (a int, b text, CONSTRAINT covering PRIMARY KEY(a) INCLUDE(b))"
3636
);
37+
$node_publisher->safe_psql('postgres',
38+
"CREATE TABLE tab_full_pk (a int primary key, b text)");
39+
$node_publisher->safe_psql('postgres',
40+
"ALTER TABLE tab_full_pk REPLICA IDENTITY FULL");
3741
# Let this table with REPLICA IDENTITY NOTHING, allowing only INSERT changes.
3842
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
3943
$node_publisher->safe_psql('postgres',
@@ -46,6 +50,10 @@
4650
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full2 (x text)");
4751
$node_subscriber->safe_psql('postgres',
4852
"CREATE TABLE tab_rep (a int primary key)");
53+
$node_subscriber->safe_psql('postgres',
54+
"CREATE TABLE tab_full_pk (a int primary key, b text)");
55+
$node_subscriber->safe_psql('postgres',
56+
"ALTER TABLE tab_full_pk REPLICA IDENTITY FULL");
4957
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
5058

5159
# different column count and order than on publisher
@@ -64,7 +72,7 @@
6472
$node_publisher->safe_psql('postgres',
6573
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
6674
$node_publisher->safe_psql('postgres',
67-
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing"
75+
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing, tab_full_pk"
6876
);
6977
$node_publisher->safe_psql('postgres',
7078
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
@@ -103,6 +111,9 @@
103111
$node_publisher->safe_psql('postgres',
104112
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
105113

114+
$node_publisher->safe_psql('postgres',
115+
"INSERT INTO tab_full_pk VALUES (1, 'foo')");
116+
106117
$node_publisher->safe_psql('postgres',
107118
"INSERT INTO tab_nothing VALUES (generate_series(1,20))");
108119

@@ -160,6 +171,8 @@
160171
"UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
161172
$node_publisher->safe_psql('postgres',
162173
"UPDATE tab_mixed SET b = 'baz' WHERE a = 1");
174+
$node_publisher->safe_psql('postgres',
175+
"UPDATE tab_full_pk SET b = 'bar' WHERE a = 1");
163176

164177
$node_publisher->wait_for_catchup($appname);
165178

0 commit comments

Comments
 (0)