the
responsibility of the hook to minimize duplicated work.
</para>
<para>
Note also that the set of join clauses to apply to the join,
which is passed as <literal>extra->restrictlist</literal>, varies
depending on the combination of inner and outer relations. A
<structname>CustomPath</structname> path generated for the
<literal>joinrel</literal> must contain the set of join clauses it uses,
which will be used by the planner to convert the
<structname>CustomPath</structname> path into a plan, if it is selected
by the planner as the best path for the <literal>joinrel</literal>.
</para>
<sect2 id="custom-scan-path-callbacks">
<title>Custom Scan Path Callbacks</title>
<para>
<programlisting>
Plan *(*PlanCustomPath) (PlannerInfo *root,
RelOptInfo *rel,
CustomPath *best_path,
List *tlist,
List *clauses,
List *custom_plans);
</programlisting>
Convert a custom path to a finished plan. The return value will generally
be a <literal>CustomScan</literal> object, which the callback must allocate and
initialize. See <xref linkend="custom-scan-plan"/> for more details.
</para>
<para>
<programlisting>
List *(*ReparameterizeCustomPathByChild) (PlannerInfo *root,
List *custom_private,
RelOptInfo *child_rel);
</programlisting>
This callback is called while converting a path parameterized by the
top-most parent of the given child relation <literal>child_rel</literal>
to be parameterized by the child relation. The callback is used to
reparameterize any paths or translate any expression nodes saved in the
given <literal>custom_private</literal> member of a
<structname>CustomPath</structname>. The callback may use
<literal>reparameterize_path_by_child</literal>,
<literal>adjust_appendrel_attrs</literal> or
<literal>adjust_appendrel_attrs_multilevel</literal> as required.
</para>
</sect2>
</sect1>
<sect1 id="custom-scan-plan">
<title>Creating Custom Scan Plans</title>
<para>
A custom scan is represented in a finished plan tree using the following
structure:
<programlisting>
typedef struct CustomScan
{
Scan scan;
uint32 flags;
List *custom_plans;
List *custom_exprs;
List *custom_private;
List *custom_scan_tlist;
Bitmapset *custom_relids;
const CustomScanMethods *methods;
} CustomScan;
</programlisting>
</para>
<para>
<structfield>scan</structfield> must be initialized as for any other scan, including
estimated costs, target lists, qualifications, and so on.
<structfield>flags</structfield> is a bit mask with the same meaning as in
<structname>CustomPath</structname>.
<structfield>custom_plans</structfield> can be used to store child
<structname>Plan</structname> nodes.
<structfield>custom_exprs</structfield> should be used to
store expression trees that will need to be fixed up by
<filename>setrefs.c</filename> and <filename>subselect.c</filename>, while
<structfield>custom_private</structfield> should be used to store other private data
that is only used by the custom scan provider itself.
<structfield>custom_scan_tlist</structfield> can be NIL when scanning a base
relation, indicating that the custom scan returns scan tuples that match
the base relation's row type. Otherwise it is a target list describing
the actual scan tuples. <structfield>custom_scan_tlist</structfield> must be
provided for joins, and could be provided for scans if the custom scan
provider can compute some non-Var expressions.
<structfield>custom_relids</structfield> is set by the core code to the set of
relations (range table indexes) that this scan node handles; except when
this scan is replacing a join, it