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 247 of file nodeResult.c.

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

Referenced by ExecEndNode().

248 {
249  /*
250  * Free the exprcontext
251  */
252  ExecFreeExprContext(&node->ps);
253 
254  /*
255  * clean out the tuple table
256  */
258 
259  /*
260  * shut down subplans
261  */
263 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:624
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:684
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1076
#define outerPlanState(node)
Definition: execnodes.h:1089
PlanState ps
Definition: execnodes.h:1125
ResultState* ExecInitResult ( Result node,
EState estate,
int  eflags 
)

Definition at line 179 of file nodeResult.c.

References Assert, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecAssignResultTypeFromTL(), ExecInitExpr(), ExecInitNode(), 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, PlanState::state, Plan::targetlist, and PlanState::targetlist.

Referenced by ExecInitNode().

180 {
181  ResultState *resstate;
182 
183  /* check for unsupported flags */
184  Assert(!(eflags & (EXEC_FLAG_MARK | EXEC_FLAG_BACKWARD)) ||
185  outerPlan(node) != NULL);
186 
187  /*
188  * create state structure
189  */
190  resstate = makeNode(ResultState);
191  resstate->ps.plan = (Plan *) node;
192  resstate->ps.state = estate;
193 
194  resstate->rs_done = false;
195  resstate->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
196 
197  /*
198  * Miscellaneous initialization
199  *
200  * create expression context for node
201  */
202  ExecAssignExprContext(estate, &resstate->ps);
203 
204  /*
205  * tuple table initialization
206  */
207  ExecInitResultTupleSlot(estate, &resstate->ps);
208 
209  /*
210  * initialize child expressions
211  */
212  resstate->ps.targetlist = (List *)
213  ExecInitExpr((Expr *) node->plan.targetlist,
214  (PlanState *) resstate);
215  resstate->ps.qual = (List *)
216  ExecInitExpr((Expr *) node->plan.qual,
217  (PlanState *) resstate);
218  resstate->resconstantqual = ExecInitExpr((Expr *) node->resconstantqual,
219  (PlanState *) resstate);
220 
221  /*
222  * initialize child nodes
223  */
224  outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate, eflags);
225 
226  /*
227  * we don't use inner plan
228  */
229  Assert(innerPlan(node) == NULL);
230 
231  /*
232  * initialize tuple type and projection info
233  */
234  ExecAssignResultTypeFromTL(&resstate->ps);
235  ExecAssignProjectionInfo(&resstate->ps, NULL);
236 
237  return resstate;
238 }
Plan plan
Definition: plannodes.h:175
List * qual
Definition: plannodes.h:130
bool rs_done
Definition: execnodes.h:1127
List * qual
Definition: execnodes.h:1061
List * targetlist
Definition: execnodes.h:1060
EState * state
Definition: execnodes.h:1048
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:429
Node * resconstantqual
Definition: plannodes.h:176
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execQual.c:4266
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
ExprState * resconstantqual
Definition: execnodes.h:1126
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:1089
#define innerPlan(node)
Definition: plannodes.h:158
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:656
#define outerPlan(node)
Definition: plannodes.h:159
bool rs_checkqual
Definition: execnodes.h:1128
Plan * plan
Definition: execnodes.h:1046
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:670
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:407
List * targetlist
Definition: plannodes.h:129
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:137
Definition: pg_list.h:45
PlanState ps
Definition: execnodes.h:1125
void ExecReScanResult ( ResultState node)

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

267 {
268  node->rs_done = false;
269  node->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
270 
271  /*
272  * If chgParam of subnode is not null then plan will be re-scanned by
273  * first ExecProcNode.
274  */
275  if (node->ps.lefttree &&
276  node->ps.lefttree->chgParam == NULL)
277  ExecReScan(node->ps.lefttree);
278 }
bool rs_done
Definition: execnodes.h:1127
void ExecReScan(PlanState *node)
Definition: execAmi.c:73
struct PlanState * lefttree
Definition: execnodes.h:1062
ExprState * resconstantqual
Definition: execnodes.h:1126
Bitmapset * chgParam
Definition: execnodes.h:1071
bool rs_checkqual
Definition: execnodes.h:1128
#define NULL
Definition: c.h:226
PlanState ps
Definition: execnodes.h:1125
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((List *) node->resconstantqual,
81  econtext,
82  false);
83 
84  node->rs_checkqual = false;
85  if (!qualResult)
86  {
87  node->rs_done = true;
88  return NULL;
89  }
90  }
91 
92  /*
93  * Reset per-tuple memory context to free any expression evaluation
94  * storage allocated in the previous tuple cycle.
95  */
96  ResetExprContext(econtext);
97 
98  /*
99  * if rs_done is true then it means that we were asked to return a
100  * constant tuple and we already did the last time ExecResult() was
101  * called, OR that we failed the constant qual check. Either way, now we
102  * are through.
103  */
104  while (!node->rs_done)
105  {
106  outerPlan = outerPlanState(node);
107 
108  if (outerPlan != NULL)
109  {
110  /*
111  * retrieve tuples from the outer plan until there are no more.
112  */
113  outerTupleSlot = ExecProcNode(outerPlan);
114 
115  if (TupIsNull(outerTupleSlot))
116  return NULL;
117 
118  /*
119  * prepare to compute projection expressions, which will expect to
120  * access the input tuples as varno OUTER.
121  */
122  econtext->ecxt_outertuple = outerTupleSlot;
123  }
124  else
125  {
126  /*
127  * if we don't have an outer plan, then we are just generating the
128  * results from a constant target list. Do it only once.
129  */
130  node->rs_done = true;
131  }
132 
133  /* form the result tuple using ExecProject(), and return it */
134  return ExecProject(node->ps.ps_ProjInfo);
135  }
136 
137  return NULL;
138 }
bool rs_done
Definition: execnodes.h:1127
TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
Definition: execQual.c:5214
TupleTableSlot * ExecProcNode(PlanState *node)
Definition: execProcnode.c:380
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1078
ExprContext * ps_ExprContext
Definition: execnodes.h:1077
ExprState * resconstantqual
Definition: execnodes.h:1126
#define outerPlanState(node)
Definition: execnodes.h:1089
bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull)
Definition: execQual.c:5055
#define TupIsNull(slot)
Definition: tuptable.h:138
#define outerPlan(node)
Definition: plannodes.h:159
bool rs_checkqual
Definition: execnodes.h:1128
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:130
#define NULL
Definition: c.h:226
Definition: pg_list.h:45
#define ResetExprContext(econtext)
Definition: executor.h:332
PlanState ps
Definition: execnodes.h:1125
void ExecResultMarkPos ( ResultState node)

Definition at line 145 of file nodeResult.c.

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

Referenced by ExecMarkPos().

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

Definition at line 160 of file nodeResult.c.

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

Referenced by ExecRestrPos().

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