PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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/plannodes.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

CustomScanStateExecInitCustomScan (CustomScan *cscan, EState *estate, int eflags)
 
TupleTableSlotExecCustomScan (CustomScanState *node)
 
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 ExecCustomScanInitializeWorker (CustomScanState *node, shm_toc *toc)
 
void ExecShutdownCustomScan (CustomScanState *node)
 

Function Documentation

void ExecCustomMarkPos ( CustomScanState node)

Definition at line 137 of file nodeCustom.c.

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

Referenced by ExecMarkPos().

138 {
139  if (!node->methods->MarkPosCustomScan)
140  ereport(ERROR,
141  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
142  errmsg("custom scan \"%s\" does not support MarkPos",
143  node->methods->CustomName)));
144  node->methods->MarkPosCustomScan(node);
145 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
#define ERROR
Definition: elog.h:43
void(* MarkPosCustomScan)(CustomScanState *node)
Definition: extensible.h:130
#define ereport(elevel, rest)
Definition: elog.h:122
const char * CustomName
Definition: extensible.h:119
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ExecCustomRestrPos ( CustomScanState node)

Definition at line 148 of file nodeCustom.c.

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

Referenced by ExecRestrPos().

149 {
150  if (!node->methods->RestrPosCustomScan)
151  ereport(ERROR,
152  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
153  errmsg("custom scan \"%s\" does not support MarkPos",
154  node->methods->CustomName)));
155  node->methods->RestrPosCustomScan(node);
156 }
int errcode(int sqlerrcode)
Definition: elog.c:575
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
const char * CustomName
Definition: extensible.h:119
void(* RestrPosCustomScan)(CustomScanState *node)
Definition: extensible.h:131
int errmsg(const char *fmt,...)
Definition: elog.c:797
TupleTableSlot* ExecCustomScan ( CustomScanState node)

Definition at line 105 of file nodeCustom.c.

References Assert, CustomExecMethods::ExecCustomScan, CustomScanState::methods, and NULL.

Referenced by ExecProcNode().

106 {
107  Assert(node->methods->ExecCustomScan != NULL);
108  return node->methods->ExecCustomScan(node);
109 }
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
TupleTableSlot *(* ExecCustomScan)(CustomScanState *node)
Definition: extensible.h:125
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
void ExecCustomScanEstimate ( CustomScanState node,
ParallelContext pcxt 
)

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

160 {
161  const CustomExecMethods *methods = node->methods;
162 
163  if (methods->EstimateDSMCustomScan)
164  {
165  node->pscan_len = methods->EstimateDSMCustomScan(node, pcxt);
167  shm_toc_estimate_keys(&pcxt->estimator, 1);
168  }
169 }
shm_toc_estimator estimator
Definition: parallel.h:41
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:49
Size(* EstimateDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt)
Definition: extensible.h:134
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:52
void ExecCustomScanInitializeDSM ( CustomScanState node,
ParallelContext pcxt 
)

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

173 {
174  const CustomExecMethods *methods = node->methods;
175 
176  if (methods->InitializeDSMCustomScan)
177  {
178  int plan_node_id = node->ss.ps.plan->plan_node_id;
179  void *coordinate;
180 
181  coordinate = shm_toc_allocate(pcxt->toc, node->pscan_len);
182  methods->InitializeDSMCustomScan(node, pcxt, coordinate);
183  shm_toc_insert(pcxt->toc, plan_node_id, coordinate);
184  }
185 }
int plan_node_id
Definition: plannodes.h:133
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
PlanState ps
Definition: execnodes.h:1047
ScanState ss
Definition: execnodes.h:1516
Plan * plan
Definition: execnodes.h:803
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:83
void(* InitializeDSMCustomScan)(CustomScanState *node, ParallelContext *pcxt, void *coordinate)
Definition: extensible.h:136
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:161
shm_toc * toc
Definition: parallel.h:44
void ExecCustomScanInitializeWorker ( CustomScanState node,
shm_toc toc 
)

Definition at line 188 of file nodeCustom.c.

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

Referenced by ExecParallelInitializeWorker().

189 {
190  const CustomExecMethods *methods = node->methods;
191 
192  if (methods->InitializeWorkerCustomScan)
193  {
194  int plan_node_id = node->ss.ps.plan->plan_node_id;
195  void *coordinate;
196 
197  coordinate = shm_toc_lookup(toc, plan_node_id);
198  methods->InitializeWorkerCustomScan(node, toc, coordinate);
199  }
200 }
int plan_node_id
Definition: plannodes.h:133
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
PlanState ps
Definition: execnodes.h:1047
ScanState ss
Definition: execnodes.h:1516
void * shm_toc_lookup(shm_toc *toc, uint64 key)
Definition: shm_toc.c:218
Plan * plan
Definition: execnodes.h:803
void(* InitializeWorkerCustomScan)(CustomScanState *node, shm_toc *toc, void *coordinate)
Definition: extensible.h:139
void ExecEndCustomScan ( CustomScanState node)

Definition at line 112 of file nodeCustom.c.

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

Referenced by ExecEndNode().

