PostgreSQL Source Code  git master
nodeResult.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeResult.h"
#include "miscadmin.h"
#include "utils/memutils.h"
Include dependency graph for nodeResult.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ ExecEndResult()

void ExecEndResult ( ResultState node)

Definition at line 246 of file nodeResult.c.

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

Referenced by ExecEndNode().

247 {
248  /*
249  * Free the exprcontext
250  */
251  ExecFreeExprContext(&node->ps);
252 
253  /*
254  * clean out the tuple table
255  */
257 
258  /*
259  * shut down subplans
260  */
262 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:603
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:883
#define outerPlanState(node)
Definition: execnodes.h:896
PlanState ps
Definition: execnodes.h:932

◆ ExecInitResult()

ResultState* ExecInitResult ( Result node,
EState estate,
int  eflags 
)

Definition at line 181 of file nodeResult.c.

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

Referenced by ExecInitNode().

182 {
183  ResultState *resstate;
184 
185  /* check for unsupported flags */
186  Assert(!(eflags & (EXEC_FLAG_MARK | EXEC_FLAG_BACKWARD)) ||
187  outerPlan(node) != NULL);
188 
189  /*
190  * create state structure
191  */
192  resstate = makeNode(ResultState);
193  resstate->ps.plan = (Plan *) node;
194  resstate->ps.state = estate;
195  resstate->ps.ExecProcNode = ExecResult;
196 
197  resstate->rs_done = false;
198  resstate->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
199 
200  /*
201  * Miscellaneous initialization
202  *
203  * create expression context for node
204  */
205  ExecAssignExprContext(estate, &resstate->ps);
206 
207  /*
208  * tuple table initialization
209  */
210  ExecInitResultTupleSlot(estate, &resstate->ps);
211 
212  /*
213  * initialize child expressions
214  */
215  resstate->ps.qual =
216  ExecInitQual(node->plan.qual, (PlanState *) resstate);
217  resstate->resconstantqual =
218  ExecInitQual((List *) node->resconstantqual, (PlanState *) resstate);
219 
220  /*
221  * initialize child nodes
222  */
223  outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate, eflags);
224 
225  /*
226  * we don't use inner plan
227  */
228  Assert(innerPlan(node) == NULL);
229 
230  /*
231  * initialize tuple type and projection info
232  */
233  ExecAssignResultTypeFromTL(&resstate->ps);
234  ExecAssignProjectionInfo(&resstate->ps, NULL);
235 
236  return resstate;
237 }
Plan plan
Definition: plannodes.h:190
List * qual
Definition: plannodes.h:145
bool rs_done
Definition: execnodes.h:934
EState * state
Definition: execnodes.h:852
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:448
Node * resconstantqual
Definition: plannodes.h:191
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
ExprState * resconstantqual
Definition: execnodes.h:933
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:896
#define innerPlan(node)
Definition: plannodes.h:173
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:495
#define outerPlan(node)
Definition: plannodes.h:174
bool rs_checkqual
Definition: execnodes.h:935
static TupleTableSlot * ExecResult(PlanState *pstate)
Definition: nodeResult.c:68
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:856
Plan * plan
Definition: execnodes.h:850
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:670
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:426
ExprState * qual
Definition: execnodes.h:868
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
Definition: pg_list.h:45
PlanState ps
Definition: execnodes.h:932

◆ ExecReScanResult()

void ExecReScanResult ( ResultState node)

Definition at line 265 of file nodeResult.c.

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

Referenced by ExecReScan().

266 {
267  node->rs_done = false;
268  node->rs_checkqual = (node->resconstantqual == NULL) ? false : true;
269 
270  /*
271  * If chgParam of subnode is not null then plan will be re-scanned by
272  * first ExecProcNode.
273  */
274  if (node->ps.lefttree &&
275  node->ps.lefttree->chgParam == NULL)
276  ExecReScan(node->ps.lefttree);
277 }
bool rs_done
Definition: execnodes.h:934
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
struct PlanState * lefttree
Definition: execnodes.h:869
ExprState * resconstantqual
Definition: execnodes.h:933
Bitmapset * chgParam
Definition: execnodes.h:878
bool rs_checkqual
Definition: execnodes.h:935
PlanState ps
Definition: execnodes.h:932

◆ ExecResult()

static TupleTableSlot* ExecResult ( PlanState pstate)
static

Definition at line 68 of file nodeResult.c.

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

Referenced by ExecInitResult().

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

◆ ExecResultMarkPos()

void ExecResultMarkPos ( ResultState node)

Definition at line 147 of file nodeResult.c.

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

Referenced by ExecMarkPos().

148 {
150 
151  if (outerPlan != NULL)
152  ExecMarkPos(outerPlan);
153  else
154  elog(DEBUG2, "Result nodes do not support mark/restore");
155 }
#define outerPlanState(node)
Definition: execnodes.h:896
#define DEBUG2
Definition: elog.h:24
#define outerPlan(node)
Definition: plannodes.h:174
void ExecMarkPos(PlanState *node)
Definition: execAmi.c:314
#define elog
Definition: elog.h:219

◆ ExecResultRestrPos()

void ExecResultRestrPos ( ResultState node)

Definition at line 162 of file nodeResult.c.

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

Referenced by ExecRestrPos().

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