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

Go to the source code of this file.

Functions

MaterialStateExecInitMaterial (Material *node, EState *estate, int eflags)
 
void ExecEndMaterial (MaterialState *node)
 
void ExecMaterialMarkPos (MaterialState *node)
 
void ExecMaterialRestrPos (MaterialState *node)
 
void ExecReScanMaterial (MaterialState *node)
 

Function Documentation

◆ ExecEndMaterial()

void ExecEndMaterial ( MaterialState node)

Definition at line 240 of file nodeMaterial.c.

References ExecClearTuple(), ExecEndNode(), outerPlanState, MaterialState::ss, ScanState::ss_ScanTupleSlot, tuplestore_end(), and MaterialState::tuplestorestate.

Referenced by ExecEndNode().

241 {
242  /*
243  * clean out the tuple table
244  */
246 
247  /*
248  * Release tuplestore resources
249  */
250  if (node->tuplestorestate != NULL)
252  node->tuplestorestate = NULL;
253 
254  /*
255  * shut down the subplan
256  */
258 }
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1973
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
ScanState ss
Definition: execnodes.h:1970
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1334
#define outerPlanState(node)
Definition: execnodes.h:1034
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:453

◆ ExecInitMaterial()

MaterialState* ExecInitMaterial ( Material node,
EState estate,
int  eflags 
)

Definition at line 164 of file nodeMaterial.c.

References MaterialState::eflags, MaterialState::eof_underlying, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecCreateScanSlotFromOuterPlan(), ExecInitNode(), ExecInitResultTupleSlotTL(), ExecMaterial(), PlanState::ExecProcNode, makeNode, outerPlan, outerPlanState, PlanState::plan, ScanState::ps, PlanState::ps_ProjInfo, MaterialState::ss, PlanState::state, TTSOpsMinimalTuple, and MaterialState::tuplestorestate.

Referenced by ExecInitNode().

165 {
166  MaterialState *matstate;
167  Plan *outerPlan;
168 
169  /*
170  * create state structure
171  */
172  matstate = makeNode(MaterialState);
173  matstate->ss.ps.plan = (Plan *) node;
174  matstate->ss.ps.state = estate;
175  matstate->ss.ps.ExecProcNode = ExecMaterial;
176 
177  /*
178  * We must have a tuplestore buffering the subplan output to do backward
179  * scan or mark/restore. We also prefer to materialize the subplan output
180  * if we might be called on to rewind and replay it many times. However,
181  * if none of these cases apply, we can skip storing the data.
182  */
183  matstate->eflags = (eflags & (EXEC_FLAG_REWIND |
185  EXEC_FLAG_MARK));
186 
187  /*
188  * Tuplestore's interpretation of the flag bits is subtly different from
189  * the general executor meaning: it doesn't think BACKWARD necessarily
190  * means "backwards all the way to start". If told to support BACKWARD we
191  * must include REWIND in the tuplestore eflags, else tuplestore_trim
192  * might throw away too much.
193  */
194  if (eflags & EXEC_FLAG_BACKWARD)
195  matstate->eflags |= EXEC_FLAG_REWIND;
196 
197  matstate->eof_underlying = false;
198  matstate->tuplestorestate = NULL;
199 
200  /*
201  * Miscellaneous initialization
202  *
203  * Materialization nodes don't need ExprContexts because they never call
204  * ExecQual or ExecProject.
205  */
206 
207  /*
208  * initialize child nodes
209  *
210  * We shield the child node from the need to support REWIND, BACKWARD, or
211  * MARK/RESTORE.
212  */
213  eflags &= ~(EXEC_FLAG_REWIND | EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK);
214 
215  outerPlan = outerPlan(node);
216  outerPlanState(matstate) = ExecInitNode(outerPlan, estate, eflags);
217 
218  /*
219  * Initialize result type and slot. No need to initialize projection info
220  * because this node doesn't do projections.
221  *
222  * material nodes only return tuples from their materialized relation.
223  */
225  matstate->ss.ps.ps_ProjInfo = NULL;
226 
227  /*
228  * initialize tuple type.
229  */
231 
232  return matstate;
233 }
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1973
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:980
ScanState ss
Definition: execnodes.h:1970
EState * state
Definition: execnodes.h:942
static TupleTableSlot * ExecMaterial(PlanState *pstate)
Definition: nodeMaterial.c:39
PlanState ps
Definition: execnodes.h:1331
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1034
bool eof_underlying
Definition: execnodes.h:1972
#define EXEC_FLAG_REWIND
Definition: executor.h:57
#define outerPlan(node)
Definition: plannodes.h:170
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:946
Plan * plan
Definition: execnodes.h:940
#define makeNode(_type_)
Definition: nodes.h:573
#define EXEC_FLAG_MARK
Definition: executor.h:59
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1764
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:646
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86

