Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > a8985c53237f42e0cfdfd17da0a53df3 > files > 258

postgresql9.4-docs-9.4.15-1.mga6.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Foreign Data Wrapper Callback Routines</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.4.15 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Writing A Foreign Data Wrapper"
HREF="fdwhandler.html"><LINK
REL="PREVIOUS"
TITLE="Foreign Data Wrapper Functions"
HREF="fdw-functions.html"><LINK
REL="NEXT"
TITLE="Foreign Data Wrapper Helper Functions"
HREF="fdw-helpers.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2017-11-10T00:43:05"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="4"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.4.15 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Foreign Data Wrapper Functions"
HREF="fdw-functions.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="fdwhandler.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 53. Writing A Foreign Data Wrapper</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Foreign Data Wrapper Helper Functions"
HREF="fdw-helpers.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="FDW-CALLBACKS"
>53.2. Foreign Data Wrapper Callback Routines</A
></H1
><P
>     The FDW handler function returns a palloc'd <TT
CLASS="STRUCTNAME"
>FdwRoutine</TT
>
     struct containing pointers to the callback functions described below.
     The scan-related functions are required, the rest are optional.
    </P
><P
>     The <TT
CLASS="STRUCTNAME"
>FdwRoutine</TT
> struct type is declared in
     <TT
CLASS="FILENAME"
>src/include/foreign/fdwapi.h</TT
>, which see for additional
     details.
    </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="FDW-CALLBACKS-SCAN"
>53.2.1. FDW Routines For Scanning Foreign Tables</A
></H2
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
GetForeignRelSize (PlannerInfo *root,
                   RelOptInfo *baserel,
                   Oid foreigntableid);</PRE
><P>

     Obtain relation size estimates for a foreign table.  This is called
     at the beginning of planning for a query that scans a foreign table.
     <TT
CLASS="LITERAL"
>root</TT
> is the planner's global information about the query;
     <TT
CLASS="LITERAL"
>baserel</TT
> is the planner's information about this table; and
     <TT
CLASS="LITERAL"
>foreigntableid</TT
> is the <TT
CLASS="STRUCTNAME"
>pg_class</TT
> OID of the
     foreign table.  (<TT
CLASS="LITERAL"
>foreigntableid</TT
> could be obtained from the
     planner data structures, but it's passed explicitly to save effort.)
    </P
><P
>     This function should update <TT
CLASS="LITERAL"
>baserel-&gt;rows</TT
> to be the
     expected number of rows returned by the table scan, after accounting for
     the filtering done by the restriction quals.  The initial value of
     <TT
CLASS="LITERAL"
>baserel-&gt;rows</TT
> is just a constant default estimate, which
     should be replaced if at all possible.  The function may also choose to
     update <TT
CLASS="LITERAL"
>baserel-&gt;width</TT
> if it can compute a better estimate
     of the average result row width.
    </P
><P
>     See <A
HREF="fdw-planning.html"
>Section 53.4</A
> for additional information.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
GetForeignPaths (PlannerInfo *root,
                 RelOptInfo *baserel,
                 Oid foreigntableid);</PRE
><P>

     Create possible access paths for a scan on a foreign table.
     This is called during query planning.
     The parameters are the same as for <CODE
CLASS="FUNCTION"
>GetForeignRelSize</CODE
>,
     which has already been called.
    </P
><P
>     This function must generate at least one access path
     (<TT
CLASS="STRUCTNAME"
>ForeignPath</TT
> node) for a scan on the foreign table and
     must call <CODE
CLASS="FUNCTION"
>add_path</CODE
> to add each such path to
     <TT
CLASS="LITERAL"
>baserel-&gt;pathlist</TT
>.  It's recommended to use
     <CODE
CLASS="FUNCTION"
>create_foreignscan_path</CODE
> to build the
     <TT
CLASS="STRUCTNAME"
>ForeignPath</TT
> nodes.  The function can generate multiple
     access paths, e.g., a path which has valid <TT
CLASS="LITERAL"
>pathkeys</TT
> 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.
    </P
><P
>     See <A
HREF="fdw-planning.html"
>Section 53.4</A
> for additional information.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>ForeignScan *
GetForeignPlan (PlannerInfo *root,
                RelOptInfo *baserel,
                Oid foreigntableid,
                ForeignPath *best_path,
                List *tlist,
                List *scan_clauses);</PRE
><P>

     Create a <TT
CLASS="STRUCTNAME"
>ForeignScan</TT
> plan node from the selected foreign
     access path.  This is called at the end of query planning.
     The parameters are as for <CODE
CLASS="FUNCTION"
>GetForeignRelSize</CODE
>, plus
     the selected <TT
CLASS="STRUCTNAME"
>ForeignPath</TT
> (previously produced by
     <CODE
CLASS="FUNCTION"
>GetForeignPaths</CODE
>), the target list to be emitted by the
     plan node, and the restriction clauses to be enforced by the plan node.
    </P
><P
>     This function must create and return a <TT
CLASS="STRUCTNAME"
>ForeignScan</TT
> plan
     node; it's recommended to use <CODE
CLASS="FUNCTION"
>make_foreignscan</CODE
> to build the
     <TT
CLASS="STRUCTNAME"
>ForeignScan</TT
> node.
    </P
><P
>     See <A
HREF="fdw-planning.html"
>Section 53.4</A
> for additional information.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
BeginForeignScan (ForeignScanState *node,
                  int eflags);</PRE
><P>

     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 <CODE
CLASS="FUNCTION"
>IterateForeignScan</CODE
>).
     The <TT
CLASS="STRUCTNAME"
>ForeignScanState</TT
> node has already been created, but
     its <TT
CLASS="STRUCTFIELD"
>fdw_state</TT
> field is still NULL.  Information about
     the table to scan is accessible through the
     <TT
CLASS="STRUCTNAME"
>ForeignScanState</TT
> node (in particular, from the underlying
     <TT
CLASS="STRUCTNAME"
>ForeignScan</TT
> plan node, which contains any FDW-private
     information provided by <CODE
CLASS="FUNCTION"
>GetForeignPlan</CODE
>).
     <TT
CLASS="LITERAL"
>eflags</TT
> contains flag bits describing the executor's
     operating mode for this plan node.
    </P
><P
>     Note that when <TT
CLASS="LITERAL"
>(eflags &amp; EXEC_FLAG_EXPLAIN_ONLY)</TT
> is
     true, this function should not perform any externally-visible actions;
     it should only do the minimum required to make the node state valid
     for <CODE
CLASS="FUNCTION"
>ExplainForeignScan</CODE
> and <CODE
CLASS="FUNCTION"
>EndForeignScan</CODE
>.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>TupleTableSlot *
IterateForeignScan (ForeignScanState *node);</PRE
><P>

     Fetch one row from the foreign source, returning it in a tuple table slot
     (the node's <TT
CLASS="STRUCTFIELD"
>ScanTupleSlot</TT
> should be used for this
     purpose).  Return NULL if no more rows are available.  The tuple table
     slot infrastructure allows either a physical or virtual tuple to be
     returned; in most cases the latter choice is preferable from a
     performance standpoint.  Note that this is called in a short-lived memory
     context that will be reset between invocations.  Create a memory context
     in <CODE
CLASS="FUNCTION"
>BeginForeignScan</CODE
> if you need longer-lived storage, or use
     the <TT
CLASS="STRUCTFIELD"
>es_query_cxt</TT
> of the node's <TT
CLASS="STRUCTNAME"
>EState</TT
>.
    </P
><P
>     The rows returned must match the column signature of the foreign table
     being scanned.  If you choose to optimize away fetching columns that
     are not needed, you should insert nulls in those column positions.
    </P
><P
>     Note that <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s executor doesn't care
     whether the rows returned violate any <TT
CLASS="LITERAL"
>NOT NULL</TT
>
     constraints that were defined on the foreign table columns &mdash; but
     the planner does care, and may optimize queries incorrectly if
     <TT
CLASS="LITERAL"
>NULL</TT
> values are present in a column declared not to contain
     them.  If a <TT
CLASS="LITERAL"
>NULL</TT
> value is encountered when the user has
     declared that none should be present, it may be appropriate to raise an
     error (just as you would need to do in the case of a data type mismatch).
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
ReScanForeignScan (ForeignScanState *node);</PRE
><P>

     Restart the scan from the beginning.  Note that any parameters the
     scan depends on may have changed value, so the new scan does not
     necessarily return exactly the same rows.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
EndForeignScan (ForeignScanState *node);</PRE
><P>

     End the scan and release resources.  It is normally not important
     to release palloc'd memory, but for example open files and connections
     to remote servers should be cleaned up.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="FDW-CALLBACKS-UPDATE"
>53.2.2. FDW Routines For Updating Foreign Tables</A
></H2
><P
>     If an FDW supports writable foreign tables, it should provide
     some or all of the following callback functions depending on
     the needs and capabilities of the FDW:
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
AddForeignUpdateTargets (Query *parsetree,
                         RangeTblEntry *target_rte,
                         Relation target_relation);</PRE
><P>

     <TT
CLASS="COMMAND"
>UPDATE</TT
> and <TT
CLASS="COMMAND"
>DELETE</TT
> operations are performed
     against rows previously fetched by the table-scanning functions.  The
     FDW may need extra information, such as a row ID or the values of
     primary-key columns, to ensure that it can identify the exact row to
     update or delete.  To support that, this function can add extra hidden,
     or <SPAN
CLASS="QUOTE"
>"junk"</SPAN
>, target columns to the list of columns that are to be
     retrieved from the foreign table during an <TT
CLASS="COMMAND"
>UPDATE</TT
> or
     <TT
CLASS="COMMAND"
>DELETE</TT
>.
    </P
><P
>     To do that, add <TT
CLASS="STRUCTNAME"
>TargetEntry</TT
> items to
     <TT
CLASS="LITERAL"
>parsetree-&gt;targetList</TT
>, containing expressions for the
     extra values to be fetched.  Each such entry must be marked
     <TT
CLASS="STRUCTFIELD"
>resjunk</TT
> = <TT
CLASS="LITERAL"
>true</TT
>, and must have a distinct
     <TT
CLASS="STRUCTFIELD"
>resname</TT
> that will identify it at execution time.
     Avoid using names matching <TT
CLASS="LITERAL"
>ctid<TT
CLASS="REPLACEABLE"
><I
>N</I
></TT
></TT
>,
     <TT
CLASS="LITERAL"
>wholerow</TT
>, or
     <TT
CLASS="LITERAL"
>wholerow<TT
CLASS="REPLACEABLE"
><I
>N</I
></TT
></TT
>, as the core system can
     generate junk columns of these names.
    </P
><P
>     This function is called in the rewriter, not the planner, so the
     information available is a bit different from that available to the
     planning routines.
     <TT
CLASS="LITERAL"
>parsetree</TT
> is the parse tree for the <TT
CLASS="COMMAND"
>UPDATE</TT
> or
     <TT
CLASS="COMMAND"
>DELETE</TT
> command, while <TT
CLASS="LITERAL"
>target_rte</TT
> and
     <TT
CLASS="LITERAL"
>target_relation</TT
> describe the target foreign table.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>AddForeignUpdateTargets</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, no extra target expressions are added.
     (This will make it impossible to implement <TT
CLASS="COMMAND"
>DELETE</TT
>
     operations, though <TT
CLASS="COMMAND"
>UPDATE</TT
> may still be feasible if the FDW
     relies on an unchanging primary key to identify rows.)
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>List *
PlanForeignModify (PlannerInfo *root,
                   ModifyTable *plan,
                   Index resultRelation,
                   int subplan_index);</PRE
><P>

     Perform any additional planning actions needed for an insert, update, or
     delete on a foreign table.  This function generates the FDW-private
     information that will be attached to the <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan
     node that performs the update action.  This private information must
     have the form of a <TT
CLASS="LITERAL"
>List</TT
>, and will be delivered to
     <CODE
CLASS="FUNCTION"
>BeginForeignModify</CODE
> during the execution stage.
    </P
><P
>     <TT
CLASS="LITERAL"
>root</TT
> is the planner's global information about the query.
     <TT
CLASS="LITERAL"
>plan</TT
> is the <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node, which is
     complete except for the <TT
CLASS="STRUCTFIELD"
>fdwPrivLists</TT
> field.
     <TT
CLASS="LITERAL"
>resultRelation</TT
> identifies the target foreign table by its
     range table index.  <TT
CLASS="LITERAL"
>subplan_index</TT
> identifies which target of
     the <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node this is, counting from zero;
     use this if you want to index into <TT
CLASS="LITERAL"
>plan-&gt;plans</TT
> or other
     substructure of the <TT
CLASS="LITERAL"
>plan</TT
> node.
    </P
><P
>     See <A
HREF="fdw-planning.html"
>Section 53.4</A
> for additional information.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>PlanForeignModify</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, no additional plan-time actions are taken, and the
     <TT
CLASS="LITERAL"
>fdw_private</TT
> list delivered to
     <CODE
CLASS="FUNCTION"
>BeginForeignModify</CODE
> will be NIL.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
BeginForeignModify (ModifyTableState *mtstate,
                    ResultRelInfo *rinfo,
                    List *fdw_private,
                    int subplan_index,
                    int eflags);</PRE
><P>

     Begin executing a foreign table modification operation.  This routine is
     called during executor startup.  It should perform any initialization
     needed prior to the actual table modifications.  Subsequently,
     <CODE
CLASS="FUNCTION"
>ExecForeignInsert</CODE
>, <CODE
CLASS="FUNCTION"
>ExecForeignUpdate</CODE
> or
     <CODE
CLASS="FUNCTION"
>ExecForeignDelete</CODE
> will be called for each tuple to be
     inserted, updated, or deleted.
    </P
><P
>     <TT
CLASS="LITERAL"
>mtstate</TT
> is the overall state of the
     <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node being executed; global data about
     the plan and execution state is available via this structure.
     <TT
CLASS="LITERAL"
>rinfo</TT
> is the <TT
CLASS="STRUCTNAME"
>ResultRelInfo</TT
> struct describing
     the target foreign table.  (The <TT
CLASS="STRUCTFIELD"
>ri_FdwState</TT
> field of
     <TT
CLASS="STRUCTNAME"
>ResultRelInfo</TT
> is available for the FDW to store any
     private state it needs for this operation.)
     <TT
CLASS="LITERAL"
>fdw_private</TT
> contains the private data generated by
     <CODE
CLASS="FUNCTION"
>PlanForeignModify</CODE
>, if any.
     <TT
CLASS="LITERAL"
>subplan_index</TT
> identifies which target of
     the <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node this is.
     <TT
CLASS="LITERAL"
>eflags</TT
> contains flag bits describing the executor's
     operating mode for this plan node.
    </P
><P
>     Note that when <TT
CLASS="LITERAL"
>(eflags &amp; EXEC_FLAG_EXPLAIN_ONLY)</TT
> is
     true, this function should not perform any externally-visible actions;
     it should only do the minimum required to make the node state valid
     for <CODE
CLASS="FUNCTION"
>ExplainForeignModify</CODE
> and <CODE
CLASS="FUNCTION"
>EndForeignModify</CODE
>.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>BeginForeignModify</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, no action is taken during executor startup.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>TupleTableSlot *
ExecForeignInsert (EState *estate,
                   ResultRelInfo *rinfo,
                   TupleTableSlot *slot,
                   TupleTableSlot *planSlot);</PRE
><P>

     Insert one tuple into the foreign table.
     <TT
CLASS="LITERAL"
>estate</TT
> is global execution state for the query.
     <TT
CLASS="LITERAL"
>rinfo</TT
> is the <TT
CLASS="STRUCTNAME"
>ResultRelInfo</TT
> struct describing
     the target foreign table.
     <TT
CLASS="LITERAL"
>slot</TT
> contains the tuple to be inserted; it will match the
     row-type definition of the foreign table.
     <TT
CLASS="LITERAL"
>planSlot</TT
> contains the tuple that was generated by the
     <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node's subplan; it differs from
     <TT
CLASS="LITERAL"
>slot</TT
> in possibly containing additional <SPAN
CLASS="QUOTE"
>"junk"</SPAN
>
     columns.  (The <TT
CLASS="LITERAL"
>planSlot</TT
> is typically of little interest
     for <TT
CLASS="COMMAND"
>INSERT</TT
> cases, but is provided for completeness.)
    </P
><P
>     The return value is either a slot containing the data that was actually
     inserted (this might differ from the data supplied, for example as a
     result of trigger actions), or NULL if no row was actually inserted
     (again, typically as a result of triggers).  The passed-in
     <TT
CLASS="LITERAL"
>slot</TT
> can be re-used for this purpose.
    </P
><P
>     The data in the returned slot is used only if the <TT
CLASS="COMMAND"
>INSERT</TT
>
     query has a <TT
CLASS="LITERAL"
>RETURNING</TT
> clause or the foreign table has
     an <TT
CLASS="LITERAL"
>AFTER ROW</TT
> trigger.  Triggers require all columns, but the
     FDW could choose to optimize away returning some or all columns depending
     on the contents of the <TT
CLASS="LITERAL"
>RETURNING</TT
> clause.  Regardless, some
     slot must be returned to indicate success, or the query's reported row
     count will be wrong.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>ExecForeignInsert</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, attempts to insert into the foreign table will fail
     with an error message.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>TupleTableSlot *
ExecForeignUpdate (EState *estate,
                   ResultRelInfo *rinfo,
                   TupleTableSlot *slot,
                   TupleTableSlot *planSlot);</PRE
><P>

     Update one tuple in the foreign table.
     <TT
CLASS="LITERAL"
>estate</TT
> is global execution state for the query.
     <TT
CLASS="LITERAL"
>rinfo</TT
> is the <TT
CLASS="STRUCTNAME"
>ResultRelInfo</TT
> struct describing
     the target foreign table.
     <TT
CLASS="LITERAL"
>slot</TT
> contains the new data for the tuple; it will match the
     row-type definition of the foreign table.
     <TT
CLASS="LITERAL"
>planSlot</TT
> contains the tuple that was generated by the
     <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node's subplan; it differs from
     <TT
CLASS="LITERAL"
>slot</TT
> in possibly containing additional <SPAN
CLASS="QUOTE"
>"junk"</SPAN
>
     columns.  In particular, any junk columns that were requested by
     <CODE
CLASS="FUNCTION"
>AddForeignUpdateTargets</CODE
> will be available from this slot.
    </P
><P
>     The return value is either a slot containing the row as it was actually
     updated (this might differ from the data supplied, for example as a
     result of trigger actions), or NULL if no row was actually updated
     (again, typically as a result of triggers).  The passed-in
     <TT
CLASS="LITERAL"
>slot</TT
> can be re-used for this purpose.
    </P
><P
>     The data in the returned slot is used only if the <TT
CLASS="COMMAND"
>UPDATE</TT
>
     query has a <TT
CLASS="LITERAL"
>RETURNING</TT
> clause or the foreign table has
     an <TT
CLASS="LITERAL"
>AFTER ROW</TT
> trigger.  Triggers require all columns, but the
     FDW could choose to optimize away returning some or all columns depending
     on the contents of the <TT
CLASS="LITERAL"
>RETURNING</TT
> clause.  Regardless, some
     slot must be returned to indicate success, or the query's reported row
     count will be wrong.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>ExecForeignUpdate</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, attempts to update the foreign table will fail
     with an error message.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>TupleTableSlot *
ExecForeignDelete (EState *estate,
                   ResultRelInfo *rinfo,
                   TupleTableSlot *slot,
                   TupleTableSlot *planSlot);</PRE
><P>

     Delete one tuple from the foreign table.
     <TT
CLASS="LITERAL"
>estate</TT
> is global execution state for the query.
     <TT
CLASS="LITERAL"
>rinfo</TT
> is the <TT
CLASS="STRUCTNAME"
>ResultRelInfo</TT
> struct describing
     the target foreign table.
     <TT
