PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeWorktablescan.c File Reference
Include dependency graph for nodeWorktablescan.c:

Go to the source code of this file.

Functions

static TupleTableSlotWorkTableScanNext (WorkTableScanState *node)
 
static bool WorkTableScanRecheck (WorkTableScanState *node, TupleTableSlot *slot)
 
static TupleTableSlotExecWorkTableScan (PlanState *pstate)
 
WorkTableScanStateExecInitWorkTableScan (WorkTableScan *node, EState *estate, int eflags)
 
void ExecEndWorkTableScan (WorkTableScanState *node)
 
void ExecReScanWorkTableScan (WorkTableScanState *node)
 

Function Documentation

void ExecEndWorkTableScan ( WorkTableScanState node)

Definition at line 186 of file nodeWorktablescan.c.

References ExecClearTuple(), ExecFreeExprContext(), ScanState::ps, PlanState::ps_ResultTupleSlot, WorkTableScanState::ss, and ScanState::ss_ScanTupleSlot.

Referenced by ExecEndNode().

187 {
188  /*
189  * Free exprcontext
190  */
191  ExecFreeExprContext(&node->ss.ps);
192 
193  /*
194  * clean out the tuple table
195  */
198 }
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1101
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:521
PlanState ps
Definition: execnodes.h:1098
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
WorkTableScanState* ExecInitWorkTableScan ( WorkTableScan node,
EState estate,
int  eflags 
)

Definition at line 130 of file nodeWorktablescan.c.

References Assert, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), PlanState::ExecProcNode, ExecWorkTableScan(), innerPlan, makeNode, NULL, outerPlan, Scan::plan, PlanState::plan, ScanState::ps, Plan::qual, PlanState::qual, WorkTableScanState::rustate, WorkTableScan::scan, WorkTableScanState::ss, and PlanState::state.

Referenced by ExecInitNode().

131 {
132  WorkTableScanState *scanstate;
133 
134  /* check for unsupported flags */
135  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
136 
137  /*
138  * WorkTableScan should not have any children.
139  */
140  Assert(outerPlan(node) == NULL);
141  Assert(innerPlan(node) == NULL);
142 
143  /*
144  * create new WorkTableScanState for node
145  */
146  scanstate = makeNode(WorkTableScanState);
147  scanstate->ss.ps.plan = (Plan *) node;
148  scanstate->ss.ps.state = estate;
149  scanstate->ss.ps.ExecProcNode = ExecWorkTableScan;
150  scanstate->rustate = NULL; /* we'll set this later */
151 
152  /*
153  * Miscellaneous initialization
154  *
155  * create expression context for node
156  */
157  ExecAssignExprContext(estate, &scanstate->ss.ps);
158 
159  /*
160  * initialize child expressions
161  */
162  scanstate->ss.ps.qual =
163  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
164 
165  /*
166  * tuple table initialization
167  */
168  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
169  ExecInitScanTupleSlot(estate, &scanstate->ss);
170 
171  /*
172  * Initialize result tuple type, but not yet projection info.
173  */
174  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
175 
176  return scanstate;
177 }
List * qual
Definition: plannodes.h:145
Plan plan
Definition: plannodes.h:328
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
EState * state
Definition: execnodes.h:849
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
PlanState ps
Definition: execnodes.h:1098
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define innerPlan(node)
Definition: plannodes.h:173
#define outerPlan(node)
Definition: plannodes.h:174
RecursiveUnionState * rustate
Definition: execnodes.h:1530
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
static TupleTableSlot * ExecWorkTableScan(PlanState *pstate)
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:423
ExprState * qual
Definition: execnodes.h:865
void ExecReScanWorkTableScan ( WorkTableScanState node)

Definition at line 207 of file nodeWorktablescan.c.

References ExecClearTuple(), ExecScanReScan(), ScanState::ps, PlanState::ps_ResultTupleSlot, WorkTableScanState::rustate, WorkTableScanState::ss, tuplestore_rescan(), and RecursiveUnionState::working_table.

Referenced by ExecReScan().

208 {
210 
211  ExecScanReScan(&node->ss);
212 
213  /* No need (or way) to rescan if ExecWorkTableScan not called yet */
214  if (node->rustate)
216 }
void tuplestore_rescan(Tuplestorestate *state)
Definition: tuplestore.c:1233
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
PlanState ps
Definition: execnodes.h:1098
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
Tuplestorestate * working_table
Definition: execnodes.h:1045
RecursiveUnionState * rustate
Definition: execnodes.h:1530
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
static TupleTableSlot* ExecWorkTableScan ( PlanState pstate)
static

Definition at line 81 of file nodeWorktablescan.c.

