PostgreSQL Source Code  git master
nodeCustom.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
Include dependency graph for nodeCustom.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

CustomScanStateExecInitCustomScan (CustomScan *cscan, EState *estate, int eflags)
 
void ExecEndCustomScan (CustomScanState *node)
 
void ExecReScanCustomScan (CustomScanState *node)
 
void ExecCustomMarkPos (CustomScanState *node)
 
void ExecCustomRestrPos (CustomScanState *node)
 
void ExecCustomScanEstimate (CustomScanState *node, ParallelContext *pcxt)
 
void ExecCustomScanInitializeDSM (CustomScanState *node, ParallelContext *pcxt)
 
void ExecCustomScanReInitializeDSM (CustomScanState *node, ParallelContext *pcxt)
 
void ExecCustomScanInitializeWorker (CustomScanState *node, ParallelWorkerContext *pwcxt)
 
void ExecShutdownCustomScan (CustomScanState *node)
 

Function Documentation

◆ ExecCustomMarkPos()

void ExecCustomMarkPos ( CustomScanState node)

Definition at line 149 of file nodeCustom.c.

150 {
151  if (!node->methods->MarkPosCustomScan)
152  ereport(ERROR,
153  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
154  errmsg("custom scan \"%s\" does not support MarkPos",
155  node->methods->CustomName)));
156  node->methods->MarkPosCustomScan(node);
157 }
int errcode(int sqlerrcode)
Definition: elog.c:695
int errmsg(const char *fmt,...)
Definition: elog.c:906
#define ERROR
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:145
const char * CustomName
Definition: extensible.h:126
void(* MarkPosCustomScan)(CustomScanState *node)
Definition: extensible.h:137
const struct CustomExecMethods * methods
Definition: execnodes.h:1960

References CustomExecMethods::CustomName, ereport, errcode(), errmsg(), ERROR, CustomExecMethods::MarkPosCustomScan, and CustomScanState::methods.

Referenced by ExecMarkPos().

◆ ExecCustomRestrPos()

void ExecCustomRestrPos ( CustomScanState node)

Definition at line 160 of file nodeCustom.c.

161 {
162  if (!node->methods->RestrPosCustomScan)
163  ereport(ERROR,
164  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
165  errmsg("custom scan \"%s\" does not support MarkPos",
166  node->methods->CustomName)));
167  node->methods->RestrPosCustomScan(node);
168 }
void(* RestrPosCustomScan)(CustomScanState *node)
Definition: extensible.h:138

References CustomExecMethods::CustomName, ereport, errcode(), errmsg(), ERROR, CustomScanState::methods, and CustomExecMethods::RestrPosCustomScan.

Referenced by ExecRestrPos().

◆ ExecCustomScanEstimate()

void ExecCustomScanEstimate ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 171 of file nodeCustom.c.

172 {
173  const CustomExecMethods *methods = node->methods;
174 
175  if (methods->EstimateDSMCustomScan)
176  {
177  node->pscan_len = methods->EstimateDSMCustomScan(node, pcxt);
179  shm_toc_estimate_keys(&pcxt->estimator, 1);
180  }
181 }
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size(* EstimateDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt)
Definition: extensible.h:141
shm_toc_estimator estimator
Definition: parallel.h:42

References CustomExecMethods::EstimateDSMCustomScan, ParallelContext::estimator, CustomScanState::methods, CustomScanState::pscan_len, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

◆ ExecCustomScanInitializeDSM()

void ExecCustomScanInitializeDSM ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 184 of file nodeCustom.c.

185 {
186  const CustomExecMethods *methods = node->methods;
187 
188  if (methods->InitializeDSMCustomScan)
189  {
190  int plan_node_id = node->ss.ps.plan->plan_node_id;
191  void *coordinate;
192 
193  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
194  methods->InitializeDSMCustomScan(node, pcxt, coordinate);
195  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
196  }
197 }
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void(* InitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:143
ScanState ss
Definition: execnodes.h:1955
shm_toc * toc
Definition: parallel.h:45
Plan * plan
Definition: execnodes.h:1024
int plan_node_id
Definition: plannodes.h:149
PlanState ps
Definition: execnodes.h:1449

References CustomExecMethods::InitializeDSMCustomScan, CustomScanState::methods, PlanState::plan, Plan::plan_node_id, ScanState::ps, CustomScanState::pscan_len, shm_toc_allocate(), shm_toc_insert(), CustomScanState::ss, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

◆ ExecCustomScanInitializeWorker()

void ExecCustomScanInitializeWorker ( CustomScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 215 of file nodeCustom.c.

217 {
218  const CustomExecMethods *methods = node->methods;
219 
220  if (methods->InitializeWorkerCustomScan)
221  {
222  int plan_node_id = node->ss.ps.plan->plan_node_id;
223  void *coordinate;
224 
225  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
226  methods->InitializeWorkerCustomScan(node, pwcxt->toc, coordinate);
227  }
228 }
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
void(* InitializeWorkerCustomScan)(CustomScanState *node, shm_toc *toc, void *coordinate)
Definition: extensible.h:149

References CustomExecMethods::InitializeWorkerCustomScan, CustomScanState::methods, PlanState::plan, Plan::plan_node_id, ScanState::ps, shm_toc_lookup(), CustomScanState::ss, and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecCustomScanReInitializeDSM()

void ExecCustomScanReInitializeDSM ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 200 of file nodeCustom.c.

201 {
202  const CustomExecMethods *methods = node->methods;
203 
204  if (methods->ReInitializeDSMCustomScan)
205  {
206  int plan_node_id = node->ss.ps.plan->plan_node_id;
207  void *coordinate;
208 
209  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
210  methods->ReInitializeDSMCustomScan(node, pcxt, coordinate);
211  }
212 }
void(* ReInitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:146

References CustomScanState::methods, PlanState::plan, Plan::plan_node_id, ScanState::ps, CustomExecMethods::ReInitializeDSMCustomScan, shm_toc_lookup(), CustomScanState::ss, and ParallelContext::toc.

Referenced by ExecParallelReInitializeDSM().

◆ ExecEndCustomScan()

void ExecEndCustomScan ( CustomScanState node)

Definition at line 128 of file nodeCustom.c.

129 {
130  Assert(node->methods->EndCustomScan != NULL);
131  node->methods->EndCustomScan(node);
132 
133  /* Free the exprcontext */
134  ExecFreeExprContext(&node->ss.ps);
135 
136  /* Clean out the tuple table */
139 }
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:651
Assert(fmt[strlen(fmt) - 1] !='\n')
void(* EndCustomScan)(CustomScanState *node)
Definition: extensible.h:133
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1062
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1452
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

References Assert(), CustomExecMethods::EndCustomScan, ExecClearTuple(), ExecFreeExprContext(), CustomScanState::methods, ScanState::ps, PlanState::ps_ResultTupleSlot, CustomScanState::ss, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

◆ ExecInitCustomScan()

CustomScanState* ExecInitCustomScan ( CustomScan cscan,
EState estate,
int  eflags 
)

Definition at line 29 of file nodeCustom.c.

30 {
31  CustomScanState *css;
32  const TupleTableSlotOps *slotOps;
33  Relation scan_rel = NULL;
34  Index scanrelid = cscan->scan.scanrelid;
35  int tlistvarno;
36 
37  /*
38  * Allocate the CustomScanState object. We let the custom scan provider
39  * do the palloc, in case it wants to make a larger object that embeds
40  * CustomScanState as the first field. It must set the node tag and the
41  * methods field correctly at this time. Other standard fields should be
42  * set to zero.
43  */
45  cscan->methods->CreateCustomScanState(cscan));
46 
47  /* ensure flags is filled correctly */
48  css->flags = cscan->flags;
49 
50  /* fill up fields of ScanState */
51  css->ss.ps.plan = &cscan->scan.plan;
52  css->ss.ps.state = estate;
54 
55  /* create expression context for node */
56  ExecAssignExprContext(estate, &css->ss.ps);
57 
58  /*
59  * open the scan relation, if any
60  */
61  if (scanrelid > 0)
62  {
63  scan_rel = ExecOpenScanRelation(estate, scanrelid, eflags);
64  css->ss.ss_currentRelation = scan_rel;
65  }
66 
67  /*
68  * Use a custom slot if specified in CustomScanState or use virtual slot
69  * otherwise.
70  */
71  slotOps = css->slotOps;
72  if (!slotOps)
73  slotOps = &TTSOpsVirtual;
74 
75  /*
76  * Determine the scan tuple type. If the custom scan provider provided a
77  * targetlist describing the scan tuples, use that; else use base
78  * relation's rowtype.
79  */
80  if (cscan->custom_scan_tlist != NIL || scan_rel == NULL)
81  {
82  TupleDesc scan_tupdesc;
83 
84  scan_tupdesc = ExecTypeFromTL(cscan->custom_scan_tlist);
85  ExecInitScanTupleSlot(estate, &css->ss, scan_tupdesc, slotOps);
86  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
87  tlistvarno = INDEX_VAR;
88  }
89  else
90  {
91  ExecInitScanTupleSlot(estate, &css->ss, RelationGetDescr(scan_rel),
92  slotOps);
93  /* Node's targetlist will contain Vars with varno = scanrelid */
94  tlistvarno = scanrelid;
95  }
96 
97  /*
98  * Initialize result slot, type and projection.
99  */
101  ExecAssignScanProjectionInfoWithVarno(&css->ss, tlistvarno);
102 
103  /* initialize child expressions */
104  css->ss.ps.qual =
105  ExecInitQual(cscan->scan.plan.qual, (PlanState *) css);
106 
107  /*
108  * The callback of custom-scan provider applies the final initialization
109  * of the custom-scan-state node according to its logic.
110  */
111  css->methods->BeginCustomScan(css, estate, eflags);
112 
113  return css;
114 }
unsigned int Index
Definition: c.h:550
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:210
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, int varno)
Definition: execScan.c:285
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1811
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1799
TupleDesc ExecTypeFromTL(List *targetList)
Definition: execTuples.c:1938
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:481
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:721
static TupleTableSlot * ExecCustomScan(PlanState *pstate)
Definition: nodeCustom.c:117
#define castNode(_type_, nodeptr)
Definition: nodes.h:180
#define NIL
Definition: pg_list.h:66
#define INDEX_VAR
Definition: primnodes.h:195
#define RelationGetDescr(relation)
Definition: rel.h:527
void(* BeginCustomScan)(CustomScanState *node, EState *estate, int eflags)
Definition: extensible.h:129
Node *(* CreateCustomScanState)(CustomScan *cscan)
Definition: extensible.h:117
const struct TupleTableSlotOps * slotOps
Definition: execnodes.h:1961
uint32 flags
Definition: plannodes.h:733
List * custom_scan_tlist
Definition: plannodes.h:738
Scan scan
Definition: plannodes.h:732
const struct CustomScanMethods * methods
Definition: plannodes.h:746
ExprState * qual
Definition: execnodes.h:1045
EState * state
Definition: execnodes.h:1026
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1030
Relation ss_currentRelation
Definition: execnodes.h:1450
Index scanrelid
Definition: plannodes.h:384

References CustomExecMethods::BeginCustomScan, castNode, CustomScanMethods::CreateCustomScanState, CustomScan::custom_scan_tlist, ExecAssignExprContext(), ExecAssignScanProjectionInfoWithVarno(), ExecCustomScan(), ExecInitQual(), ExecInitResultTupleSlotTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, ExecTypeFromTL(), CustomScanState::flags, CustomScan::flags, INDEX_VAR, CustomScanState::methods, CustomScan::methods, NIL, PlanState::plan, ScanState::ps, PlanState::qual, RelationGetDescr, CustomScan::scan, Scan::scanrelid, CustomScanState::slotOps, CustomScanState::ss, ScanState::ss_currentRelation, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanCustomScan()

void ExecReScanCustomScan ( CustomScanState node)

Definition at line 142 of file nodeCustom.c.

143 {
144  Assert(node->methods->ReScanCustomScan != NULL);
145  node->methods->ReScanCustomScan(node);
146 }
void(* ReScanCustomScan)(CustomScanState *node)
Definition: extensible.h:134

References Assert(), CustomScanState::methods, and CustomExecMethods::ReScanCustomScan.

Referenced by ExecReScan().

◆ ExecShutdownCustomScan()

void ExecShutdownCustomScan ( CustomScanState node)

Definition at line 231 of file nodeCustom.c.

232 {
233  const CustomExecMethods *methods = node->methods;
234 
235  if (methods->ShutdownCustomScan)
236  methods->ShutdownCustomScan(node);
237 }
void(* ShutdownCustomScan)(CustomScanState *node)
Definition: extensible.h:152

References CustomScanState::methods, and CustomExecMethods::ShutdownCustomScan.

Referenced by ExecShutdownNode_walker().