<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>.
</para>
<para>
If provided, the sample collection function must have the signature
<programlisting>
int
AcquireSampleRowsFunc(Relation relation,
int elevel,
HeapTuple *rows,
int targrows,
double *totalrows,
double *totaldeadrows);
</programlisting>
A random sample of up to <parameter>targrows</parameter> rows should be collected
from the table and stored into the caller-provided <parameter>rows</parameter>
array. The actual number of rows collected must be returned. In
addition, store estimates of the total numbers of live and dead rows in
the table into the output parameters <parameter>totalrows</parameter> and
<parameter>totaldeadrows</parameter>. (Set <parameter>totaldeadrows</parameter> to zero
if the FDW does not have any concept of dead rows.)
</para>
</sect2>
<sect2 id="fdw-callbacks-import">
<title>FDW Routines for <command>IMPORT FOREIGN SCHEMA</command></title>
<para>
<programlisting>
List *
ImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid);
</programlisting>
Obtain a list of foreign table creation commands. This function is
called when executing <xref linkend="sql-importforeignschema"/>, and is
passed the parse tree for that statement, as well as the OID of the
foreign server to use. It should return a list of C strings, each of
which must contain a <xref linkend="sql-createforeigntable"/> command.
These strings will be parsed and executed by the core server.
</para>
<para>
Within the <structname>ImportForeignSchemaStmt</structname> struct,
<structfield>remote_schema</structfield> is the name of the remote schema from
which tables are to be imported.
<structfield>list_type</structfield> identifies how to filter table names:
<literal>FDW_IMPORT_SCHEMA_ALL</literal> means that all tables in the remote
schema should be imported (in this case <structfield>table_list</structfield> is
empty), <literal>FDW_IMPORT_SCHEMA_LIMIT_TO</literal> means to include only
tables listed in <structfield>table_list</structfield>,
and <literal>FDW_IMPORT_SCHEMA_EXCEPT</literal> means to exclude the tables
listed in <structfield>table_list</structfield>.
<structfield>options</structfield> is a list of options used for the import process.
The meanings of the options are up to the FDW.
For example, an FDW could use an option to define whether the
<literal>NOT NULL</literal> attributes of columns should be imported.
These options need not have anything to do with those supported by the
FDW as database object options.
</para>
<para>
The FDW may ignore the <structfield>local_schema</structfield> field of
the <structname>ImportForeignSchemaStmt</structname>, because the core server
will automatically insert that name into the