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

Commit1950fab

Browse files
committed
Disable COPY FROM to foreign parts, because no generic impl exists.
1 parentd45843e commit1950fab

File tree

3 files changed

+27
-42
lines changed

3 files changed

+27
-42
lines changed

‎contrib/file_fdw/output/file_fdw.source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ SELECT tableoid::regclass, * FROM p2;
315315
(0 rows)
316316

317317
COPY pt FROM '@abs_srcdir@/data/list2.bad' with (format 'csv', delimiter ','); -- ERROR
318-
ERROR:FDW adapter for relation "p1" doesn't support COPY FROM
318+
ERROR:cannot route inserted tuples to a foreign table
319319
CONTEXT: COPY pt, line 2: "1,qux"
320320
COPY pt FROM '@abs_srcdir@/data/list2.csv' with (format 'csv', delimiter ',');
321321
SELECT tableoid::regclass, * FROM pt;

‎src/backend/commands/copy.c

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ static void CopySendInt32(CopyState cstate, int32 val);
180180
staticboolCopyGetInt32(CopyStatecstate,int32*val);
181181
staticvoidCopySendInt16(CopyStatecstate,int16val);
182182
staticboolCopyGetInt16(CopyStatecstate,int16*val);
183-
staticvoidInitForeignCopyFrom(EState*estate,ResultRelInfo*resultRelInfo,
184-
CopyStatecstate,char*dest_relname);
185-
staticvoidEndForeignCopyFrom(EState*estate,ResultRelInfo*resultRelInfo);
186183

187184

188185
/*
@@ -2314,7 +2311,6 @@ CopyFrom(CopyState cstate)
23142311
TupleTableSlot*partition_tuple_slot;
23152312
intnum_parted,
23162313
num_partitions;
2317-
inti;
23182314

23192315
ExecSetupPartitionTupleRouting(cstate->rel,
23202316
1,
@@ -2351,16 +2347,15 @@ CopyFrom(CopyState cstate)
23512347
gettext_noop("could not convert row type"));
23522348
}
23532349
}
2354-
2355-
/* If some partitions are foreign tables, init copy on remote end */
2356-
for (i=0;i<num_partitions;i++)
2357-
{
2358-
InitForeignCopyFrom(estate,partitions+i,cstate,NULL);
2359-
}
23602350
}
23612351

23622352
/* If we are copying to foreign table, init it */
2363-
InitForeignCopyFrom(estate,resultRelInfo,cstate,NULL);
2353+
if (resultRelInfo->ri_FdwRoutine&&
2354+
FdwCopyFromIsSupported(resultRelInfo->ri_FdwRoutine))
2355+
{
2356+
resultRelInfo->ri_FdwRoutine->
2357+
BeginForeignCopyFrom(estate,resultRelInfo,cstate,NULL);
2358+
}
23642359

23652360
/*
23662361
* It's more efficient to prepare a bunch of tuples for insertion, and
@@ -2490,6 +2485,12 @@ CopyFrom(CopyState cstate)
24902485
saved_resultRelInfo=resultRelInfo;
24912486
resultRelInfo=cstate->partitions+leaf_part_index;
24922487

2488+
/* We do not yet have a way to insert into a foreign partition */
2489+
if (resultRelInfo->ri_FdwRoutine)
2490+
ereport(ERROR,
2491+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2492+
errmsg("cannot route inserted tuples to a foreign table")));
2493+
24932494
/*
24942495
* For ExecInsertIndexTuples() to work on the partition's indexes
24952496
*/
@@ -2710,7 +2711,12 @@ CopyFrom(CopyState cstate)
27102711
/*
27112712
* Shut down FDW.
27122713
*/
2713-
EndForeignCopyFrom(estate,resultRelInfo);
2714+
if (resultRelInfo->ri_FdwRoutine&&
2715+
FdwCopyFromIsSupported(resultRelInfo->ri_FdwRoutine))
2716+
{
2717+
resultRelInfo->ri_FdwRoutine->EndForeignCopyFrom(
2718+
estate,resultRelInfo);
2719+
}
27142720

27152721
/* Close all the partitioned tables, leaf partitions, and their indices */
27162722
if (cstate->partition_dispatch_info)
@@ -2734,8 +2740,6 @@ CopyFrom(CopyState cstate)
27342740
{
27352741
ResultRelInfo*resultRelInfo=cstate->partitions+i;
27362742

2737-
EndForeignCopyFrom(estate,resultRelInfo);
2738-
27392743
ExecCloseIndices(resultRelInfo);
27402744
heap_close(resultRelInfo->ri_RelationDesc,NoLock);
27412745
}
@@ -4726,30 +4730,3 @@ CreateCopyDestReceiver(void)
47264730

47274731
return (DestReceiver*)self;
47284732
}
4729-
4730-
/*
4731-
* Start COPY FROM on foreign relation, if possible. If not, just do nothing.
4732-
*/
4733-
staticvoidInitForeignCopyFrom(EState*estate,ResultRelInfo*resultRelInfo,
4734-
CopyStatecstate,char*dest_relname)
4735-
{
4736-
if (resultRelInfo->ri_FdwRoutine&&
4737-
FdwCopyFromIsSupported(resultRelInfo->ri_FdwRoutine))
4738-
{
4739-
resultRelInfo->ri_FdwRoutine->
4740-
BeginForeignCopyFrom(estate,resultRelInfo,cstate,dest_relname);
4741-
}
4742-
}
4743-
4744-
/*
4745-
* Finish COPY FROM on foreign relation, if needed.
4746-
*/
4747-
staticvoidEndForeignCopyFrom(EState*estate,ResultRelInfo*resultRelInfo)
4748-
{
4749-
if (resultRelInfo->ri_FdwRoutine&&
4750-
FdwCopyFromIsSupported(resultRelInfo->ri_FdwRoutine))
4751-
{
4752-
resultRelInfo->ri_FdwRoutine->EndForeignCopyFrom(
4753-
estate,resultRelInfo);
4754-
}
4755-
}

‎src/include/foreign/fdwapi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ typedef bool (*IsForeignScanParallelSafe_function) (PlannerInfo *root,
160160
RelOptInfo*rel,
161161
RangeTblEntry*rte);
162162

163+
/*
164+
* These functions are not documented in fdwhandler.sgml because the interface
165+
* is pretty unstable and weird, it hardly would be useful for anyone but
166+
* shardman. In particular,
167+
* - There is no way to COPY binary data.
168+
* - Private CopyState is exported.
169+
* - I am not sure about passing parent_rinfo.
170+
*/
163171
typedefvoid (*BeginForeignCopyFrom_function) (EState*estate,
164172
ResultRelInfo*rinfo,
165173
CopyStatecstate,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp