Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit073ce40

Browse files
committed
Fix table syncing with different column order
Logical replication supports replicating between tables with differentcolumn order. But this failed for the initial table sync because of alogic error in how the column list for the internal COPY command wascomposed. Fix that and also add a test.Also fix a minor omission in the column name mapping cache. Whencreating the mapping list, it would not skip locally dropped columns.So if a remote column had the same name as a locally droppedcolumn (...pg.dropped...), then the expected error would not occur.
1 parent92ecb14 commit073ce40

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

‎src/backend/replication/logical/relation.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,13 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
277277
found=0;
278278
for (i=0;i<desc->natts;i++)
279279
{
280-
intattnum=logicalrep_rel_att_by_name(remoterel,
281-
NameStr(desc->attrs[i]->attname));
280+
intattnum;
281+
282+
if (desc->attrs[i]->attisdropped)
283+
continue;
284+
285+
attnum=logicalrep_rel_att_by_name(remoterel,
286+
NameStr(desc->attrs[i]->attname));
282287

283288
entry->attrmap[i]=attnum;
284289
if (attnum >=0)

‎src/backend/replication/logical/tablesync.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -492,25 +492,15 @@ static List *
492492
make_copy_attnamelist(LogicalRepRelMapEntry*rel)
493493
{
494494
List*attnamelist=NIL;
495-
TupleDescdesc=RelationGetDescr(rel->localrel);
496495
inti;
497496

498-
for (i=0;i<desc->natts;i++)
497+
for (i=0;i<rel->remoterel.natts;i++)
499498
{
500-
intremoteattnum=rel->attrmap[i];
501-
502-
/* Skip dropped attributes. */
503-
if (desc->attrs[i]->attisdropped)
504-
continue;
505-
506-
/* Skip attributes that are missing on remote side. */
507-
if (remoteattnum<0)
508-
continue;
509-
510499
attnamelist=lappend(attnamelist,
511-
makeString(rel->remoterel.attnames[remoteattnum]));
500+
makeString(rel->remoterel.attnames[i]));
512501
}
513502

503+
514504
returnattnamelist;
515505
}
516506

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::Moretests=>14;
6+
use Test::Moretests=>15;
77

88
# Initialize publisher node
99
my$node_publisher = get_new_node('publisher');
@@ -24,21 +24,28 @@
2424
"CREATE TABLE tab_full AS SELECT generate_series(1,10) AS a");
2525
$node_publisher->safe_psql('postgres',
2626
"CREATE TABLE tab_rep (a int primary key)");
27+
$node_publisher->safe_psql('postgres',
28+
"CREATE TABLE tab_mixed (a int primary key, b text)");
29+
$node_publisher->safe_psql('postgres',
30+
"INSERT INTO tab_mixed (a, b) VALUES (1, 'foo')");
2731

2832
# Setup structure on subscriber
2933
$node_subscriber->safe_psql('postgres',"CREATE TABLE tab_notrep (a int)");
3034
$node_subscriber->safe_psql('postgres',"CREATE TABLE tab_ins (a int)");
3135
$node_subscriber->safe_psql('postgres',"CREATE TABLE tab_full (a int)");
3236
$node_subscriber->safe_psql('postgres',
3337
"CREATE TABLE tab_rep (a int primary key)");
38+
# different column count and order than on publisher
39+
$node_subscriber->safe_psql('postgres',
40+
"CREATE TABLE tab_mixed (c text, b text, a int primary key)");
3441

3542
# Setup logical replication
3643
my$publisher_connstr =$node_publisher->connstr .' dbname=postgres';
3744
$node_publisher->safe_psql('postgres',"CREATE PUBLICATION tap_pub");
3845
$node_publisher->safe_psql('postgres',
3946
"CREATE PUBLICATION tap_pub_ins_only WITH (publish = insert)");
4047
$node_publisher->safe_psql('postgres',
41-
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full");
48+
"ALTER PUBLICATION tap_pub ADD TABLE tab_rep, tab_full, tab_mixed");
4249
$node_publisher->safe_psql('postgres',
4350
"ALTER PUBLICATION tap_pub_ins_only ADD TABLE tab_ins");
4451

@@ -88,6 +95,10 @@
8895
"SELECT count(*), min(a), max(a) FROM tab_rep");
8996
is($result,qq(20|-20|-1),'check replicated changes on subscriber');
9097

98+
$result =$node_subscriber->safe_psql('postgres',
99+
"SELECT c, b, a FROM tab_mixed");
100+
is($result,qq(|foo|1),'check replicated changes with different column order');
101+
91102
# insert some duplicate rows
92103
$node_publisher->safe_psql('postgres',
93104
"INSERT INTO tab_full SELECT generate_series(1,10)");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp