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

Commit71e561b

Browse files
committed
Fix construction of updated-columns bitmap in logical replication.
Commitb9c130a failed to apply the publisher-to-subscriber columnmapping while checking which columns were updated. Perhaps lesssignificantly, it didn't exclude dropped columns either. This couldresult in an incorrect updated-columns bitmap and thus wrong decisionsabout whether to fire column-specific triggers on the subscriber whileapplying updates. In HEAD (since commit9de77b5), it could alsoresult in accesses off the end of the colstatus array, as detected bybuildfarm member skink. Fix the logic, and adjust 003_constraints.plso that the problem is exposed in unpatched code.In HEAD, also add some assertions to check that we don't access offthe ends of these newly variable-sized arrays.Back-patch to v10, asb9c130a was.Discussion:https://postgr.es/m/CAH2-Wz=79hKQ4++c5A060RYbjTHgiYTHz=fw6mptCtgghH2gJA@mail.gmail.com
1 parentab5ad0c commit71e561b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,16 @@ apply_handle_update(StringInfo s)
732732
target_rte=list_nth(estate->es_range_table,0);
733733
for (inti=0;i<remoteslot->tts_tupleDescriptor->natts;i++)
734734
{
735-
if (newtup.changed[i])
736-
target_rte->updatedCols=bms_add_member(target_rte->updatedCols,
737-
i+1-FirstLowInvalidHeapAttributeNumber);
735+
Form_pg_attributeatt=TupleDescAttr(remoteslot->tts_tupleDescriptor,i);
736+
intremoteattnum=rel->attrmap[i];
737+
738+
if (!att->attisdropped&&remoteattnum >=0)
739+
{
740+
if (newtup.changed[remoteattnum])
741+
target_rte->updatedCols=
742+
bms_add_member(target_rte->updatedCols,
743+
i+1-FirstLowInvalidHeapAttributeNumber);
744+
}
738745
}
739746

740747
fill_extraUpdatedCols(target_rte,RelationGetDescr(rel->localrel));

‎src/test/subscription/t/003_constraints.pl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
$node_publisher->safe_psql('postgres',
2020
"CREATE TABLE tab_fk (bid int PRIMARY KEY);");
2121
$node_publisher->safe_psql('postgres',
22-
"CREATE TABLE tab_fk_ref (id int PRIMARY KEY, bid int REFERENCES tab_fk (bid));"
22+
"CREATE TABLE tab_fk_ref (id int PRIMARY KEY,junk text,bid int REFERENCES tab_fk (bid));"
2323
);
2424

25-
# Setup structure on subscriber
25+
# Setup structure on subscriber; column order intentionally different
2626
$node_subscriber->safe_psql('postgres',
2727
"CREATE TABLE tab_fk (bid int PRIMARY KEY);");
2828
$node_subscriber->safe_psql('postgres',
29-
"CREATE TABLE tab_fk_ref (id int PRIMARY KEY, bid int REFERENCES tab_fk (bid));"
29+
"CREATE TABLE tab_fk_ref (id int PRIMARY KEY, bid int REFERENCES tab_fk (bid), junk text);"
3030
);
3131

3232
# Setup logical replication
@@ -42,8 +42,10 @@
4242

4343
$node_publisher->safe_psql('postgres',
4444
"INSERT INTO tab_fk (bid) VALUES (1);");
45+
# "junk" value is meant to be large enough to force out-of-line storage
4546
$node_publisher->safe_psql('postgres',
46-
"INSERT INTO tab_fk_ref (id, bid) VALUES (1, 1);");
47+
"INSERT INTO tab_fk_ref (id, bid, junk) VALUES (1, 1, repeat(pi()::text,20000));"
48+
);
4749

4850
$node_publisher->wait_for_catchup('tap_sub');
4951

@@ -126,7 +128,8 @@ BEGIN
126128

127129
$result =$node_subscriber->safe_psql('postgres',
128130
"SELECT count(*), min(id), max(id) FROM tab_fk_ref;");
129-
is($result,qq(2|1|2),'check column trigger applied on even for other column');
131+
is($result,qq(2|1|2),
132+
'check column trigger applied even on update for other column');
130133

131134
$node_subscriber->stop('fast');
132135
$node_publisher->stop('fast');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp