1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>60.2. Creating Custom Scan Plans</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="custom-scan-path.html" title="60.1. Creating Custom Scan Paths" /><link rel="next" href="custom-scan-execution.html" title="60.3. Executing Custom Scans" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">60.2. Creating Custom Scan Plans</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="custom-scan-path.html" title="60.1. Creating Custom Scan Paths">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="custom-scan.html" title="Chapter 60. Writing a Custom Scan Provider">Up</a></td><th width="60%" align="center">Chapter 60. Writing a Custom Scan Provider</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="custom-scan-execution.html" title="60.3. Executing Custom Scans">Next</a></td></tr></table><hr /></div><div class="sect1" id="CUSTOM-SCAN-PLAN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">60.2. Creating Custom Scan Plans <a href="#CUSTOM-SCAN-PLAN" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="custom-scan-plan.html#CUSTOM-SCAN-PLAN-CALLBACKS">60.2.1. Custom Scan Plan Callbacks</a></span></dt></dl></div><p>
3 A custom scan is represented in a finished plan tree using the following
5 </p><pre class="programlisting">
6 typedef struct CustomScan
13 List *custom_scan_tlist;
14 Bitmapset *custom_relids;
15 const CustomScanMethods *methods;
19 <code class="structfield">scan</code> must be initialized as for any other scan, including
20 estimated costs, target lists, qualifications, and so on.
21 <code class="structfield">flags</code> is a bit mask with the same meaning as in
22 <code class="structname">CustomPath</code>.
23 <code class="structfield">custom_plans</code> can be used to store child
24 <code class="structname">Plan</code> nodes.
25 <code class="structfield">custom_exprs</code> should be used to
26 store expression trees that will need to be fixed up by
27 <code class="filename">setrefs.c</code> and <code class="filename">subselect.c</code>, while
28 <code class="structfield">custom_private</code> should be used to store other private data
29 that is only used by the custom scan provider itself.
30 <code class="structfield">custom_scan_tlist</code> can be NIL when scanning a base
31 relation, indicating that the custom scan returns scan tuples that match
32 the base relation's row type. Otherwise it is a target list describing
33 the actual scan tuples. <code class="structfield">custom_scan_tlist</code> must be
34 provided for joins, and could be provided for scans if the custom scan
35 provider can compute some non-Var expressions.
36 <code class="structfield">custom_relids</code> is set by the core code to the set of
37 relations (range table indexes) that this scan node handles; except when
38 this scan is replacing a join, it will have only one member.
39 <code class="structfield">methods</code> must point to a (usually statically allocated)
40 object implementing the required custom scan methods, which are further
43 When a <code class="structname">CustomScan</code> scans a single relation,
44 <code class="structfield">scan.scanrelid</code> must be the range table index of the table
45 to be scanned. When it replaces a join, <code class="structfield">scan.scanrelid</code>
48 Plan trees must be able to be duplicated using <code class="function">copyObject</code>,
49 so all the data stored within the <span class="quote">“<span class="quote">custom</span>”</span> fields must consist of
50 nodes that that function can handle. Furthermore, custom scan providers
51 cannot substitute a larger structure that embeds
52 a <code class="structname">CustomScan</code> for the structure itself, as would be possible
53 for a <code class="structname">CustomPath</code> or <code class="structname">CustomScanState</code>.
54 </p><div class="sect2" id="CUSTOM-SCAN-PLAN-CALLBACKS"><div class="titlepage"><div><div><h3 class="title">60.2.1. Custom Scan Plan Callbacks <a href="#CUSTOM-SCAN-PLAN-CALLBACKS" class="id_link">#</a></h3></div></div></div><p>
55 </p><pre class="programlisting">
56 Node *(*CreateCustomScanState) (CustomScan *cscan);
58 Allocate a <code class="structname">CustomScanState</code> for this
59 <code class="structname">CustomScan</code>. The actual allocation will often be larger than
60 required for an ordinary <code class="structname">CustomScanState</code>, because many
61 providers will wish to embed that as the first field of a larger structure.
62 The value returned must have the node tag and <code class="structfield">methods</code>
63 set appropriately, but other fields should be left as zeroes at this
64 stage; after <code class="function">ExecInitCustomScan</code> performs basic initialization,
65 the <code class="function">BeginCustomScan</code> callback will be invoked to give the
66 custom scan provider a chance to do whatever else is needed.
67 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="custom-scan-path.html" title="60.1. Creating Custom Scan Paths">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="custom-scan.html" title="Chapter 60. Writing a Custom Scan Provider">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="custom-scan-execution.html" title="60.3. Executing Custom Scans">Next</a></td></tr><tr><td width="40%" align="left" valign="top">60.1. Creating Custom Scan Paths </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 60.3. Executing Custom Scans</td></tr></table></div></body></html>