CLASS="LITERAL"
>slot</TT
> contains nothing useful upon call, but can be used to
     hold the returned tuple.
     <TT
CLASS="LITERAL"
>planSlot</TT
> contains the tuple that was generated by the
     <TT
CLASS="STRUCTNAME"
>ModifyTable</TT
> plan node's subplan; in particular, it will
     carry any junk columns that were requested by
     <CODE
CLASS="FUNCTION"
>AddForeignUpdateTargets</CODE
>.  The junk column(s) must be used
     to identify the tuple to be deleted.
    </P
><P
>     The return value is either a slot containing the row that was deleted,
     or NULL if no row was deleted (typically as a result of triggers).  The
     passed-in <TT
CLASS="LITERAL"
>slot</TT
> can be used to hold the tuple to be returned.
    </P
><P
>     The data in the returned slot is used only if the <TT
CLASS="COMMAND"
>DELETE</TT
>
     query has a <TT
CLASS="LITERAL"
>RETURNING</TT
> clause or the foreign table has
     an <TT
CLASS="LITERAL"
>AFTER ROW</TT
> trigger.  Triggers require all columns, but the
     FDW could choose to optimize away returning some or all columns depending
     on the contents of the <TT
CLASS="LITERAL"
>RETURNING</TT
> clause.  Regardless, some
     slot must be returned to indicate success, or the query's reported row
     count will be wrong.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>ExecForeignDelete</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, attempts to delete from the foreign table will fail
     with an error message.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
EndForeignModify (EState *estate,
                  ResultRelInfo *rinfo);</PRE
><P>

     End the table update and release resources.  It is normally not important
     to release palloc'd memory, but for example open files and connections
     to remote servers should be cleaned up.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>EndForeignModify</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, no action is taken during executor shutdown.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>int
IsForeignRelUpdatable (Relation rel);</PRE
><P>

     Report which update operations the specified foreign table supports.
     The return value should be a bit mask of rule event numbers indicating
     which operations are supported by the foreign table, using the
     <TT
CLASS="LITERAL"
>CmdType</TT
> enumeration; that is,
     <TT
