Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
custom-scan-plan.html67 linesDownload Raw Back to html
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>61.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="61.1. Creating Custom Scan Paths" /><link rel="next" href="custom-scan-execution.html" title="61.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">61.2. Creating Custom Scan Plans</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="custom-scan-path.html" title="61.1. Creating Custom Scan Paths">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="custom-scan.html" title="Chapter 61. Writing a Custom Scan Provider">Up</a></td><th width="60%" align="center">Chapter 61. Writing a Custom Scan Provider</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="custom-scan-execution.html" title="61.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">61.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">61.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 following4    structure:5</p><pre class="programlisting">6typedef struct CustomScan7{8    Scan      scan;9    uint32    flags;10    List     *custom_plans;11    List     *custom_exprs;12    List     *custom_private;13    List     *custom_scan_tlist;14    Bitmapset *custom_relids;15    const CustomScanMethods *methods;16} CustomScan;17</pre><p>18  </p><p>19    <code class="structfield">scan</code> must be initialized as for any other scan, including20    estimated costs, target lists, qualifications, and so on.21    <code class="structfield">flags</code> is a bit mask with the same meaning as in22    <code class="structname">CustomPath</code>.23    <code class="structfield">custom_plans</code> can be used to store child24    <code class="structname">Plan</code> nodes.25    <code class="structfield">custom_exprs</code> should be used to26    store expression trees that will need to be fixed up by27    <code class="filename">setrefs.c</code> and <code class="filename">subselect.c</code>, while28    <code class="structfield">custom_private</code> should be used to store other private data29    that is only used by the custom scan provider itself.30    <code class="structfield">custom_scan_tlist</code> can be NIL when scanning a base31    relation, indicating that the custom scan returns scan tuples that match32    the base relation's row type.  Otherwise it is a target list describing33    the actual scan tuples.  <code class="structfield">custom_scan_tlist</code> must be34    provided for joins, and could be provided for scans if the custom scan35    provider can compute some non-Var expressions.36    <code class="structfield">custom_relids</code> is set by the core code to the set of37    relations (range table indexes) that this scan node handles; except when38    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 further41    detailed below.42  </p><p>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 table45   to be scanned.  When it replaces a join, <code class="structfield">scan.scanrelid</code>46   should be zero.47  </p><p>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 of50   nodes that that function can handle.  Furthermore, custom scan providers51   cannot substitute a larger structure that embeds52   a <code class="structname">CustomScan</code> for the structure itself, as would be possible53   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">61.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">56Node *(*CreateCustomScanState) (CustomScan *cscan);57</pre><p>58    Allocate a <code class="structname">CustomScanState</code> for this59    <code class="structname">CustomScan</code>.  The actual allocation will often be larger than60    required for an ordinary <code class="structname">CustomScanState</code>, because many61    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 this64    stage; after <code class="function">ExecInitCustomScan</code> performs basic initialization,65    the <code class="function">BeginCustomScan</code> callback will be invoked to give the66    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="61.1. Creating Custom Scan Paths">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="custom-scan.html" title="Chapter 61. Writing a Custom Scan Provider">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="custom-scan-execution.html" title="61.3. Executing Custom Scans">Next</a></td></tr><tr><td width="40%" align="left" valign="top">61.1. Creating Custom Scan Paths </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 61.3. Executing Custom Scans</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai