PostgreSQL Source Code  git master
nodeCustom.c File Reference
#include "postgres.h"
#include "access/parallel.h"
#include "executor/executor.h"
#include "executor/nodeCustom.h"
#include "nodes/execnodes.h"
#include "nodes/extensible.h"
#include "nodes/plannodes.h"
#include "miscadmin.h"
#include "parser/parsetree.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "utils/rel.h"
Include dependency graph for nodeCustom.c:

Go to the source code of this file.

Functions

static TupleTableSlotExecCustomScan (PlanState *pstate)
 
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 141 of file nodeCustom.c.

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

Referenced by ExecMarkPos().

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

◆ ExecCustomRestrPos()

void ExecCustomRestrPos ( CustomScanState node)

Definition at line 152 of file nodeCustom.c.

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

Referenced by ExecRestrPos().

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

◆ ExecCustomScan()

static TupleTableSlot * ExecCustomScan ( PlanState pstate)
static

Definition at line 109 of file nodeCustom.c.

References Assert, castNode, CHECK_FOR_INTERRUPTS, CustomExecMethods::ExecCustomScan, and CustomScanState::methods.

Referenced by ExecInitCustomScan().

110 {
111  CustomScanState *node = castNode(CustomScanState, pstate);
112 
114 
115  Assert(node->methods->ExecCustomScan != NULL);
116  return node->methods->ExecCustomScan(node);
117 }
#define castNode(_type_, nodeptr)
Definition: nodes.h:593
const struct CustomExecMethods * methods
Definition: execnodes.h:1764
TupleTableSlot *(* ExecCustomScan)(CustomScanState *node)
Definition: extensible.h:128
#define Assert(condition)
Definition: c.h:732
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99

◆ ExecCustomScanEstimate()

void ExecCustomScanEstimate ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 163 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().

164 {
165  const CustomExecMethods *methods = node->methods;
166 
167  if (methods->EstimateDSMCustomScan)
168  {
169  node->pscan_len = methods->EstimateDSMCustomScan(node, pcxt);
171  shm_toc_estimate_keys(&pcxt->estimator, 1);
172  }
173 }
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:1764
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53

◆ ExecCustomScanInitializeDSM()

void ExecCustomScanInitializeDSM ( CustomScanState node,
ParallelContext pcxt 
)

Definition at line 176 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().

177 {
178  const CustomExecMethods *methods = node->methods;
179 
180  if (methods->InitializeDSMCustomScan)
181  {
182  int plan_node_id = node->ss.ps.plan->plan_node_id;
183  void *coordinate;
184 
185  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
186  methods->InitializeDSMCustomScan(node, pcxt, coordinate);
187  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
188  }
189 }
int plan_node_id
Definition: plannodes.h:139
const struct CustomExecMethods * methods
Definition: execnodes.h:1764
PlanState ps
Definition: execnodes.h:1280
ScanState ss
Definition: execnodes.h:1759
Plan * plan
Definition: execnodes.h:945
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 207 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().

209 {
210  const CustomExecMethods *methods = node->methods;
211 
212  if (methods->InitializeWorkerCustomScan)
213  {
214  int plan_node_id = node->ss.ps.plan->plan_node_id;
215  void *coordinate;
216 
217  coordinate = shm_toc_lookup(pwcxt->toc, plan_node_id, false);
218  methods->InitializeWorkerCustomScan(node, pwcxt->toc, coordinate);
219  }
220 }
int plan_node_id
Definition: plannodes.h:139
const struct CustomExecMethods * methods
Definition: execnodes.h:1764
PlanState ps
Definition: execnodes.h:1280
ScanState ss
Definition: execnodes.h:1759
void(* InitializeWorkerCustomScan)(CustomScanState *node, shm_toc *toc, void *coordinate)
Definition: extensible.h:145
Plan * plan
Definition: execnodes.h:945
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 192 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().

