Skip to content

Commit 7ccb2f5

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 474e7da commit 7ccb2f5

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
@@ -57,7 +57,8 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
5757
int2vector *indkey = &idxrel->rd_index->indkey;
5858
bool hasnulls = false;
5959

60-
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel));
60+
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel) ||
61+
RelationGetPrimaryKeyIndex(rel) == RelationGetRelid(idxrel));
6162

6263
indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
6364
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");
@@ -102,6 +110,9 @@
102110
$node_publisher->safe_psql('postgres',
103111
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
104112

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

@@ -159,6 +170,8 @@
159170
"UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
160171
$node_publisher->safe_psql('postgres',
161172
"UPDATE tab_mixed SET b = 'baz' WHERE a = 1");
173+
$node_publisher->safe_psql('postgres',
174+
"UPDATE tab_full_pk SET b = 'bar' WHERE a = 1");
162175

163176
$node_publisher->wait_for_catchup('tap_sub');
164177

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