Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2731ce1

Browse files
author
Amit Kapila
committed
Handle no replica identity index case in RelationGetIdentityKeyBitmap.
Commit e7eea52 has introduced a new function RelationGetIdentityKeyBitmap which omits to handle the case where there is no replica identity index on a relation. Author: Mark Dilger Reviewed-by: Takamichi Osumi, Amit Kapila Discussion: https://www.postgresql.org/message-id/[email protected]
1 parent 3499df0 commit 2731ce1

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/backend/utils/cache/relcache.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5266,8 +5266,18 @@ RelationGetIdentityKeyBitmap(Relation relation)
52665266
if (indexoidlist == NIL)
52675267
return NULL;
52685268

5269-
/* Add referenced attributes to idindexattrs */
5269+
/* Fall out if there is no replica identity index */
5270+
if (!OidIsValid(relation->rd_replidindex))
5271+
return NULL;
5272+
5273+
/* Look up the description for the replica identity index */
52705274
indexDesc = RelationIdGetRelation(relation->rd_replidindex);
5275+
5276+
if (!RelationIsValid(indexDesc))
5277+
elog(ERROR, "could not open relation with OID %u",
5278+
relation->rd_replidindex);
5279+
5280+
/* Add referenced attributes to idindexattrs */
52715281
for (i = 0; i < indexDesc->rd_index->indnatts; i++)
52725282
{
52735283
int attrnum = indexDesc->rd_index->indkey.values[i];

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use warnings;
77
use PostgresNode;
88
use TestLib;
9-
use Test::More tests => 31;
9+
use Test::More tests => 32;
1010

1111
# Initialize publisher node
1212
my $node_publisher = get_new_node('publisher');
@@ -50,6 +50,10 @@
5050
$node_publisher->safe_psql('postgres',
5151
"ALTER TABLE tab_nothing REPLICA IDENTITY NOTHING");
5252

53+
# Replicate the changes without replica identity index
54+
$node_publisher->safe_psql('postgres', "CREATE TABLE tab_no_replidentity_index(c1 int)");
55+
$node_publisher->safe_psql('postgres', "CREATE INDEX idx_no_replidentity_index ON tab_no_replidentity_index(c1)");
56+
5357
# Setup structure on subscriber
5458
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_notrep (a int)");
5559
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_ins (a int)");
@@ -73,13 +77,17 @@
7377
"CREATE TABLE tab_include (a int, b text, CONSTRAINT covering PRIMARY KEY(a) INCLUDE(b))"
7478
);
7579

80+
# replication of the table without replica identity index
81+
$node_subscriber->safe_psql('postgres', "CREATE TABLE tab_no_replidentity_index(c1 int)");
82+
$node_subscriber->safe_psql('postgres', "CREATE INDEX idx_no_replidentity_index ON tab_no_replidentity_index(c1)");
83+
7684
# Setup logical replication
7785
my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
7886
$node_publisher->safe_psql('postgres', "CREATE PUBLICATION tap_pub");
7987
$node_publisher->safe_psql('postgres',
8088
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
8189
$node_publisher->safe_psql('postgres',
82-
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing, tab_full_pk"
90+
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_full2, tab_mixed, tab_include, tab_nothing, tab_full_pk, tab_no_replidentity_index"
8391
);
8492
$node_publisher->safe_psql('postgres',
8593
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
@@ -129,6 +137,8 @@
129137
"DELETE FROM tab_include WHERE a > 20");
130138
$node_publisher->safe_psql('postgres', "UPDATE tab_include SET a = -a");
131139

140+
$node_publisher->safe_psql('postgres', "INSERT INTO tab_no_replidentity_index VALUES(1)");
141+
132142
$node_publisher->wait_for_catchup('tap_sub');
133143

134144
$result = $node_subscriber->safe_psql('postgres',
@@ -152,6 +162,9 @@
152162
is($result, qq(20|-20|-1),
153163
'check replicated changes with primary key index with included columns');
154164

165+
is($node_subscriber->safe_psql('postgres', q(SELECT c1 FROM tab_no_replidentity_index)),
166+
1, "value replicated to subscriber without replica identity index");
167+
155168
# insert some duplicate rows
156169
$node_publisher->safe_psql('postgres',
157170
"INSERT INTO tab_full SELECT generate_series(1,10)");

0 commit comments

Comments
 (0)