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

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:557
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:658
#define outerPlanState(node)
Definition: execnodes.h:1133
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1075
PlanState ps
Definition: execnodes.h:1240
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:433

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

Referenced by ExecEndNode().

◆ ExecInitResult()

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

Definition at line 181 of file nodeResult.c.

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);
199 
200  /*
201  * Miscellaneous initialization
202  *
203  * create expression context for node
204  */
205  ExecAssignExprContext(estate, &resstate->ps);
206 
207  /*
208  * initialize child nodes
209  */
210  outerPlanState(resstate) = ExecInitNode(outerPlan(node), estate, eflags);
211 
212  /*
213  * we don't use inner plan
214  */
215  Assert(innerPlan(node) == NULL);
216 
217  /*
218  * Initialize result slot, type and projection.
219  */
221  ExecAssignProjectionInfo(&resstate->ps, NULL);
222 
223  /*
224  * initialize child expressions
225  */
226  resstate->ps.qual =
227  ExecInitQual(node->plan.qual, (PlanState *) resstate);
228  resstate->resconstantqual =
229  ExecInitQual((List *) node->resconstantqual, (PlanState *) resstate);
230 
231  return resstate;
232 }
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:213
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1800
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:543
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
Assert(fmt[strlen(fmt) - 1] !='\n')
static TupleTableSlot * ExecResult(PlanState *pstate)
Definition: nodeResult.c:68
#define makeNode(_type_)
Definition: nodes.h:176
#define innerPlan(node)
Definition: plannodes.h:182
#define outerPlan(node)
Definition: plannodes.h:183
Definition: pg_list.h:54
ExprState * qual
Definition: execnodes.h:1058
Plan * plan
Definition: execnodes.h:1037
EState * state
Definition: execnodes.h:1039
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043
List * qual
Definition: plannodes.h:154
ExprState * resconstantqual
Definition: execnodes.h:1241
bool rs_done
Definition: execnodes.h:1242
bool rs_checkqual
Definition: execnodes.h:1243
Node * resconstantqual
Definition: plannodes.h:200
Plan plan
Definition: plannodes.h:199

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

Referenced by ExecInitNode().

◆ ExecReScanResult()

void ExecReScanResult ( ResultState node)

Definition at line 260 of file nodeResult.c.

261 {
263 
264  node->rs_done = false;
265  node->rs_checkqual = (node->resconstantqual != NULL);
266 
267  /*
268  * If chgParam of subnode is not null then plan will be re-scanned by
269  * first ExecProcNode.
270  */
271  if (outerPlan && outerPlan->chgParam == NULL)
273 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:78

References ExecReScan(), outerPlan, outerPlanState, ResultState::resconstantqual, ResultState::rs_checkqual, and ResultState::rs_done.

Referenced by ExecReScan().

◆ ExecResult()

static TupleTableSlot* ExecResult ( PlanState pstate)
static

Definition at line 68 of file nodeResult.c.

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  if (!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 }
static TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
Definition: executor.h:375
#define ResetExprContext(econtext)
Definition: executor.h:543
static bool ExecQual(ExprState *state, ExprContext *econtext)
Definition: executor.h:412
static TupleTableSlot * ExecProcNode(PlanState *node)
Definition: executor.h:268
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:253
ExprContext * ps_ExprContext
Definition: execnodes.h:1076
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1077
#define TupIsNull(slot)
Definition: tuptable.h:300

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().

◆ ExecResultMarkPos()

void ExecResultMarkPos ( ResultState node)

Definition at line 147 of file nodeResult.c.

148 {
150 
151  if (outerPlan != NULL)
153  else
154  elog(DEBUG2, "Result nodes do not support mark/restore");
155 }
#define DEBUG2
Definition: elog.h:29
void ExecMarkPos(PlanState *node)
Definition: execAmi.c:328

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

Referenced by ExecMarkPos().

◆ ExecResultRestrPos()

void ExecResultRestrPos ( ResultState node)

Definition at line 162 of file nodeResult.c.

163 {
165 
166  if (outerPlan != NULL)
168  else
169  elog(ERROR, "Result nodes do not support mark/restore");
170 }
#define ERROR
Definition: elog.h:39
void ExecRestrPos(PlanState *node)
Definition: execAmi.c:377

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

Referenced by ExecRestrPos().