193 {
194  const CustomExecMethods *methods = node->methods;
195 
196  if (methods->ReInitializeDSMCustomScan)
197  {
198  int plan_node_id = node->ss.ps.plan->plan_node_id;
199  void *coordinate;
200 
201  coordinate = shm_toc_lookup(pcxt->toc, plan_node_id, false);
202  methods->ReInitializeDSMCustomScan(node, pcxt, coordinate);
203  }
204 }
int plan_node_id
Definition: plannodes.h:139
void(* ReInitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:142
const struct CustomExecMethods * methods
Definition: execnodes.h:1764
PlanState ps
Definition: execnodes.h:1280
ScanState ss
Definition: execnodes.h:1759
Plan * plan
Definition: execnodes.h:945
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 120 of file nodeCustom.c.

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

Referenced by ExecEndNode().

121 {
122  Assert(node->methods->EndCustomScan != NULL);
123  node->methods->EndCustomScan(node);
124 
125  /* Free the exprcontext */
126  ExecFreeExprContext(&node->ss.ps);
127 
128  /* Clean out the tuple table */
131 }
void(* EndCustomScan)(CustomScanState *node)
Definition: extensible.h:129
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1283
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:616
const struct CustomExecMethods * methods
Definition: execnodes.h:1764
PlanState ps
Definition: execnodes.h:1280
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:983
ScanState ss
Definition: execnodes.h:1759
#define Assert(condition)
Definition: c.h:732

◆ ExecInitCustomScan()

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

Definition at line 30 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, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

31 {
32  CustomScanState *css;
33  Relation scan_rel = NULL;
34  Index scanrelid = cscan->scan.scanrelid;
35  Index 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  * Determine the scan tuple type. If the custom scan provider provided a
69  * targetlist describing the scan tuples, use that; else use base
70  * relation's rowtype.
71  */
72  if (cscan->custom_scan_tlist != NIL || scan_rel == NULL)
73  {
74  TupleDesc scan_tupdesc;
75 
76  scan_tupdesc = ExecTypeFromTL(cscan->custom_scan_tlist);
77  ExecInitScanTupleSlot(estate, &css->ss, scan_tupdesc, &TTSOpsVirtual);
78  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
79  tlistvarno = INDEX_VAR;
80  }
81  else
82  {
83  ExecInitScanTupleSlot(estate, &css->ss, RelationGetDescr(scan_rel),
84  &TTSOpsVirtual);
85  /* Node's targetlist will contain Vars with varno = scanrelid */
86  tlistvarno = scanrelid;
87  }
88 
89  /*
90  * Initialize result slot, type and projection.
91  */
93  ExecAssignScanProjectionInfoWithVarno(&css->ss, tlistvarno);
94 
95  /* initialize child expressions */
96  css->ss.ps.qual =
97  ExecInitQual(cscan->scan.plan.qual, (PlanState *) css);
98 
99  /*
100  * The callback of custom-scan provider applies the final initialization
101  * of the custom-scan-state node according to its logic.
102  */
103  css->methods->BeginCustomScan(css, estate, eflags);
104 
105  return css;
106 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
Plan plan
Definition: plannodes.h:340
Index scanrelid
Definition: plannodes.h:341
static TupleTableSlot * ExecCustomScan(PlanState *pstate)
Definition: nodeCustom.c:109
#define RelationGetDescr(relation)
Definition: rel.h:442
#define castNode(_type_, nodeptr)
Definition: nodes.h:593
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
Relation ss_currentRelation
Definition: execnodes.h:1281
EState * state
Definition: execnodes.h:947
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:207
const struct CustomExecMethods * methods
Definition: execnodes.h:1764
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, Index varno)
Definition: execScan.c:246
PlanState ps
Definition: execnodes.h:1280
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:695
ScanState ss
Definition: execnodes.h:1759
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1776
Node *(* CreateCustomScanState)(CustomScan *cscan)
Definition: extensible.h:113
const struct CustomScanMethods * methods
Definition: plannodes.h:646
void(* BeginCustomScan)(CustomScanState *node, EState *estate, int eflags)
Definition: extensible.h:125
Scan scan
Definition: plannodes.h:638
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:951
unsigned int Index
Definition: c.h:475
Plan * plan
Definition: execnodes.h:945
List * custom_scan_tlist
Definition: plannodes.h:644
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:446
TupleDesc ExecTypeFromTL(List *targetList)
Definition: execTuples.c:1904
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1764
ExprState * qual
Definition: execnodes.h:966
#define INDEX_VAR
Definition: primnodes.h:159
uint32 flags
Definition: plannodes.h:639

◆ ExecReScanCustomScan()

void ExecReScanCustomScan ( CustomScanState node)

Definition at line 134 of file nodeCustom.c.

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

Referenced by ExecReScan().

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

◆ ExecShutdownCustomScan()

void ExecShutdownCustomScan ( CustomScanState node)

Definition at line 223 of file nodeCustom.c.

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

Referenced by ExecShutdownNode().

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