◆ ExecMaterialMarkPos()

void ExecMaterialMarkPos ( MaterialState node)

Definition at line 267 of file nodeMaterial.c.

References Assert, MaterialState::eflags, EXEC_FLAG_MARK, tuplestore_copy_read_pointer(), tuplestore_trim(), and MaterialState::tuplestorestate.

Referenced by ExecMarkPos().

268 {
269  Assert(node->eflags & EXEC_FLAG_MARK);
270 
271  /*
272  * if we haven't materialized yet, just return.
273  */
274  if (!node->tuplestorestate)
275  return;
276 
277  /*
278  * copy the active read pointer to the mark.
279  */
281 
282  /*
283  * since we may have advanced the mark, try to truncate the tuplestore.
284  */
286 }
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1973
void tuplestore_trim(Tuplestorestate *state)
Definition: tuplestore.c:1360
void tuplestore_copy_read_pointer(Tuplestorestate *state, int srcptr, int destptr)
Definition: tuplestore.c:1268
#define Assert(condition)
Definition: c.h:732
#define EXEC_FLAG_MARK
Definition: executor.h:59

◆ ExecMaterialRestrPos()

void ExecMaterialRestrPos ( MaterialState node)

Definition at line 295 of file nodeMaterial.c.

References Assert, MaterialState::eflags, EXEC_FLAG_MARK, tuplestore_copy_read_pointer(), and MaterialState::tuplestorestate.

Referenced by ExecRestrPos().

296 {
297  Assert(node->eflags & EXEC_FLAG_MARK);
298 
299  /*
300  * if we haven't materialized yet, just return.
301  */
302  if (!node->tuplestorestate)
303  return;
304 
305  /*
306  * copy the mark to the active read pointer.
307  */
309 }
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1973
void tuplestore_copy_read_pointer(Tuplestorestate *state, int srcptr, int destptr)
Definition: tuplestore.c:1268
#define Assert(condition)
Definition: c.h:732
#define EXEC_FLAG_MARK
Definition: executor.h:59

◆ ExecReScanMaterial()

void ExecReScanMaterial ( MaterialState node)

Definition at line 318 of file nodeMaterial.c.

References PlanState::chgParam, MaterialState::eflags, MaterialState::eof_underlying, EXEC_FLAG_REWIND, ExecClearTuple(), ExecReScan(), outerPlan, outerPlanState, ScanState::ps, PlanState::ps_ResultTupleSlot, MaterialState::ss, tuplestore_end(), tuplestore_rescan(), and MaterialState::tuplestorestate.

Referenced by ExecReScan().

319 {
321 
323 
324  if (node->eflags != 0)
325  {
326  /*
327  * If we haven't materialized yet, just return. If outerplan's
328  * chgParam is not NULL then it will be re-scanned by ExecProcNode,
329  * else no reason to re-scan it at all.
330  */
331  if (!node->tuplestorestate)
332  return;
333 
334  /*
335  * If subnode is to be rescanned then we forget previous stored
336  * results; we have to re-read the subplan and re-store. Also, if we
337  * told tuplestore it needn't support rescan, we lose and must
338  * re-read. (This last should not happen in common cases; else our
339  * caller lied by not passing EXEC_FLAG_REWIND to us.)
340  *
341  * Otherwise we can just rewind and rescan the stored output. The
342  * state of the subnode does not change.
343  */
344  if (outerPlan->chgParam != NULL ||
345  (node->eflags & EXEC_FLAG_REWIND) == 0)
346  {
348  node->tuplestorestate = NULL;
349  if (outerPlan->chgParam == NULL)
350  ExecReScan(outerPlan);
351  node->eof_underlying = false;
352  }
353  else
355  }
356  else
357  {
358  /* In this case we are just passing on the subquery's output */
359 
360  /*
361  * if chgParam of subnode is not null then plan will be re-scanned by
362  * first ExecProcNode.
363  */
364  if (outerPlan->chgParam == NULL)
365  ExecReScan(outerPlan);
366  node->eof_underlying = false;
367  }
368 }
void tuplestore_rescan(Tuplestorestate *state)
Definition: tuplestore.c:1233
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1973
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
ScanState ss
Definition: execnodes.h:1970
PlanState ps
Definition: execnodes.h:1331
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
#define outerPlanState(node)
Definition: execnodes.h:1034
bool eof_underlying
Definition: execnodes.h:1972
#define EXEC_FLAG_REWIND
Definition: executor.h:57
Bitmapset * chgParam
Definition: execnodes.h:972
#define outerPlan(node)
Definition: plannodes.h:170
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:453