PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeResult.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeResult.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ResultStateExecInitResult (Result *node, EState *estate, int eflags)
 
TupleTableSlotExecResult (ResultState *node)
 
void ExecEndResult (ResultState *node)
 
void ExecResultMarkPos (ResultState *node)
 
void ExecResultRestrPos (ResultState *node)
 
void ExecReScanResult (ResultState *node)
 

Function Documentation

void ExecEndResult ( ResultState node)

Definition at line 241 of file nodeResult.c.

References ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), outerPlanState, ResultState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecEndNode().

242 {
243  /*
244  * Free the exprcontext
245  */
246  ExecFreeExprContext(&node->ps);
247 
248  /*
249  * clean out the tuple table
250  */
252 
253  /*
254  * shut down subplans
255  */
257 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:654
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:516
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:861
#define outerPlanState(node)
Definition: execnodes.h:874
PlanState ps
Definition: execnodes.h:910
ResultState* ExecInitResult ( Result node,
EState estate,
int  eflags 
)

Definition at line 177 of file nodeResult.c.

References Assert, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecAssignResultTypeFromTL(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlot(), innerPlan, makeNode, NULL, outerPlan, outerPlanState, Result::plan, PlanState::plan, ResultState::ps, Plan::qual, PlanState::qual, Result::resconstantqual, ResultState::resconstantqual, ResultState::rs_checkqual, ResultState::rs_done, and PlanState::state.

Referenced by ExecInitNode().

178 {
179  ResultState *resstate;
180 
181  /* check for unsupported flags */
182  Assert(!(eflags & (EXEC_FLAG_MARK | EXEC_FLAG_BACKWARD)) ||
183  outerPlan(node) != NULL);
184 
185  /*
186  * create state structure
187  */
188  resstate = makeNode(ResultState);
189  resstate->ps.plan = (Plan *) node;
190  resstate->ps.state = estate;
191 
192  resstate->rs_done = false;
193  resstate->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
194 
195  /*
196  * Miscellaneous initialization
197  *
198  * create expression context for node
199  */
200  ExecAssignExprContext(estate, &resstate->ps);
201 
202  /*
203  * tuple table initialization
204  */
205  ExecInitResultTupleSlot(estate, &resstate->ps);
206 
207  /*
208  * initialize child expressions
209  */
210  resstate->ps.qual =
211  ExecInitQual(node->plan.qual, (PlanState *) resstate);
212  resstate->resconstantqual =
213  ExecInitQual((List *) node->resconstantqual, (PlanState *) resstate);
214 
215  /*
216  * initialize child nodes
217  */
218  outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate, eflags);
219 
220  /*
221  * we don't use inner plan
222  */
223  Assert(innerPlan(node) == NULL);
224 
225  /*
226  * initialize tuple type and projection info
227  */
228  ExecAssignResultTypeFromTL(&resstate->ps);
229  ExecAssignProjectionInfo(&resstate->ps, NULL);
230 
231  return resstate;
232 }
Plan plan
Definition: plannodes.h:190
List * qual
Definition: plannodes.h:145
bool rs_done
Definition: execnodes.h:912
EState * state
Definition: execnodes.h:834
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:440
Node * resconstantqual
Definition: plannodes.h:191
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
ExprState * resconstantqual
Definition: execnodes.h:911
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:874
#define innerPlan(node)
Definition: plannodes.h:173
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:487
#define outerPlan(node)
Definition: plannodes.h:174
bool rs_checkqual
Definition: execnodes.h:913
Plan * plan
Definition: execnodes.h:832
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:418
ExprState * qual
Definition: execnodes.h:846
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:140
Definition: pg_list.h:45
PlanState ps
Definition: execnodes.h:910
void ExecReScanResult ( ResultState node)

Definition at line 260 of file nodeResult.c.

References PlanState::chgParam, ExecReScan(), PlanState::lefttree, NULL, ResultState::ps, ResultState::resconstantqual, ResultState::rs_checkqual, and ResultState::rs_done.

Referenced by ExecReScan().

261 {
262  node->rs_done = false;
263  node->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
264 
265  /*
266  * If chgParam of subnode is not null then plan will be re-scanned by
267  * first ExecProcNode.
268  */
269  if (node->ps.lefttree &&
270  node->ps.lefttree->chgParam == NULL)
271  ExecReScan(node->ps.lefttree);
272 }
bool rs_done
Definition: execnodes.h:912
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
struct PlanState * lefttree
Definition: execnodes.h:847
ExprState * resconstantqual
Definition: execnodes.h:911
Bitmapset * chgParam
Definition: execnodes.h:856
bool rs_checkqual
Definition: execnodes.h:913
#define NULL
Definition: c.h:229
PlanState ps
Definition: execnodes.h:910
TupleTableSlot* ExecResult ( ResultState node)

Definition at line 67 of file nodeResult.c.

References ExprContext::ecxt_outertuple, ExecProcNode(), ExecProject(), ExecQual(), NULL, outerPlan, outerPlanState, ResultState::ps, PlanState::ps_ExprContext, PlanState::ps_ProjInfo, ResultState::resconstantqual, ResetExprContext, ResultState::rs_checkqual, ResultState::rs_done, and TupIsNull.

Referenced by ExecProcNode().

68 {
69  TupleTableSlot *outerTupleSlot;
71  ExprContext *econtext;
72 
73  econtext = node->ps.ps_ExprContext;
74 
75  /*
76  * check constant qualifications like (2 > 1), if not already done
77  */
78  if (node->rs_checkqual)
79  {
80  bool qualResult = ExecQual(node->resconstantqual, econtext);
81 
82  node->rs_checkqual = false;
83  if (!qualResult)
84  {
85  node->rs_done = true;
86  return NULL;
87  }
88  }
89 
90  /*
91  * Reset per-tuple memory context to free any expression evaluation
92  * storage allocated in the previous tuple cycle.
93  */
94  ResetExprContext(econtext);
95 
96  /*
97  * if rs_done is true then it means that we were asked to return a
98  * constant tuple and we already did the last time ExecResult() was
99  * called, OR that we failed the constant qual check. Either way, now we
100  * are through.
101  */
102  while (!node->rs_done)
103  {
104  outerPlan = outerPlanState(node);
105 
106  if (outerPlan != NULL)
107  {
108  /*
109  * retrieve tuples from the outer plan until there are no more.
110  */
111  outerTupleSlot = ExecProcNode(outerPlan);
112 
113  if (TupIsNull(outerTupleSlot))
114  return NULL;
115 
116  /*
117  * prepare to compute projection expressions, which will expect to
118  * access the input tuples as varno OUTER.
119  */
120  econtext->ecxt_outertuple = outerTupleSlot;
121  }
122  else
123  {
124  /*
125  * if we don't have an outer plan, then we are just generating the
126  * results from a constant target list. Do it only once.
127  */
128  node->rs_done = true;
129  }
130 
131  /* form the result tuple using ExecProject(), and return it */
132  return ExecProject(node->ps.ps_ProjInfo);
133  }
134 
135  return NULL;
136 }
bool rs_done
Definition: execnodes.h:912
TupleTableSlot * ExecProcNode(PlanState *node)
Definition: execProcnode.c:398
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:863
ExprContext * ps_ExprContext
Definition: execnodes.h:862
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:347
ExprState * resconstantqual
Definition: execnodes.h:911
#define outerPlanState(node)
Definition: execnodes.h:874
#define TupIsNull(slot)
Definition: tuptable.h:138
#define outerPlan(node)
Definition: plannodes.h:174
bool rs_checkqual
Definition: execnodes.h:913
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:199
#define NULL
Definition: c.h:229
static TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
Definition: executor.h:310
#define ResetExprContext(econtext)
Definition: executor.h:451
PlanState ps
Definition: execnodes.h:910
void ExecResultMarkPos ( ResultState node)

Definition at line 143 of file nodeResult.c.

References DEBUG2, elog, ExecMarkPos(), NULL, outerPlan, and outerPlanState.

Referenced by ExecMarkPos().

144 {
146 
147  if (outerPlan != NULL)
148  ExecMarkPos(outerPlan);
149  else
150  elog(DEBUG2, "Result nodes do not support mark/restore");
151 }
#define outerPlanState(node)
Definition: execnodes.h:874
#define DEBUG2
Definition: elog.h:24
#define outerPlan(node)
Definition: plannodes.h:174
void ExecMarkPos(PlanState *node)
Definition: execAmi.c:309
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219
void ExecResultRestrPos ( ResultState node)

Definition at line 158 of file nodeResult.c.

References elog, ERROR, ExecRestrPos(), NULL, outerPlan, and outerPlanState.

Referenced by ExecRestrPos().

159 {
161 
162  if (outerPlan != NULL)
163  ExecRestrPos(outerPlan);
164  else
165  elog(ERROR, "Result nodes do not support mark/restore");
166 }
void ExecRestrPos(PlanState *node)
Definition: execAmi.c:358
#define ERROR
Definition: elog.h:43
#define outerPlanState(node)
Definition: execnodes.h:874
#define outerPlan(node)
Definition: plannodes.h:174
#define NULL
Definition: c.h:229
#define elog
Definition: elog.h:219