Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
custom-scan-execution.html139 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.3. Executing Custom Scans</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-plan.html" title="61.2. Creating Custom Scan Plans" /><link rel="next" href="geqo.html" title="Chapter 62. Genetic Query Optimizer" /></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.3. Executing Custom Scans</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="custom-scan-plan.html" title="61.2. Creating Custom Scan Plans">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="geqo.html" title="Chapter 62. Genetic Query Optimizer">Next</a></td></tr></table><hr /></div><div class="sect1" id="CUSTOM-SCAN-EXECUTION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">61.3. Executing Custom Scans <a href="#CUSTOM-SCAN-EXECUTION" class="id_link">#</a></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="custom-scan-execution.html#CUSTOM-SCAN-EXECUTION-CALLBACKS">61.3.1. Custom Scan Execution Callbacks</a></span></dt></dl></div><p>3   When a <code class="structfield">CustomScan</code> is executed, its execution state is4   represented by a <code class="structfield">CustomScanState</code>, which is declared as5   follows:6</p><pre class="programlisting">7typedef struct CustomScanState8{9    ScanState ss;10    uint32    flags;11    const CustomExecMethods *methods;12} CustomScanState;13</pre><p>14  </p><p>15   <code class="structfield">ss</code> is initialized as for any other scan state,16   except that if the scan is for a join rather than a base relation,17   <code class="literal">ss.ss_currentRelation</code> is left NULL.18   <code class="structfield">flags</code> is a bit mask with the same meaning as in19   <code class="structname">CustomPath</code> and <code class="structname">CustomScan</code>.20   <code class="structfield">methods</code> must point to a (usually statically allocated)21   object implementing the required custom scan state methods, which are22   further detailed below.  Typically, a <code class="structname">CustomScanState</code>, which23   need not support <code class="function">copyObject</code>, will actually be a larger24   structure embedding the above as its first member.25  </p><div class="sect2" id="CUSTOM-SCAN-EXECUTION-CALLBACKS"><div class="titlepage"><div><div><h3 class="title">61.3.1. Custom Scan Execution Callbacks <a href="#CUSTOM-SCAN-EXECUTION-CALLBACKS" class="id_link">#</a></h3></div></div></div><p>26</p><pre class="programlisting">27void (*BeginCustomScan) (CustomScanState *node,28                         EState *estate,29                         int eflags);30</pre><p>31    Complete initialization of the supplied <code class="structname">CustomScanState</code>.32    Standard fields have been initialized by <code class="function">ExecInitCustomScan</code>,33    but any private fields should be initialized here.34   </p><p>35</p><pre class="programlisting">36TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);37</pre><p>38    Fetch the next scan tuple.  If any tuples remain, it should fill39    <code class="literal">ps_ResultTupleSlot</code> with the next tuple in the current scan40    direction, and then return the tuple slot.  If not,41    <code class="literal">NULL</code> or an empty slot should be returned.42   </p><p>43</p><pre class="programlisting">44void (*EndCustomScan) (CustomScanState *node);45</pre><p>46    Clean up any private data associated with the <code class="literal">CustomScanState</code>.47    This method is required, but it does not need to do anything if there is48    no associated data or it will be cleaned up automatically.49   </p><p>50</p><pre class="programlisting">51void (*ReScanCustomScan) (CustomScanState *node);52</pre><p>53    Rewind the current scan to the beginning and prepare to rescan the54    relation.55   </p><p>56</p><pre class="programlisting">57void (*MarkPosCustomScan) (CustomScanState *node);58</pre><p>59    Save the current scan position so that it can subsequently be restored60    by the <code class="function">RestrPosCustomScan</code> callback.  This callback is61    optional, and need only be supplied if the62    <code class="literal">CUSTOMPATH_SUPPORT_MARK_RESTORE</code> flag is set.63   </p><p>64</p><pre class="programlisting">65void (*RestrPosCustomScan) (CustomScanState *node);66</pre><p>67    Restore the previous scan position as saved by the68    <code class="function">MarkPosCustomScan</code> callback.  This callback is optional,69    and need only be supplied if the70    <code class="literal">CUSTOMPATH_SUPPORT_MARK_RESTORE</code> flag is set.71   </p><p>72</p><pre class="programlisting">73Size (*EstimateDSMCustomScan) (CustomScanState *node,74                               ParallelContext *pcxt);75</pre><p>76    Estimate the amount of dynamic shared memory that will be required77    for parallel operation.  This may be higher than the amount that will78    actually be used, but it must not be lower.  The return value is in bytes.79    This callback is optional, and need only be supplied if this custom80    scan provider supports parallel execution.81   </p><p>82</p><pre class="programlisting">83void (*InitializeDSMCustomScan) (CustomScanState *node,84                                 ParallelContext *pcxt,85                                 void *coordinate);86</pre><p>87    Initialize the dynamic shared memory that will be required for parallel88    operation.  <code class="literal">coordinate</code> points to a shared memory area of89    size equal to the return value of <code class="function">EstimateDSMCustomScan</code>.90    This callback is optional, and need only be supplied if this custom91    scan provider supports parallel execution.92   </p><p>93</p><pre class="programlisting">94void (*ReInitializeDSMCustomScan) (CustomScanState *node,95                                   ParallelContext *pcxt,96                                   void *coordinate);97</pre><p>98    Re-initialize the dynamic shared memory required for parallel operation99    when the custom-scan plan node is about to be re-scanned.100    This callback is optional, and need only be supplied if this custom101    scan provider supports parallel execution.102    Recommended practice is that this callback reset only shared state,103    while the <code class="function">ReScanCustomScan</code> callback resets only local104    state.  Currently, this callback will be called105    before <code class="function">ReScanCustomScan</code>, but it's best not to rely on106    that ordering.107   </p><p>108</p><pre class="programlisting">109void (*InitializeWorkerCustomScan) (CustomScanState *node,110                                    shm_toc *toc,111                                    void *coordinate);112</pre><p>113    Initialize a parallel worker's local state based on the shared state114    set up by the leader during <code class="function">InitializeDSMCustomScan</code>.115    This callback is optional, and need only be supplied if this custom116    scan provider supports parallel execution.117   </p><p>118</p><pre class="programlisting">119void (*ShutdownCustomScan) (CustomScanState *node);120</pre><p>121    Release resources when it is anticipated the node will not be executed122    to completion.  This is not called in all cases; sometimes,123    <code class="literal">EndCustomScan</code> may be called without this function having124    been called first.  Since the DSM segment used by parallel query is125    destroyed just after this callback is invoked, custom scan providers that126    wish to take some action before the DSM segment goes away should implement127    this method.128   </p><p>129</p><pre class="programlisting">130void (*ExplainCustomScan) (CustomScanState *node,131                           List *ancestors,132                           ExplainState *es);133</pre><p>134    Output additional information for <code class="command">EXPLAIN</code> of a custom-scan135    plan node.  This callback is optional.  Common data stored in the136    <code class="structname">ScanState</code>, such as the target list and scan relation, will137    be shown even without this callback, but the callback allows the display138    of additional, private state.139   </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-plan.html" title="61.2. Creating Custom Scan Plans">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="geqo.html" title="Chapter 62. Genetic Query Optimizer">Next</a></td></tr><tr><td width="40%" align="left" valign="top">61.2. Creating Custom Scan Plans </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"> Chapter 62. Genetic Query Optimizer</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai