diff --git a/src/backend/distributed/commands/multi_copy.c b/src/backend/distributed/commands/multi_copy.c index d30a6e636..69a4a2804 100644 --- a/src/backend/distributed/commands/multi_copy.c +++ b/src/backend/distributed/commands/multi_copy.c @@ -156,7 +156,7 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag) HTAB *shardConnectionHash = NULL; List *connectionList = NIL; MemoryContext tupleContext = NULL; - MemoryContext outputContext = NULL; + MemoryContext outputRowContext = NULL; CopyState copyState = NULL; TupleDesc tupleDescriptor = NULL; uint32 columnCount = 0; @@ -290,23 +290,25 @@ CitusCopyFrom(CopyStmt *copyStatement, char *completionTag) * files. */ tupleContext = AllocSetContextCreate(CurrentMemoryContext, - "COPY Row Memory Context", + "COPY FROM Row Memory Context", ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_MAXSIZE); - outputContext = AllocSetContextCreate(CurrentMemoryContext, - "COPY Output Memory Context", - ALLOCSET_DEFAULT_MINSIZE, - ALLOCSET_DEFAULT_INITSIZE, - ALLOCSET_DEFAULT_MAXSIZE); - - columnOutputFunctions = ColumnOutputFunctions(tupleDescriptor, true); + /* we use outputRowContext to serialize row to send to workers */ + outputRowContext = AllocSetContextCreate(CurrentMemoryContext, + "COPY TO Row Memory Context", + ALLOCSET_DEFAULT_MINSIZE, + ALLOCSET_DEFAULT_INITSIZE, + ALLOCSET_DEFAULT_MAXSIZE); rowOutputState = (OutputCopyState) palloc0(sizeof(OutputCopyStateData)); rowOutputState->binary = true; rowOutputState->fe_msgbuf = makeStringInfo(); - rowOutputState->rowcontext = outputContext; + rowOutputState->rowcontext = outputRowContext; + + columnOutputFunctions = ColumnOutputFunctions(tupleDescriptor, + rowOutputState->binary); /* we use a PG_TRY block to roll back on errors (e.g. in NextCopyFrom) */ PG_TRY(); diff --git a/src/include/distributed/multi_copy.h b/src/include/distributed/multi_copy.h index 483d65601..8aab98747 100644 --- a/src/include/distributed/multi_copy.h +++ b/src/include/distributed/multi_copy.h @@ -43,13 +43,13 @@ typedef struct OutputCopyStateData typedef struct OutputCopyStateData *OutputCopyState; + +/* function declarations for copying into a distributed table */ extern FmgrInfo * ColumnOutputFunctions(TupleDesc rowDescriptor, bool binaryFormat); extern void OutputRow(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor, OutputCopyState rowOutputState, FmgrInfo *columnOutputFunctions); extern void CopySendBinaryHeaders(OutputCopyState headerOutputState); extern void CopySendBinaryFooters(OutputCopyState footerOutputState); - -/* function declarations for copying into a distributed table */ extern void CitusCopyFrom(CopyStmt *copyStatement, char *completionTag);