CLASS="LITERAL"
>(1 &#60;&#60; CMD_UPDATE) = 4</TT
> for <TT
CLASS="COMMAND"
>UPDATE</TT
>,
     <TT
CLASS="LITERAL"
>(1 &#60;&#60; CMD_INSERT) = 8</TT
> for <TT
CLASS="COMMAND"
>INSERT</TT
>, and
     <TT
CLASS="LITERAL"
>(1 &#60;&#60; CMD_DELETE) = 16</TT
> for <TT
CLASS="COMMAND"
>DELETE</TT
>.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>IsForeignRelUpdatable</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, foreign tables are assumed to be insertable, updatable,
     or deletable if the FDW provides <CODE
CLASS="FUNCTION"
>ExecForeignInsert</CODE
>,
     <CODE
CLASS="FUNCTION"
>ExecForeignUpdate</CODE
>, or <CODE
CLASS="FUNCTION"
>ExecForeignDelete</CODE
>
     respectively.  This function is only needed if the FDW supports some
     tables that are updatable and some that are not.  (Even then, it's
     permissible to throw an error in the execution routine instead of
     checking in this function.  However, this function is used to determine
     updatability for display in the <TT
CLASS="LITERAL"
>information_schema</TT
> views.)
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="FDW-CALLBACKS-EXPLAIN"
>53.2.3. FDW Routines for <TT
CLASS="COMMAND"
>EXPLAIN</TT
></A
></H2
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
ExplainForeignScan (ForeignScanState *node,
                    ExplainState *es);</PRE
><P>

     Print additional <TT
CLASS="COMMAND"
>EXPLAIN</TT
> output for a foreign table scan.
     This function can call <CODE
CLASS="FUNCTION"
>ExplainPropertyText</CODE
> and
     related functions to add fields to the <TT
CLASS="COMMAND"
>EXPLAIN</TT
> output.
     The flag fields in <TT
CLASS="LITERAL"
>es</TT
> can be used to determine what to
     print, and the state of the <TT
CLASS="STRUCTNAME"
>ForeignScanState</TT
> node
     can be inspected to provide run-time statistics in the <TT
CLASS="COMMAND"
>EXPLAIN
     ANALYZE</TT
> case.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>ExplainForeignScan</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, no additional information is printed during
     <TT
CLASS="COMMAND"
>EXPLAIN</TT
>.
    </P
><P
></P><PRE
CLASS="PROGRAMLISTING"
>void
ExplainForeignModify (ModifyTableState *mtstate,
                      ResultRelInfo *rinfo,
                      List *fdw_private,
                      int subplan_index,
                      struct ExplainState *es);</PRE
><P>

     Print additional <TT
CLASS="COMMAND"
>EXPLAIN</TT
> output for a foreign table update.
     This function can call <CODE
CLASS="FUNCTION"
>ExplainPropertyText</CODE
> and
     related functions to add fields to the <TT
CLASS="COMMAND"
>EXPLAIN</TT
> output.
     The flag fields in <TT
CLASS="LITERAL"
>es</TT
> can be used to determine what to
     print, and the state of the <TT
CLASS="STRUCTNAME"
>ModifyTableState</TT
> node
     can be inspected to provide run-time statistics in the <TT
CLASS="COMMAND"
>EXPLAIN
     ANALYZE</TT
> case.  The first four arguments are the same as for
     <CODE
CLASS="FUNCTION"
>BeginForeignModify</CODE
>.
    </P
><P
>     If the <CODE
CLASS="FUNCTION"
>ExplainForeignModify</CODE
> pointer is set to
     <TT
CLASS="LITERAL"
>NULL</TT
>, no additional information is printed during
     <TT
CLASS="COMMAND"
>EXPLAIN</TT
>.
    </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="FDW-CALLBACKS-ANALYZE"
>53.2.4. FDW Routines for <TT
CLASS="COMMAND"
>ANALYZE</TT
></A
></H2
><P
></P><PRE
CLASS="PROGRAMLISTING"
>bool
AnalyzeForeignTable (Relation relation,
                     AcquireSampleRowsFunc *func,
                     BlockNumber *totalpages);</PRE
><P>

     This function is called when <A
HREF="sql-analyze.html"
>ANALYZE</A
> is executed on
     a foreign table.  If the FDW can collect statistics for this
     foreign table, it should return <TT
CLASS="LITERAL"
>true</TT
>, and provide a pointer
     to a function that will collect sample rows from the table in
     <TT
CLASS="PARAMETER"
>func</TT
>, plus the estimated size of the table in pages in
     <TT
CLASS="PARAMETER"
>totalpages</TT
>.  Otherwise, return <TT
CLASS="LITERAL"
>false</TT
>.
    </P
><P
>     If the FDW does not support collecting statistics for any tables, the
     <CODE
CLASS="FUNCTION"
>AnalyzeForeignTable</CODE
> pointer can be set to <TT
CLASS="LITERAL"
>NULL</TT
>.
    </P
><P
>     If provided, the sample collection function must have the signature
</P><PRE
CLASS="PROGRAMLISTING"
>int
AcquireSampleRowsFunc (Relation relation, int elevel,
                       HeapTuple *rows, int targrows,
                       double *totalrows,
                       double *totaldeadrows);</PRE
><P>

     A random sample of up to <TT
CLASS="PARAMETER"
>targrows</TT
> rows should be collected
     from the table and stored into the caller-provided <TT
CLASS="PARAMETER"
>rows</TT
>
     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 <TT
CLASS="PARAMETER"
>totalrows</TT
> and
     <TT
CLASS="PARAMETER"
>totaldeadrows</TT
>.  (Set <TT
CLASS="PARAMETER"
>totaldeadrows</TT
> to zero
     if the FDW does not have any concept of dead rows.)
    </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="fdw-functions.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="fdw-helpers.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Foreign Data Wrapper Functions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="fdwhandler.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Foreign Data Wrapper Helper Functions</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>