PostgreSQL Source Code  git master
nodeCustom.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
#include "nodes/extensible.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 *custom_scan, 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 143 of file nodeCustom.c.

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

Referenced by ExecMarkPos().

144 {
145  if (!node->methods->MarkPosCustomScan)
146  ereport(ERROR,
147  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
148  errmsg("custom scan \"%s\" does not support MarkPos",
149  node->methods->CustomName)));
150  node->methods->MarkPosCustomScan(node);
151 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
const char * CustomName
Definition: extensible.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void(* MarkPosCustomScan)(CustomScanState *node)
Definition: extensible.h:133

◆ ExecCustomRestrPos()

void ExecCustomRestrPos ( CustomScanState node)

Definition at line 154 of file nodeCustom.c.

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

Referenced by ExecRestrPos().

155 {
156  if (!node->methods->RestrPosCustomScan)
157  ereport(ERROR,
158  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
159  errmsg("custom scan \"%s\" does not support MarkPos",
160  node->methods->CustomName)));
161  node->methods->RestrPosCustomScan(node);
162 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
void(* RestrPosCustomScan)(CustomScanState *node)
Definition: extensible.h:134
const char * CustomName
Definition: extensible.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797

◆ ExecCustomScanEstimate()

void ExecCustomScanEstimate ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 165 of file nodeCustom.c.

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

Referenced by ExecParallelEstimate().

166 {
167  const CustomExecMethods *methods = node->methods;
168 
169  if (methods->EstimateDSMCustomScan)
170  {
171  node->pscan_len = methods->EstimateDSMCustomScan(node, pcxt);
173  shm_toc_estimate_keys(&pcxt->estimator, 1);
174  }
175 }
shm_toc_estimator estimator
Definition: parallel.h:41
Size(* EstimateDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt)
Definition: extensible.h:137
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecCustomScanInitializeDSM()

void ExecCustomScanInitializeDSM ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 178 of file nodeCustom.c.

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().