References Assert, castNode, DatumGetPointer, ExecAssignScanProjectionInfo(), ExecAssignScanType(), ExecGetResultType(), ExecScan(), NULL, PlanState::plan, RecursiveUnionState::ps, ScanState::ps, WorkTableScanState::rustate, WorkTableScanState::ss, PlanState::state, WorkTableScanNext(), WorkTableScanRecheck(), and WorkTableScan::wtParam.

Referenced by ExecInitWorkTableScan().

82 {
84 
85  /*
86  * On the first call, find the ancestor RecursiveUnion's state via the
87  * Param slot reserved for it. (We can't do this during node init because
88  * there are corner cases where we'll get the init call before the
89  * RecursiveUnion does.)
90  */
91  if (node->rustate == NULL)
92  {
93  WorkTableScan *plan = (WorkTableScan *) node->ss.ps.plan;
94  EState *estate = node->ss.ps.state;
95  ParamExecData *param;
96 
97  param = &(estate->es_param_exec_vals[plan->wtParam]);
98  Assert(param->execPlan == NULL);
99  Assert(!param->isnull);
100  node->rustate = castNode(RecursiveUnionState, DatumGetPointer(param->value));
101  Assert(node->rustate);
102 
103  /*
104  * The scan tuple type (ie, the rowtype we expect to find in the work
105  * table) is the same as the result rowtype of the ancestor
106  * RecursiveUnion node. Note this depends on the assumption that
107  * RecursiveUnion doesn't allow projection.
108  */
109  ExecAssignScanType(&node->ss,
110  ExecGetResultType(&node->rustate->ps));
111 
112  /*
113  * Now we can initialize the projection info. This must be completed
114  * before we can call ExecScan().
115  */
117  }
118 
119  return ExecScan(&node->ss,
122 }
static TupleTableSlot * WorkTableScanNext(WorkTableScanState *node)
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
EState * state
Definition: execnodes.h:849
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:408
PlanState ps
Definition: execnodes.h:1098
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:409
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
RecursiveUnionState * rustate
Definition: execnodes.h:1530
Plan * plan
Definition: execnodes.h:847
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
static bool WorkTableScanRecheck(WorkTableScanState *node, TupleTableSlot *slot)
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:474
#define DatumGetPointer(X)
Definition: postgres.h:555
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:545
static TupleTableSlot * WorkTableScanNext ( WorkTableScanState node)
static

Definition at line 30 of file nodeWorktablescan.c.

References Assert, EState::es_direction, ScanState::ps, WorkTableScanState::rustate, ScanDirectionIsForward, WorkTableScanState::ss, ScanState::ss_ScanTupleSlot, PlanState::state, tuplestore_gettupleslot(), and RecursiveUnionState::working_table.

Referenced by ExecWorkTableScan().

31 {
32  TupleTableSlot *slot;
33  Tuplestorestate *tuplestorestate;
34 
35  /*
36  * get information from the estate and scan state
37  *
38  * Note: we intentionally do not support backward scan. Although it would
39  * take only a couple more lines here, it would force nodeRecursiveunion.c
40  * to create the tuplestore with backward scan enabled, which has a
41  * performance cost. In practice backward scan is never useful for a
42  * worktable plan node, since it cannot appear high enough in the plan
43  * tree of a scrollable cursor to be exposed to a backward-scan
44  * requirement. So it's not worth expending effort to support it.
45  *
46  * Note: we are also assuming that this node is the only reader of the
47  * worktable. Therefore, we don't need a private read pointer for the
48  * tuplestore, nor do we need to tell tuplestore_gettupleslot to copy.
49  */
51 
52  tuplestorestate = node->rustate->working_table;
53 
54  /*
55  * Get the next tuple from tuplestore. Return NULL if no more tuples.
56  */
57  slot = node->ss.ss_ScanTupleSlot;
58  (void) tuplestore_gettupleslot(tuplestorestate, true, false, slot);
59  return slot;
60 }
#define ScanDirectionIsForward(direction)
Definition: sdir.h:55
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1101
EState * state
Definition: execnodes.h:849
ScanDirection es_direction
Definition: execnodes.h:428
PlanState ps
Definition: execnodes.h:1098
Tuplestorestate * working_table
Definition: execnodes.h:1045
RecursiveUnionState * rustate
Definition: execnodes.h:1530
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
Definition: tuplestore.c:1078
#define Assert(condition)
Definition: c.h:676
static bool WorkTableScanRecheck ( WorkTableScanState node,
TupleTableSlot slot 
)
static

Definition at line 66 of file nodeWorktablescan.c.

Referenced by ExecWorkTableScan().

67 {
68  /* nothing to check */
69  return true;
70 }