Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/fdwhandler.sgml`
ca1c19d79056f1e08301b215ec0da2799f7e327cd370cdcc0000000100000fa0
 by the
     last <command>ANALYZE</command>; it will be <literal>-1</literal> if
     no <command>ANALYZE</command> has been done on this foreign table.)
    </para>

    <para>
     See <xref linkend="fdw-planning"/> for additional information.
    </para>

    <para>
<programlisting>
void
GetForeignPaths(PlannerInfo *root,
                RelOptInfo *baserel,
                Oid foreigntableid);
</programlisting>

     Create possible access paths for a scan on a foreign table.
     This is called during query planning.
     The parameters are the same as for <function>GetForeignRelSize</function>,
     which has already been called.
    </para>

    <para>
     This function must generate at least one access path
     (<structname>ForeignPath</structname> node) for a scan on the foreign table and
     must call <function>add_path</function> to add each such path to
     <literal>baserel-&gt;pathlist</literal>.  It's recommended to use
     <function>create_foreignscan_path</function> to build the
     <structname>ForeignPath</structname> nodes.  The function can generate multiple
     access paths, e.g., a path which has valid <literal>pathkeys</literal> to
     represent a pre-sorted result.  Each access path must contain cost
     estimates, and can contain any FDW-private information that is needed to
     identify the specific scan method intended.
    </para>

    <para>
     See <xref linkend="fdw-planning"/> for additional information.
    </para>

    <para>
<programlisting>
ForeignScan *
GetForeignPlan(PlannerInfo *root,
               RelOptInfo *baserel,
               Oid foreigntableid,
               ForeignPath *best_path,
               List *tlist,
               List *scan_clauses,
               Plan *outer_plan);
</programlisting>

     Create a <structname>ForeignScan</structname> plan node from the selected foreign
     access path.  This is called at the end of query planning.
     The parameters are as for <function>GetForeignRelSize</function>, plus
     the selected <structname>ForeignPath</structname> (previously produced by
     <function>GetForeignPaths</function>, <function>GetForeignJoinPaths</function>,
     or <function>GetForeignUpperPaths</function>),
     the target list to be emitted by the plan node,
     the restriction clauses to be enforced by the plan node,
     and the outer subplan of the <structname>ForeignScan</structname>,
     which is used for rechecks performed by <function>RecheckForeignScan</function>.
     (If the path is for a join rather than a base
     relation, <literal>foreigntableid</literal> is <literal>InvalidOid</literal>.)
    </para>

    <para>
     This function must create and return a <structname>ForeignScan</structname> plan
     node; it's recommended to use <function>make_foreignscan</function> to build the
     <structname>ForeignScan</structname> node.
    </para>

    <para>
     See <xref linkend="fdw-planning"/> for additional information.
    </para>

    <para>
<programlisting>
void
BeginForeignScan(ForeignScanState *node,
                 int eflags);
</programlisting>

     Begin executing a foreign scan. This is called during executor startup.
     It should perform any initialization needed before the scan can start,
     but not start executing the actual scan (that should be done upon the
     first call to <function>IterateForeignScan</function>).
     The <structname>ForeignScanState</structname> node has already been created, but
     its <structfield>fdw_state</structfield> field is still NULL.  Information about
     the table to scan is accessible through the
     <structname>ForeignScanState</structname> node (in particular, from the underlying
     <structname>ForeignScan</structname> plan node, which contains any FDW-private
     information provided by <function>GetForeignPlan</function>).
     <literal>eflags</literal> contains flag bits describing the executor's
     operating mode for this plan node.
    </para>

    <para>
  

Title: FDW Routines for Scanning Foreign Tables: GetForeignPaths, GetForeignPlan, and BeginForeignScan
Summary
This section describes three more FDW routines for scanning foreign tables: `GetForeignPaths`, `GetForeignPlan`, and `BeginForeignScan`. `GetForeignPaths` creates access paths for scanning a foreign table during query planning. `GetForeignPlan` creates a ForeignScan plan node from the selected access path. `BeginForeignScan` initializes the foreign scan during executor startup. The functions are called during different phases of query processing, from planning to execution.