179 {
180  const CustomExecMethods *methods = node->methods;
181 
182  if (methods->InitializeDSMCustomScan)
183  {
184  int plan_node_id = node->ss.ps.plan->plan_node_id;
185  void *coordinate;
186 
187  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
188  methods->InitializeDSMCustomScan(node, pcxt, coordinate);
189  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
190  }
191 }
int plan_node_id
Definition: plannodes.h:143
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
PlanState ps
Definition: execnodes.h:1124
ScanState ss
Definition: execnodes.h:1600
Plan * plan
Definition: execnodes.h:868
void(* InitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:139
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
shm_toc * toc
Definition: parallel.h:44

◆ ExecCustomScanInitializeWorker()

void ExecCustomScanInitializeWorker ( CustomScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 209 of file nodeCustom.c.

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

Referenced by ExecParallelInitializeWorker().

211 {
212  const CustomExecMethods *methods = node->methods;
213 
214  if (methods->InitializeWorkerCustomScan)
215  {
216  int plan_node_id = node->ss.ps.plan->plan_node_id;
217  void *coordinate;
218 
219  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
220  methods->InitializeWorkerCustomScan(node, pwcxt->toc, coordinate);
221  }
222 }
int plan_node_id
Definition: plannodes.h:143
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
PlanState ps
Definition: execnodes.h:1124
ScanState ss
Definition: execnodes.h:1600
void(* InitializeWorkerCustomScan)(CustomScanState *node, shm_toc *toc, void *coordinate)
Definition: extensible.h:145
Plan * plan
Definition: execnodes.h:868
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

◆ ExecCustomScanReInitializeDSM()

void ExecCustomScanReInitializeDSM ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 194 of file nodeCustom.c.

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

Referenced by ExecParallelReInitializeDSM().

195 {
196  const CustomExecMethods *methods = node->methods;
197 
198  if (methods->ReInitializeDSMCustomScan)
199  {
200  int plan_node_id = node->ss.ps.plan->plan_node_id;
201  void *coordinate;
202 
203  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
204  methods->ReInitializeDSMCustomScan(node, pcxt, coordinate);
205  }
206 }
int plan_node_id
Definition: plannodes.h:143
void(* ReInitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:142
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
PlanState ps
Definition: execnodes.h:1124
ScanState ss
Definition: execnodes.h:1600
Plan * plan
Definition: execnodes.h:868
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
shm_toc * toc
Definition: parallel.h:44

◆ ExecEndCustomScan()

void ExecEndCustomScan ( CustomScanState node)

Definition at line 118 of file nodeCustom.c.

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

Referenced by ExecEndNode().

119 {
120  Assert(node->methods->EndCustomScan != NULL);
121  node->methods->EndCustomScan(node);
122 
123  /* Free the exprcontext */
124  ExecFreeExprContext(&node->ss.ps);
125 
126  /* Clean out the tuple table */
129 
130  /* Close the heap relation */
131  if (node->ss.ss_currentRelation)
133 }
void(* EndCustomScan)(CustomScanState *node)
Definition: extensible.h:129
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1127
Relation ss_currentRelation
Definition: execnodes.h:1125
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:561
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
PlanState ps
Definition: execnodes.h:1124
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:901
ScanState ss
Definition: execnodes.h:1600
#define Assert(condition)
Definition: c.h:688
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:696

◆ ExecInitCustomScan()

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

Definition at line 29 of file nodeCustom.c.

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

Referenced by ExecInitNode().

30 {
31  CustomScanState *css;
32  Relation scan_rel = NULL;
33  Index scanrelid = cscan->scan.scanrelid;
34  Index tlistvarno;
35 
36  /*
37  * Allocate the CustomScanState object. We let the custom scan provider
38  * do the palloc, in case it wants to make a larger object that embeds
39  * CustomScanState as the first field. It must set the node tag and the
40  * methods field correctly at this time. Other standard fields should be
41  * set to zero.
42  */
44  cscan->methods->CreateCustomScanState(cscan));
45 
46  /* ensure flags is filled correctly */
47  css->flags = cscan->flags;
48 
49  /* fill up fields of ScanState */
50  css->ss.ps.plan = &cscan->scan.plan;
51  css->ss.ps.state = estate;
53 
54  /* create expression context for node */
55  ExecAssignExprContext(estate, &css->ss.ps);
56 
57  /*
58  * open the base relation, if any, and acquire an appropriate lock on it
59  */
60  if (scanrelid > 0)
61  {
62  scan_rel = ExecOpenScanRelation(estate, scanrelid, eflags);
63  css->ss.ss_currentRelation = scan_rel;
64  }
65 
66  /*
67  * Determine the scan tuple type. If the custom scan provider provided a
68  * targetlist describing the scan tuples, use that; else use base
69  * relation's rowtype.
70  */
71  if (cscan->custom_scan_tlist != NIL || scan_rel == NULL)
72  {
73  TupleDesc scan_tupdesc;
74 
75  scan_tupdesc = ExecTypeFromTL(cscan->custom_scan_tlist, false);
76  ExecInitScanTupleSlot(estate, &css->ss, scan_tupdesc);
77  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
78  tlistvarno = INDEX_VAR;
79  }
80  else
81  {
82  ExecInitScanTupleSlot(estate, &css->ss, RelationGetDescr(scan_rel));
83  /* Node's targetlist will contain Vars with varno = scanrelid */
84  tlistvarno = scanrelid;
85  }
86 
87  /*
88  * Initialize result slot, type and projection.
89  */
90  ExecInitResultTupleSlotTL(estate, &css->ss.ps);
91  ExecAssignScanProjectionInfoWithVarno(&css->ss, tlistvarno);
92 
93  /* initialize child expressions */
94  css->ss.ps.qual =
95  ExecInitQual(cscan->scan.plan.qual, (PlanState *) css);
96 
97  /*
98  * The callback of custom-scan provider applies the final initialization
99  * of the custom-scan-state node according to its logic.
100  */
101  css->methods->BeginCustomScan(css, estate, eflags);
102 
103  return css;
104 }
#define NIL
Definition: pg_list.h:69
static TupleTableSlot * ExecCustomScan(PlanState *pstate)
Definition: nodeCustom.c:107
#define RelationGetDescr(relation)
Definition: rel.h:437
#define castNode(_type_, nodeptr)
Definition: nodes.h:582
Relation ss_currentRelation
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:870
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:204
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, Index varno)
Definition: execScan.c:248
PlanState ps
Definition: execnodes.h:1124
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:638
ScanState ss
Definition: execnodes.h:1600
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:944
void(* BeginCustomScan)(CustomScanState *node, EState *estate, int eflags)
Definition: extensible.h:125
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
unsigned int Index
Definition: c.h:431
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
Plan * plan
Definition: execnodes.h:868
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:425
ExprState * qual
Definition: execnodes.h:886
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc)
Definition: execTuples.c:895
#define INDEX_VAR
Definition: primnodes.h:155

◆ ExecReScanCustomScan()

void ExecReScanCustomScan ( CustomScanState node)

Definition at line 136 of file nodeCustom.c.

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

Referenced by ExecReScan().

137 {
138  Assert(node->methods->ReScanCustomScan != NULL);
139  node->methods->ReScanCustomScan(node);
140 }
void(* ReScanCustomScan)(CustomScanState *node)
Definition: extensible.h:130
const struct CustomExecMethods * methods
Definition: execnodes.h:1605
#define Assert(condition)
Definition: c.h:688

◆ ExecShutdownCustomScan()

void ExecShutdownCustomScan ( CustomScanState node)

Definition at line 225 of file nodeCustom.c.

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

Referenced by ExecShutdownNode().

226 {
227  const CustomExecMethods *methods = node->methods;
228 
229  if (methods->ShutdownCustomScan)
230  methods->ShutdownCustomScan(node);
231 }
void(* ShutdownCustomScan)(CustomScanState *node)
Definition: extensible.h:148
const struct CustomExecMethods * methods
Definition: execnodes.h:1605