113 {
114  Assert(node->methods->EndCustomScan != NULL);
115  node->methods->EndCustomScan(node);
116 
117  /* Free the exprcontext */
118  ExecFreeExprContext(&node->ss.ps);
119 
120  /* Clean out the tuple table */
123 
124  /* Close the heap relation */
125  if (node->ss.ss_currentRelation)
127 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1050
Relation ss_currentRelation
Definition: execnodes.h:1048
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:516
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
PlanState ps
Definition: execnodes.h:1047
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:832
ScanState ss
Definition: execnodes.h:1516
void(* EndCustomScan)(CustomScanState *node)
Definition: extensible.h:126
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:661
CustomScanState* ExecInitCustomScan ( CustomScan cscan,
EState estate,
int  eflags 
)

Definition at line 24 of file nodeCustom.c.

References CustomExecMethods::BeginCustomScan, castNode, CustomScanMethods::CreateCustomScanState, CustomScan::custom_scan_tlist, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfoWithVarno(), ExecAssignScanType(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), ExecTypeFromTL(), CustomScan::flags, CustomScanState::flags, INDEX_VAR, CustomScan::methods, CustomScanState::methods, NIL, NULL, 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().

25 {
26  CustomScanState *css;
27  Relation scan_rel = NULL;
28  Index scanrelid = cscan->scan.scanrelid;
29  Index tlistvarno;
30 
31  /*
32  * Allocate the CustomScanState object. We let the custom scan provider
33  * do the palloc, in case it wants to make a larger object that embeds
34  * CustomScanState as the first field. It must set the node tag and the
35  * methods field correctly at this time. Other standard fields should be
36  * set to zero.
37  */
39  cscan->methods->CreateCustomScanState(cscan));
40 
41  /* ensure flags is filled correctly */
42  css->flags = cscan->flags;
43 
44  /* fill up fields of ScanState */
45  css->ss.ps.plan = &cscan->scan.plan;
46  css->ss.ps.state = estate;
47 
48  /* create expression context for node */
49  ExecAssignExprContext(estate, &css->ss.ps);
50 
51  /* initialize child expressions */
52  css->ss.ps.qual =
53  ExecInitQual(cscan->scan.plan.qual, (PlanState *) css);
54 
55  /* tuple table initialization */
56  ExecInitScanTupleSlot(estate, &css->ss);
57  ExecInitResultTupleSlot(estate, &css->ss.ps);
58 
59  /*
60  * open the base relation, if any, and acquire an appropriate lock on it
61  */
62  if (scanrelid > 0)
63  {
64  scan_rel = ExecOpenScanRelation(estate, scanrelid, eflags);
65  css->ss.ss_currentRelation = scan_rel;
66  }
67 
68  /*
69  * Determine the scan tuple type. If the custom scan provider provided a
70  * targetlist describing the scan tuples, use that; else use base
71  * relation's rowtype.
72  */
73  if (cscan->custom_scan_tlist != NIL || scan_rel == NULL)
74  {
75  TupleDesc scan_tupdesc;
76 
77  scan_tupdesc = ExecTypeFromTL(cscan->custom_scan_tlist, false);
78  ExecAssignScanType(&css->ss, scan_tupdesc);
79  /* Node's targetlist will contain Vars with varno = INDEX_VAR */
80  tlistvarno = INDEX_VAR;
81  }
82  else
83  {
84  ExecAssignScanType(&css->ss, RelationGetDescr(scan_rel));
85  /* Node's targetlist will contain Vars with varno = scanrelid */
86  tlistvarno = scanrelid;
87  }
88 
89  /*
90  * Initialize result tuple type and projection info.
91  */
93  ExecAssignScanProjectionInfoWithVarno(&css->ss, tlistvarno);
94 
95  /*
96  * The callback of custom-scan provider applies the final initialization
97  * of the custom-scan-state node according to its logic.
98  */
99  css->methods->BeginCustomScan(css, estate, eflags);
100 
101  return css;
102 }
#define NIL
Definition: pg_list.h:69
List * qual
Definition: plannodes.h:135
Plan plan
Definition: plannodes.h:317
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
Index scanrelid
Definition: plannodes.h:318
#define RelationGetDescr(relation)
Definition: rel.h:429
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
Node *(* CreateCustomScanState)(CustomScan *cscan)
Definition: extensible.h:110
Relation ss_currentRelation
Definition: execnodes.h:1048
EState * state
Definition: execnodes.h:805
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:440
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
void ExecAssignScanProjectionInfoWithVarno(ScanState *node, Index varno)
Definition: execScan.c:247
PlanState ps
Definition: execnodes.h:1047
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:603
ScanState ss
Definition: execnodes.h:1516
void(* BeginCustomScan)(CustomScanState *node, EState *estate, int eflags)
Definition: extensible.h:122
const struct CustomScanMethods * methods
Definition: plannodes.h:624
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:888
Scan scan
Definition: plannodes.h:615
unsigned int Index
Definition: c.h:365
Plan * plan
Definition: execnodes.h:803
#define NULL
Definition: c.h:229
List * custom_scan_tlist
Definition: plannodes.h:621
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:418
ExprState * qual
Definition: execnodes.h:817
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:540
#define INDEX_VAR
Definition: primnodes.h:155
uint32 flags
Definition: plannodes.h:616
void ExecReScanCustomScan ( CustomScanState node)

Definition at line 130 of file nodeCustom.c.

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

Referenced by ExecReScan().

131 {
132  Assert(node->methods->ReScanCustomScan != NULL);
133  node->methods->ReScanCustomScan(node);
134 }
void(* ReScanCustomScan)(CustomScanState *node)
Definition: extensible.h:127
const struct CustomExecMethods * methods
Definition: execnodes.h:1521
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
void ExecShutdownCustomScan ( CustomScanState node)

Definition at line 203 of file nodeCustom.c.

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

Referenced by ExecShutdownNode().

204 {
205  const CustomExecMethods *methods = node->methods;
206 
207  if (methods->ShutdownCustomScan)
208  methods->ShutdownCustomScan(node);
209 }
void(* ShutdownCustomScan)(CustomScanState *node)
Definition: extensible.h:142
const struct CustomExecMethods * methods
Definition: execnodes.h:1521