diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-02-26 16:14:46 +0530 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-02-26 16:14:46 +0530 |
commit | 35746bc348b6bf1f690fe17f4f80cfb68e22f504 (patch) | |
tree | 249efeced5372af345491e39d2c442f3ca610b6d /src | |
parent | 9117985b6ba9beda4f280f596035649fc23b6233 (diff) | |
download | postgresql-35746bc348b6bf1f690fe17f4f80cfb68e22f504.tar.gz postgresql-35746bc348b6bf1f690fe17f4f80cfb68e22f504.zip |
Add new FDW API to test for parallel-safety.
This is basically a bug fix; the old code assumes that a ForeignScan
is always parallel-safe, but for postgres_fdw, for example, this is
definitely false. It should be true for file_fdw, though, since a
worker can read a file from the filesystem just as well as any other
backend process.
Original patch by Thomas Munro. Documentation, and changes to the
comments, by me.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/path/allpaths.c | 17 | ||||
-rw-r--r-- | src/include/foreign/fdwapi.h | 5 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index bcb668fac5f..870a46ce74e 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -527,6 +527,23 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel, return; return; } + + /* + * Ask FDWs whether they can support performing a ForeignScan + * within a worker. Most often, the answer will be no. For + * example, if the nature of the FDW is such that it opens a TCP + * connection with a remote server, each parallel worker would end + * up with a separate connection, and these connections might not + * be appropriately coordinated between workers and the leader. + */ + if (rte->relkind == RELKIND_FOREIGN_TABLE) + { + Assert(rel->fdwroutine); + if (!rel->fdwroutine->IsForeignScanParallelSafe) + return; + if (!rel->fdwroutine->IsForeignScanParallelSafe(root, rel, rte)) + return; + } break; case RTE_SUBQUERY: diff --git a/src/include/foreign/fdwapi.h b/src/include/foreign/fdwapi.h index 9fafab06e95..ae3c230d667 100644 --- a/src/include/foreign/fdwapi.h +++ b/src/include/foreign/fdwapi.h @@ -131,6 +131,10 @@ typedef void (*InitializeDSMForeignScan_function) (ForeignScanState *node, typedef void (*InitializeWorkerForeignScan_function) (ForeignScanState *node, shm_toc *toc, void *coordinate); +typedef bool (*IsForeignScanParallelSafe_function) (PlannerInfo *root, + RelOptInfo *rel, + RangeTblEntry *rte); + /* * FdwRoutine is the struct returned by a foreign-data wrapper's handler * function. It provides pointers to the callback functions needed by the @@ -188,6 +192,7 @@ typedef struct FdwRoutine ImportForeignSchema_function ImportForeignSchema; /* Support functions for parallelism under Gather node */ + IsForeignScanParallelSafe_function IsForeignScanParallelSafe; EstimateDSMForeignScan_function EstimateDSMForeignScan; InitializeDSMForeignScan_function InitializeDSMForeignScan; InitializeWorkerForeignScan_function InitializeWorkerForeignScan; |