Home Explore Blog CI



postgresql

23th chunk of `doc/src/sgml/fdwhandler.sgml`
2cd81a85002db2c490241907446912d17f765e4727ce34c40000000100000fa0
 parallel worker.  This will generally not be the case if
    the remote data source has transaction semantics, unless the worker's
    connection to the data can somehow be made to share the same transaction
    context as the leader.
    </para>

    <para>
    If this function is not defined, it is assumed that the scan must take
    place within the parallel leader.  Note that returning true does not mean
    that the scan itself can be done in parallel, only that the scan can be
    performed within a parallel worker.  Therefore, it can be useful to define
    this method even when parallel execution is not 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.
    This function is optional, and can be omitted if not needed; but if it
    is omitted, the next three functions must be omitted as well, because
    no shared memory will be allocated for the FDW's use.
    </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</literal> points to a shared memory area of
    size equal to the return value of <function>EstimateDSMForeignScan</function>.
    This function is optional, and can be omitted if not needed.
   </para>

    <para>
<programlisting>
void
ReInitializeDSMForeignScan(ForeignScanState *node, ParallelContext *pcxt,
                           void *coordinate);
</programlisting>
    Re-initialize the dynamic shared memory required for parallel operation
    when the foreign-scan plan node is about to be re-scanned.
    This function is optional, and can be omitted if not needed.
    Recommended practice is that this function reset only shared state,
    while the <function>ReScanForeignScan</function> function resets only local
    state.  Currently, this function will be called
    before <function>ReScanForeignScan</function>, but it's best not to rely on
    that ordering.
   </para>

   <para>
<programlisting>
void
InitializeWorkerForeignScan(ForeignScanState *node, shm_toc *toc,
                            void *coordinate);
</programlisting>
    Initialize a parallel worker's local state based on the shared state
    set up by the leader during <function>InitializeDSMForeignScan</function>.
    This function is optional, and can be omitted if not needed.
   </para>

   <para>
<programlisting>
void
ShutdownForeignScan(ForeignScanState *node);
</programlisting>
    Release resources when it is anticipated the node will not be executed
    to completion.  This is not called in all cases; sometimes,
    <literal>EndForeignScan</literal> may be called without this function having
    been called first.  Since the DSM segment used by parallel query is
    destroyed just after this callback is invoked, foreign data wrappers that
    wish to take some action before the DSM segment goes away should implement
    this method.
   </para>
   </sect2>

   <sect2 id="fdw-callbacks-async">
    <title>FDW Routines for Asynchronous Execution</title>
    <para>
     A <structname>ForeignScan</structname> node can, optionally, support
     asynchronous execution as described in
     <filename>src/backend/executor/README</filename>.  The following
     functions are all optional, but are all required if asynchronous
     execution is to be supported.
    </para>

    <para>
<programlisting>
bool
IsForeignPathAsyncCapable(ForeignPath *path);
</programlisting>
     Test whether a given <structname>ForeignPath</structname> path can scan
     the underlying foreign relation asynchronously.
 

Title: FDW Routines for Parallel and Asynchronous Execution (Continued)
Summary
`EstimateDSMForeignScan` estimates the shared memory needed for parallel operation. `InitializeDSMForeignScan` initializes the shared memory, with `coordinate` pointing to the allocated memory. `ReInitializeDSMForeignScan` re-initializes the shared memory when the foreign-scan plan node is re-scanned, resetting shared state. `InitializeWorkerForeignScan` initializes a parallel worker's local state based on the leader's shared state. `ShutdownForeignScan` releases resources when the node won't complete, acting before the DSM segment is destroyed. A `ForeignScan` node can support asynchronous execution. The following functions are required to support it. `IsForeignPathAsyncCapable` tests if a given `ForeignPath` can scan the foreign relation asynchronously.