PostgreSQL Source Code  git master
nodeProjectSet.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeProjectSet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ProjectSetStateExecInitProjectSet (ProjectSet *node, EState *estate, int eflags)
 
void ExecEndProjectSet (ProjectSetState *node)
 
void ExecReScanProjectSet (ProjectSetState *node)
 

Function Documentation

◆ ExecEndProjectSet()

void ExecEndProjectSet ( ProjectSetState node)

Definition at line 321 of file nodeProjectSet.c.

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

Referenced by ExecEndNode().

322 {
323  /*
324  * Free the exprcontext
325  */
326  ExecFreeExprContext(&node->ps);
327 
328  /*
329  * clean out the tuple table
330  */
332 
333  /*
334  * shut down subplans
335  */
337 }
PlanState ps
Definition: execnodes.h:1146
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
#define outerPlanState(node)
Definition: execnodes.h:1034

◆ ExecInitProjectSet()

ProjectSetState* ExecInitProjectSet ( ProjectSet node,
EState estate,
int  eflags 
)

Definition at line 220 of file nodeProjectSet.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ProjectSetState::argcontext, Assert, CurrentMemoryContext, ProjectSetState::elemdone, ProjectSetState::elems, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecInitExpr(), ExecInitFunctionResultSet(), ExecInitNode(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, ExecProjectSet(), TargetEntry::expr, expression_returns_set(), innerPlan, IsA, lfirst, list_length(), makeNode, ProjectSetState::nelems, NIL, outerPlan, outerPlanState, palloc(), ProjectSetState::pending_srf_tuples, ProjectSet::plan, PlanState::plan, ProjectSetState::ps, PlanState::ps_ExprContext, Plan::qual, PlanState::state, Plan::targetlist, and TTSOpsVirtual.

Referenced by ExecInitNode().

221 {
223  ListCell *lc;
224  int off;
225 
226  /* check for unsupported flags */
227  Assert(!(eflags & (EXEC_FLAG_MARK | EXEC_FLAG_BACKWARD)));
228 
229  /*
230  * create state structure
231  */
232  state = makeNode(ProjectSetState);
233  state->ps.plan = (Plan *) node;
234  state->ps.state = estate;
235  state->ps.ExecProcNode = ExecProjectSet;
236 
237  state->pending_srf_tuples = false;
238 
239  /*
240  * Miscellaneous initialization
241  *
242  * create expression context for node
243  */
244  ExecAssignExprContext(estate, &state->ps);
245 
246  /*
247  * initialize child nodes
248  */
249  outerPlanState(state) = ExecInitNode(outerPlan(node), estate, eflags);
250 
251  /*
252  * we don't use inner plan
253  */
254  Assert(innerPlan(node) == NULL);
255 
256  /*
257  * tuple table and result type initialization
258  */
260 
261  /* Create workspace for per-tlist-entry expr state & SRF-is-done state */
262  state->nelems = list_length(node->plan.targetlist);
263  state->elems = (Node **)
264  palloc(sizeof(Node *) * state->nelems);
265  state->elemdone = (ExprDoneCond *)
266  palloc(sizeof(ExprDoneCond) * state->nelems);
267 
268  /*
269  * Build expressions to evaluate targetlist. We can't use
270  * ExecBuildProjectionInfo here, since that doesn't deal with SRFs.
271  * Instead compile each expression separately, using
272  * ExecInitFunctionResultSet where applicable.
273  */
274  off = 0;
275  foreach(lc, node->plan.targetlist)
276  {
277  TargetEntry *te = (TargetEntry *) lfirst(lc);
278  Expr *expr = te->expr;
279 
280  if ((IsA(expr, FuncExpr) &&((FuncExpr *) expr)->funcretset) ||
281  (IsA(expr, OpExpr) &&((OpExpr *) expr)->opretset))
282  {
283  state->elems[off] = (Node *)
285  &state->ps);
286  }
287  else
288  {
289  Assert(!expression_returns_set((Node *) expr));
290  state->elems[off] = (Node *) ExecInitExpr(expr, &state->ps);
291  }
292 
293  off++;
294  }
295 
296  /* We don't support any qual on ProjectSet nodes */
297  Assert(node->plan.qual == NIL);
298 
299  /*
300  * Create a memory context that ExecMakeFunctionResultSet can use to
301  * evaluate function arguments in. We can't use the per-tuple context for
302  * this because it gets reset too often; but we don't want to leak
303  * evaluation results into the query-lifespan context either. We use one
304  * context for the arguments of all tSRFs, as they have roughly equivalent
305  * lifetimes.
306  */
308  "tSRF function arguments",
310 
311  return state;
312 }
#define NIL
Definition: pg_list.h:65
List * qual
Definition: plannodes.h:141
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define AllocSetContextCreate
Definition: memutils.h:170
MemoryContext argcontext
Definition: execnodes.h:1151
PlanState ps
Definition: execnodes.h:1146
ExprContext * ps_ExprContext
Definition: execnodes.h:979
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
bool expression_returns_set(Node *clause)
Definition: nodeFuncs.c:670
bool pending_srf_tuples
Definition: execnodes.h:1150
Definition: nodes.h:525
EState * state
Definition: execnodes.h:942
SetExprState * ExecInitFunctionResultSet(Expr *expr, ExprContext *econtext, PlanState *parent)
Definition: execSRF.c:426
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1034
#define innerPlan(node)
Definition: plannodes.h:169
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define outerPlan(node)
Definition: plannodes.h:170
ExprDoneCond
Definition: execnodes.h:270
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:946
static TupleTableSlot * ExecProjectSet(PlanState *pstate)
Plan * plan
Definition: execnodes.h:940
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:732
#define lfirst(lc)
Definition: pg_list.h:190
#define EXEC_FLAG_MARK
Definition: executor.h:59
Definition: regguts.h:298
Expr * expr
Definition: primnodes.h:1393
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
static int list_length(const List *l)
Definition: pg_list.h:169
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1764
List * targetlist
Definition: plannodes.h:140
void * palloc(Size size)
Definition: mcxt.c:949
ExprDoneCond * elemdone
Definition: execnodes.h:1148
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
Definition: execExpr.c:121
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
Plan plan
Definition: plannodes.h:198

◆ ExecReScanProjectSet()

void ExecReScanProjectSet ( ProjectSetState node)

Definition at line 340 of file nodeProjectSet.c.

References PlanState::chgParam, ExecReScan(), PlanState::lefttree, ProjectSetState::pending_srf_tuples, and ProjectSetState::ps.

Referenced by ExecReScan().

341 {
342  /* Forget any incompletely-evaluated SRFs */
343  node->pending_srf_tuples = false;
344 
345  /*
346  * If chgParam of subnode is not null then plan will be re-scanned by
347  * first ExecProcNode.
348  */
349  if (node->ps.lefttree->chgParam == NULL)
350  ExecReScan(node->ps.lefttree);
351 }
PlanState ps
Definition: execnodes.h:1146
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
bool pending_srf_tuples
Definition: execnodes.h:1150
struct PlanState * lefttree
Definition: execnodes.h:962
Bitmapset * chgParam
Definition: execnodes.h:972