mirror of
https://github.com/postgres/postgres.git
synced 2025-05-31 03:21:24 +03:00
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
This commit is contained in:
parent
9d66ea5dee
commit
3acb30b498
@ -55,7 +55,8 @@ build_replindex_scan_key(ScanKey skey, Relation rel, Relation idxrel,
|
|||||||
int2vector *indkey = &idxrel->rd_index->indkey;
|
int2vector *indkey = &idxrel->rd_index->indkey;
|
||||||
bool hasnulls = false;
|
bool hasnulls = false;
|
||||||
|
|
||||||
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel));
|
Assert(RelationGetReplicaIndex(rel) == RelationGetRelid(idxrel) ||
|
||||||
|
RelationGetPrimaryKeyIndex(rel) == RelationGetRelid(idxrel));
|
||||||
|
|
||||||
indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
|
indclassDatum = SysCacheGetAttr(INDEXRELID, idxrel->rd_indextuple,
|
||||||
Anum_pg_index_indclass, &isnull);
|
Anum_pg_index_indclass, &isnull);
|
||||||
|
@ -31,6 +31,10 @@ $node_publisher->safe_psql('postgres',
|
|||||||
"CREATE TABLE tab_mixed (a int primary key, b text, c numeric)");
|
"CREATE TABLE tab_mixed (a int primary key, b text, c numeric)");
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"INSERT INTO tab_mixed (a, b, c) VALUES (1, 'foo', 1.1)");
|
"INSERT INTO tab_mixed (a, b, c) VALUES (1, 'foo', 1.1)");
|
||||||
|
$node_publisher->safe_psql('postgres',
|
||||||
|
"CREATE TABLE tab_full_pk (a int primary key, b text)");
|
||||||
|
$node_publisher->safe_psql('postgres',
|
||||||
|
"ALTER TABLE tab_full_pk REPLICA IDENTITY FULL");
|
||||||
# Let this table with REPLICA IDENTITY NOTHING, allowing only INSERT changes.
|
# Let this table with REPLICA IDENTITY NOTHING, allowing only INSERT changes.
|
||||||
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
|
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
@ -43,6 +47,10 @@ $node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full (a int)");
|
|||||||
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full2 (x text)");
|
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_full2 (x text)");
|
||||||
$node_subscriber->safe_psql('postgres',
|
$node_subscriber->safe_psql('postgres',
|
||||||
"CREATE TABLE tab_rep (a int primary key)");
|
"CREATE TABLE tab_rep (a int primary key)");
|
||||||
|
$node_subscriber->safe_psql('postgres',
|
||||||
|
"CREATE TABLE tab_full_pk (a int primary key, b text)");
|
||||||
|
$node_subscriber->safe_psql('postgres',
|
||||||
|
"ALTER TABLE tab_full_pk REPLICA IDENTITY FULL");
|
||||||
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
|
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_nothing (a int)");
|
||||||
|
|
||||||
# different column count and order than on publisher
|
# different column count and order than on publisher
|
||||||
@ -56,7 +64,7 @@ $node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub");
|
|||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
|
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_nothing"
|
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_nothing, tab_full_pk"
|
||||||
);
|
);
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
|
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
|
||||||
@ -99,6 +107,9 @@ $node_publisher->safe_psql('postgres', "UPDATE tab_rep SET a = -a");
|
|||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
|
"INSERT INTO tab_mixed VALUES (2, 'bar', 2.2)");
|
||||||
|
|
||||||
|
$node_publisher->safe_psql('postgres',
|
||||||
|
"INSERT INTO tab_full_pk VALUES (1, 'foo')");
|
||||||
|
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"INSERT INTO tab_nothing VALUES (generate_series(1,20))");
|
"INSERT INTO tab_nothing VALUES (generate_series(1,20))");
|
||||||
|
|
||||||
@ -146,6 +157,8 @@ $node_publisher->safe_psql('postgres',
|
|||||||
"UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
|
"UPDATE tab_full2 SET x = 'bb' WHERE x = 'b'");
|
||||||
$node_publisher->safe_psql('postgres',
|
$node_publisher->safe_psql('postgres',
|
||||||
"UPDATE tab_mixed SET b = 'baz' WHERE a = 1");
|
"UPDATE tab_mixed SET b = 'baz' WHERE a = 1");
|
||||||
|
$node_publisher->safe_psql('postgres',
|
||||||
|
"UPDATE tab_full_pk SET b = 'bar' WHERE a = 1");
|
||||||
|
|
||||||
# Wait for subscription to catch up
|
# Wait for subscription to catch up
|
||||||
$node_publisher->poll_query_until('postgres', $caughtup_query)
|
$node_publisher->poll_query_until('postgres', $caughtup_query)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user