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

Commitcba4e78

Browse files
committed
Disallow MERGE cleanly for foreign partitions
While directly targetting a foreign table with MERGE was alreadyexpressly forbidden, we failed to catch the case of a partitioned tablethat has a foreign table as a partition; and the result if you try is anincomprehensible error. Fix that by adding a specific check.Backpatch to 15.Reported-by: Tatsuhiro Nakamori <bt22nakamorit@oss.nttdata.com>Discussion:https://postgr.es/m/bt22nakamorit@oss.nttdata.com
1 parent1054c60 commitcba4e78

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

‎contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8284,6 +8284,11 @@ select tableoid::regclass, * FROM remp2;
82848284
(3 rows)
82858285

82868286
delete from itrtest;
8287+
-- MERGE ought to fail cleanly
8288+
merge into itrtest using (select 1, 'foo') as source on (true)
8289+
when matched then do nothing;
8290+
ERROR: cannot execute MERGE on relation "remp1"
8291+
DETAIL: This operation is not supported for foreign tables.
82878292
create unique index loct1_idx on loct1 (a);
82888293
-- DO NOTHING without an inference specification is supported
82898294
insert into itrtest values (1, 'foo') on conflict do nothing returning *;

‎contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,10 @@ select tableoid::regclass, * FROM remp2;
22072207

22082208
deletefrom itrtest;
22092209

2210+
-- MERGE ought to fail cleanly
2211+
merge into itrtest using (select1,'foo')as sourceon (true)
2212+
when matched then do nothing;
2213+
22102214
createunique indexloct1_idxon loct1 (a);
22112215

22122216
-- DO NOTHING without an inference specification is supported

‎src/backend/optimizer/plan/createplan.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7078,12 +7078,32 @@ make_modifytable(PlannerInfo *root, Plan *subplan,
70787078
RelOptInfo*resultRel=root->simple_rel_array[rti];
70797079

70807080
fdwroutine=resultRel->fdwroutine;
7081+
7082+
/*
7083+
* MERGE is not currently supported for foreign tables and we
7084+
* already checked when the table mentioned in the query is
7085+
* foreign; but we can still get here if a partitioned table has a
7086+
* foreign table as partition. Disallow that now, to avoid an
7087+
* uglier error message later.
7088+
*/
7089+
if (operation==CMD_MERGE&&fdwroutine!=NULL)
7090+
{
7091+
RangeTblEntry*rte=root->simple_rte_array[rti];
7092+
7093+
ereport(ERROR,
7094+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
7095+
errmsg("cannot execute MERGE on relation \"%s\"",
7096+
get_rel_name(rte->relid)),
7097+
errdetail_relkind_not_supported(rte->relkind));
7098+
}
7099+
70817100
}
70827101
else
70837102
{
70847103
RangeTblEntry*rte=planner_rt_fetch(rti,root);
70857104

70867105
Assert(rte->rtekind==RTE_RELATION);
7106+
Assert(operation!=CMD_MERGE);
70877107
if (rte->relkind==RELKIND_FOREIGN_TABLE)
70887108
fdwroutine=GetFdwRoutineByRelId(rte->relid);
70897109
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp