From 1bbc557d12316820b8f8a954a855ed51d9facb79 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Tue, 4 Dec 2018 01:15:40 +0100 Subject: [PATCH] Mark foreign scan as parallel safe --- cstore_fdw.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cstore_fdw.c b/cstore_fdw.c index cd37cb4..63ac172 100644 --- a/cstore_fdw.c +++ b/cstore_fdw.c @@ -143,6 +143,10 @@ static TupleTableSlot * CStoreExecForeignInsert(EState *executorState, TupleTableSlot *planSlot); static void CStoreEndForeignModify(EState *executorState, ResultRelInfo *relationInfo); static void CStoreEndForeignInsert(EState *executorState, ResultRelInfo *relationInfo); +#if PG_VERSION_NUM >= 90600 +static bool CStoreIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel, + RangeTblEntry *rte); +#endif /* declarations for dynamic loading */ @@ -1214,6 +1218,10 @@ cstore_fdw_handler(PG_FUNCTION_ARGS) fdwRoutine->EndForeignInsert = CStoreEndForeignInsert; #endif +#if PG_VERSION_NUM >= 90600 + fdwRoutine->IsForeignScanParallelSafe = CStoreIsForeignScanParallelSafe; +#endif + PG_RETURN_POINTER(fdwRoutine); } @@ -2336,3 +2344,23 @@ CStoreEndForeignInsert(EState *executorState, ResultRelInfo *relationInfo) heap_close(relation, ShareUpdateExclusiveLock); } } + + +#if PG_VERSION_NUM >= 90600 +/* + * CStoreIsForeignScanParallelSafe always returns true to indicate that + * reading from a cstore_fdw table in a parallel worker is safe. This + * does not enable parallelism for queries on individual cstore_fdw + * tables, but does allow parallel scans of cstore_fdw partitions. + * + * cstore_fdw is parallel-safe because all writes are immediately committed + * to disk and then read from disk. There is no uncommitted state that needs + * to be shared across processes. + */ +static bool +CStoreIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel, + RangeTblEntry *rte) +{ + return true; +} +#endif