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

Commit16d11d6

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 parent27ca0bc commit16d11d6

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
@@ -8251,6 +8251,11 @@ select tableoid::regclass, * FROM remp2;
82518251
(3 rows)
82528252

82538253
delete from itrtest;
8254+
-- MERGE ought to fail cleanly
8255+
merge into itrtest using (select 1, 'foo') as source on (true)
8256+
when matched then do nothing;
8257+
ERROR: cannot execute MERGE on relation "remp1"
8258+
DETAIL: This operation is not supported for foreign tables.
82548259
create unique index loct1_idx on loct1 (a);
82558260
-- DO NOTHING without an inference specification is supported
82568261
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
@@ -2194,6 +2194,10 @@ select tableoid::regclass, * FROM remp2;
21942194

21952195
deletefrom itrtest;
21962196

2197+
-- MERGE ought to fail cleanly
2198+
merge into itrtest using (select1,'foo')as sourceon (true)
2199+
when matched then do nothing;
2200+
21972201
createunique indexloct1_idxon loct1 (a);
21982202

21992203
-- 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
@@ -7084,12 +7084,32 @@ make_modifytable(PlannerInfo *root, Plan *subplan,
70847084
RelOptInfo*resultRel=root->simple_rel_array[rti];
70857085

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

70927111
Assert(rte->rtekind==RTE_RELATION);
7112+
Assert(operation!=CMD_MERGE);
70937113
if (rte->relkind==RELKIND_FOREIGN_TABLE)
70947114
fdwroutine=GetFdwRoutineByRelId(rte->relid);
70957115
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp