Home Explore Blog CI



postgresql

20th chunk of `doc/src/sgml/fdwhandler.sgml`
f4d0ebb8a066cde398e977c0b988ad924ed947ce50af60050000000100000fa3
 foreign data wrapper may build the local path by itself or
     may choose not to create access paths for that join.)
    </para>
   </sect2>

   <sect2 id="fdw-callbacks-explain">
    <title>FDW Routines for <command>EXPLAIN</command></title>

    <para>
<programlisting>
void
ExplainForeignScan(ForeignScanState *node,
                   ExplainState *es);
</programlisting>

     Print additional <command>EXPLAIN</command> output for a foreign table scan.
     This function can call <function>ExplainPropertyText</function> and
     related functions to add fields to the <command>EXPLAIN</command> output.
     The flag fields in <literal>es</literal> can be used to determine what to
     print, and the state of the <structname>ForeignScanState</structname> node
     can be inspected to provide run-time statistics in the <command>EXPLAIN
     ANALYZE</command> case.
    </para>

    <para>
     If the <function>ExplainForeignScan</function> pointer is set to
     <literal>NULL</literal>, no additional information is printed during
     <command>EXPLAIN</command>.
    </para>

    <para>
<programlisting>
void
ExplainForeignModify(ModifyTableState *mtstate,
                     ResultRelInfo *rinfo,
                     List *fdw_private,
                     int subplan_index,
                     struct ExplainState *es);
</programlisting>

     Print additional <command>EXPLAIN</command> output for a foreign table update.
     This function can call <function>ExplainPropertyText</function> and
     related functions to add fields to the <command>EXPLAIN</command> output.
     The flag fields in <literal>es</literal> can be used to determine what to
     print, and the state of the <structname>ModifyTableState</structname> node
     can be inspected to provide run-time statistics in the <command>EXPLAIN
     ANALYZE</command> case.  The first four arguments are the same as for
     <function>BeginForeignModify</function>.
    </para>

    <para>
     If the <function>ExplainForeignModify</function> pointer is set to
     <literal>NULL</literal>, no additional information is printed during
     <command>EXPLAIN</command>.
    </para>

    <para>
<programlisting>
void
ExplainDirectModify(ForeignScanState *node,
                    ExplainState *es);
</programlisting>

     Print additional <command>EXPLAIN</command> output for a direct modification
     on the remote server.
     This function can call <function>ExplainPropertyText</function> and
     related functions to add fields to the <command>EXPLAIN</command> output.
     The flag fields in <literal>es</literal> can be used to determine what to
     print, and the state of the <structname>ForeignScanState</structname> node
     can be inspected to provide run-time statistics in the <command>EXPLAIN
     ANALYZE</command> case.
    </para>

    <para>
     If the <function>ExplainDirectModify</function> pointer is set to
     <literal>NULL</literal>, no additional information is printed during
     <command>EXPLAIN</command>.
    </para>

   </sect2>

   <sect2 id="fdw-callbacks-analyze">
    <title>FDW Routines for <command>ANALYZE</command></title>

    <para>
<programlisting>
bool
AnalyzeForeignTable(Relation relation,
                    AcquireSampleRowsFunc *func,
                    BlockNumber *totalpages);
</programlisting>

     This function is called when <xref linkend="sql-analyze"/> is executed on
     a foreign table.  If the FDW can collect statistics for this
     foreign table, it should return <literal>true</literal>, and provide a pointer
     to a function that will collect sample rows from the table in
     <parameter>func</parameter>, plus the estimated size of the table in pages in
     <parameter>totalpages</parameter>.  Otherwise, return <literal>false</literal>.
    </para>

    <para>
     If the FDW does not support collecting statistics for any tables, the
     <function>AnalyzeForeignTable</function> pointer can be set to <literal>NULL</literal>.

Title: FDW Routines for EXPLAIN and ANALYZE
Summary
This section describes FDW routines used for the EXPLAIN and ANALYZE commands. `ExplainForeignScan` adds custom output during EXPLAIN for foreign table scans. `ExplainForeignModify` provides additional EXPLAIN output for foreign table updates. `ExplainDirectModify` prints EXPLAIN output for direct modifications on the remote server. `AnalyzeForeignTable` enables the FDW to collect statistics for a foreign table during ANALYZE, providing a function to collect sample rows and estimating the table's size.