1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Allow parallel custom and foreign scans.

This patch doesn't put the new infrastructure to use anywhere, and
indeed it's not clear how it could ever be used for something like
postgres_fdw which has to send an SQL query and wait for a reply,
but there might be FDWs or custom scan providers that are CPU-bound,
so let's give them a way to join club parallel.

KaiGai Kohei, reviewed by me.
This commit is contained in:
Robert Haas
2016-02-03 12:46:18 -05:00
parent 25e44518c1
commit 69d34408e5
9 changed files with 263 additions and 1 deletions

View File

@ -303,6 +303,43 @@ void (*RestrPosCustomScan) (CustomScanState *node);
<para>
<programlisting>
Size (*EstimateDSMCustomScan) (CustomScanState *node,
ParallelContext *pcxt);
</programlisting>
Estimate the amount of dynamic shared memory that will be required
for parallel operation. This may be higher than the amount that will
actually be used, but it must not be lower. The return value is in bytes.
This callback is optional, and need only be supplied if this custom
scan provider supports parallel execution.
</para>
<para>
<programlisting>
void (*InitializeDSMCustomScan) (CustomScanState *node,
ParallelContext *pcxt,
void *coordinate);
</programlisting>
Initialize the dynamic shared memory that will be required for parallel
operation; <literal>coordinate</> points to an amount of allocated space
equal to the return value of <function>EstimateDSMCustomScan</>.
This callback is optional, and need only be supplied if this custom
scan provider supports parallel execution.
</para>
<para>
<programlisting>
void (*InitializeWorkerCustomScan) (CustomScanState *node,
shm_toc *toc,
void *coordinate);
</programlisting>
Initialize a parallel worker's custom state based on the shared state
set up in the leader by <literal>InitializeDSMCustomScan</>.
This callback is optional, and needs only be supplied if this
custom path supports parallel execution.
</para>
<para>
<programlisting>
void (*ExplainCustomScan) (CustomScanState *node,
List *ancestors,
ExplainState *es);

View File

@ -955,6 +955,53 @@ ImportForeignSchema (ImportForeignSchemaStmt *stmt, Oid serverOid);
</sect2>
<sect2 id="fdw-callbacks-parallel">
<title>FDW Routines for Parallel Execution</title>
<para>
A <structname>ForeignScan</> node can, optionally, support parallel
execution. A parallel <structname>ForeignScan</> will be executed
in multiple processes and should return each row only once across
all cooperating processes. To do this, processes can coordinate through
fixed size chunks of dynamic shared memory. This shared memory is not
guaranteed to be mapped at the same address in every process, so pointers
may not be used. The following callbacks are all optional in general,
but required if parallel execution is to be supported.
</para>
<para>
<programlisting>
Size
EstimateDSMForeignScan(ForeignScanState *node, ParallelContext *pcxt);
</programlisting>
Estimate the amount of dynamic shared memory that will be required
for parallel operation. This may be higher than the amount that will
actually be used, but it must not be lower. The return value is in bytes.
</para>
<para>
<programlisting>
void
InitializeDSMForeignScan(ForeignScanState *node, ParallelContext *pcxt,
void *coordinate);
</programlisting>
Initialize the dynamic shared memory that will be required for parallel
operation; <literal>coordinate</> points to an amount of allocated space
equal to the return value of <function>EstimateDSMForeignScan</>.
</para>
<para>
<programlisting>
void
InitializeWorkerForeignScan(ForeignScanState *node, shm_toc *toc,
void *coordinate);
</programlisting>
Initialize a parallel worker's custom state based on the shared state
set up in the leader by <literal>InitializeDSMForeignScan</>.
This callback is optional, and needs only be supplied if this
custom path supports parallel execution.
</para>
</sect2>
</sect1>
<sect1 id="fdw-helpers">