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

Commit4d3f7e7

Browse files
committed
Defend against unsupported partition relkind in logical replication worker.
Since partitions can be foreign tables not only plain tables, butlogical replication only supports plain tables, we'd better check therelkind of a partition after we find it. (There was some discussionof checking this when adding a partitioned table to a subscription;but that would be inadequate since the troublesome partition could beadded later.) Without this, the situation leads to a segfault orassertion failure.In passing, add a separate variable for the target Relation ofa cross-partition UPDATE; reusing partrel seemed mighty confusingand error-prone.Shi Yu and Tom Lane, per report from Ilya Gladyshev. Back-patchto v13 where logical replication into partitioned tables becamea thing.Discussion:https://postgr.es/m/6b93e3748ba43298694f376ca8797279d7945e29.camel@gmail.com
1 parent197cbca commit4d3f7e7

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,15 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
10951095
Assert(partrelinfo!=NULL);
10961096
partrel=partrelinfo->ri_RelationDesc;
10971097

1098+
/*
1099+
* Check for supported relkind. We need this since partitions might be of
1100+
* unsupported relkinds; and the set of partitions can change, so checking
1101+
* at CREATE/ALTER SUBSCRIPTION would be insufficient.
1102+
*/
1103+
CheckSubscriptionRelkind(partrel->rd_rel->relkind,
1104+
get_namespace_name(RelationGetNamespace(partrel)),
1105+
RelationGetRelationName(partrel));
1106+
10981107
/*
10991108
* To perform any of the operations below, the tuple must match the
11001109
* partition's rowtype. Convert if needed or just copy, using a dedicated
@@ -1151,6 +1160,7 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
11511160
{
11521161
TupleTableSlot*localslot;
11531162
ResultRelInfo*partrelinfo_new;
1163+
Relationpartrel_new;
11541164
boolfound;
11551165

11561166
/* Get the matching local tuple from the partition. */
@@ -1235,14 +1245,19 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
12351245
slot_getallattrs(remoteslot);
12361246
}
12371247

1238-
12391248
/* Find the new partition. */
12401249
oldctx=MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
12411250
partrelinfo_new=ExecFindPartition(mtstate,relinfo,
12421251
proute,remoteslot,
12431252
estate);
12441253
MemoryContextSwitchTo(oldctx);
12451254
Assert(partrelinfo_new!=partrelinfo);
1255+
partrel_new=partrelinfo_new->ri_RelationDesc;
1256+
1257+
/* Check that new partition also has supported relkind. */
1258+
CheckSubscriptionRelkind(partrel_new->rd_rel->relkind,
1259+
get_namespace_name(RelationGetNamespace(partrel_new)),
1260+
RelationGetRelationName(partrel_new));
12461261

12471262
/* DELETE old tuple found in the old partition. */
12481263
estate->es_result_relation_info=partrelinfo;
@@ -1257,11 +1272,10 @@ apply_handle_tuple_routing(ApplyExecutionData *edata,
12571272
* partition rowtype.
12581273
*/
12591274
oldctx=MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
1260-
partrel=partrelinfo_new->ri_RelationDesc;
12611275
partinfo=partrelinfo_new->ri_PartitionInfo;
12621276
remoteslot_part=partinfo->pi_PartitionTupleSlot;
12631277
if (remoteslot_part==NULL)
1264-
remoteslot_part=table_slot_create(partrel,
1278+
remoteslot_part=table_slot_create(partrel_new,
12651279
&estate->es_tupleTable);
12661280
map=partinfo->pi_RootToPartitionMap;
12671281
if (map!=NULL)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp