Skip to content

Commit

Permalink
Merge 5de5123 into 134f009
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocitus committed Dec 3, 2018
2 parents 134f009 + 5de5123 commit 2fa449a
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions cstore_fdw.c
Expand Up @@ -135,11 +135,14 @@ static List * CStorePlanForeignModify(PlannerInfo *plannerInfo, ModifyTable *pla
static void CStoreBeginForeignModify(ModifyTableState *modifyTableState,
ResultRelInfo *relationInfo, List *fdwPrivate,
int subplanIndex, int executorflags);
static void CStoreBeginForeignInsert(ModifyTableState *modifyTableState,
ResultRelInfo *relationInfo);
static TupleTableSlot * CStoreExecForeignInsert(EState *executorState,
ResultRelInfo *relationInfo,
TupleTableSlot *tupleSlot,
TupleTableSlot *planSlot);
static void CStoreEndForeignModify(EState *executorState, ResultRelInfo *relationInfo);
static void CStoreEndForeignInsert(EState *executorState, ResultRelInfo *relationInfo);


/* declarations for dynamic loading */
Expand Down Expand Up @@ -1206,6 +1209,11 @@ cstore_fdw_handler(PG_FUNCTION_ARGS)
fdwRoutine->ExecForeignInsert = CStoreExecForeignInsert;
fdwRoutine->EndForeignModify = CStoreEndForeignModify;

#if PG_VERSION_NUM >= 110000
fdwRoutine->BeginForeignInsert = CStoreBeginForeignInsert;
fdwRoutine->EndForeignInsert = CStoreEndForeignInsert;
#endif

PG_RETURN_POINTER(fdwRoutine);
}

Expand Down Expand Up @@ -2223,18 +2231,15 @@ CStorePlanForeignModify(PlannerInfo *plannerInfo, ModifyTable *plan,
}


/* CStoreBeginForeignModify prepares cstore table for insert operation. */
/*
* CStoreBeginForeignModify prepares cstore table for a modification.
* Only insert is currently supported.
*/
static void
CStoreBeginForeignModify(ModifyTableState *modifyTableState,
ResultRelInfo *relationInfo, List *fdwPrivate,
int subplanIndex, int executorFlags)
{
Oid foreignTableOid = InvalidOid;
CStoreFdwOptions *cstoreFdwOptions = NULL;
TupleDesc tupleDescriptor = NULL;
TableWriteState *writeState = NULL;
Relation relation = NULL;

/* if Explain with no Analyze, do nothing */
if (executorFlags & EXEC_FLAG_EXPLAIN_ONLY)
{
Expand All @@ -2243,6 +2248,23 @@ CStoreBeginForeignModify(ModifyTableState *modifyTableState,

Assert (modifyTableState->operation == CMD_INSERT);

CStoreBeginForeignInsert(modifyTableState, relationInfo);
}


/*
* CStoreBeginForeignInsert prepares a cstore table for an insert or rows
* coming from a COPY.
*/
static void
CStoreBeginForeignInsert(ModifyTableState *modifyTableState, ResultRelInfo *relationInfo)
{
Oid foreignTableOid = InvalidOid;
CStoreFdwOptions *cstoreFdwOptions = NULL;
TupleDesc tupleDescriptor = NULL;
TableWriteState *writeState = NULL;
Relation relation = NULL;

foreignTableOid = RelationGetRelid(relationInfo->ri_RelationDesc);
relation = heap_open(foreignTableOid, ShareUpdateExclusiveLock);
cstoreFdwOptions = CStoreGetOptions(foreignTableOid);
Expand Down Expand Up @@ -2286,9 +2308,22 @@ CStoreExecForeignInsert(EState *executorState, ResultRelInfo *relationInfo,
}


/* CStoreEndForeignModify ends the current insert operation. */
/*
* CStoreEndForeignModify ends the current modification. Only insert is currently
* supported.
*/
static void
CStoreEndForeignModify(EState *executorState, ResultRelInfo *relationInfo)
{
CStoreEndForeignInsert(executorState, relationInfo);
}


/*
* CStoreEndForeignInsert ends the current insert or COPY operation.
*/
static void
CStoreEndForeignInsert(EState *executorState, ResultRelInfo *relationInfo)
{
TableWriteState *writeState = (TableWriteState*) relationInfo->ri_FdwState;

Expand All @@ -2301,4 +2336,3 @@ CStoreEndForeignModify(EState *executorState, ResultRelInfo *relationInfo)
heap_close(relation, ShareUpdateExclusiveLock);
}
}

0 comments on commit 2fa449a

Please sign in to comment.