likely unnecessary hardening of COPY

cmake_branch_point
Brian Cloutier 2018-04-10 22:43:30 +00:00 committed by Brian Cloutier
parent e06e9842c0
commit 73e1d81bb3
1 changed files with 54 additions and 40 deletions

View File

@ -323,6 +323,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
uint64 processedRowCount = 0;
ErrorContextCallback errorCallback;
volatile MemoryContext oldContext;
/* allocate column values and nulls arrays */
distributedRelation = heap_open(tableId, RowExclusiveLock);
@ -405,6 +406,9 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
copiedDistributedRelationTuple->relkind = RELKIND_RELATION;
}
PG_TRY();
{
/* initialize copy state to read from COPY data source */
#if (PG_VERSION_NUM >= 100000)
copyState = BeginCopyFrom(NULL,
@ -431,7 +435,6 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
while (true)
{
bool nextRowFound = false;
MemoryContext oldContext = NULL;
ResetPerTupleExprContext(executorState);
@ -455,6 +458,17 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
processedRowCount += 1;
}
}
PG_CATCH();
{
if (oldContext != NULL)
{
MemoryContextSwitchTo(oldContext);
}
AtEOXact_Files();
PG_RE_THROW();
}
PG_END_TRY();
EndCopyFrom(copyState);