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 244 of file nodeMaterial.c.

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

Referenced by ExecEndNode().

245 {
246  /*
247  * clean out the tuple table
248  */
250 
251  /*
252  * Release tuplestore resources
253  */
254  if (node->tuplestorestate != NULL)
256  node->tuplestorestate = NULL;
257 
258  /*
259  * shut down the subplan
260  */
262 }
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1743
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
ScanState ss
Definition: execnodes.h:1740
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1106
#define outerPlanState(node)
Definition: execnodes.h:895
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:453

◆ ExecInitMaterial()

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

Definition at line 166 of file nodeMaterial.c.

References MaterialState::eflags, MaterialState::eof_underlying, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAssignResultTypeFromTL(), ExecAssignScanTypeFromOuterPlan(), ExecInitNode(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecMaterial(), PlanState::ExecProcNode, makeNode, outerPlan, outerPlanState, PlanState::plan, ScanState::ps, PlanState::ps_ProjInfo, MaterialState::ss, PlanState::state, and MaterialState::tuplestorestate.

Referenced by ExecInitNode().

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

◆ ExecMaterialMarkPos()

void ExecMaterialMarkPos ( MaterialState node)

Definition at line 271 of file nodeMaterial.c.

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

Referenced by ExecMarkPos().

272 {
273  Assert(node->eflags & EXEC_FLAG_MARK);
274 
275  /*
276  * if we haven't materialized yet, just return.
277  */
278  if (!node->tuplestorestate)
279  return;
280 
281  /*
282  * copy the active read pointer to the mark.
283  */
285 
286  /*
287  * since we may have advanced the mark, try to truncate the tuplestore.
288  */
290 }
Tuplestorestate * tuplestorestate
Definition: execnodes.h:1743
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:670
#define EXEC_FLAG_MARK
Definition: executor.h:61

◆ ExecMaterialRestrPos()

void ExecMaterialRestrPos ( MaterialState node)

Definition at line 299 of file nodeMaterial.c.

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

Referenced by ExecRestrPos().

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

◆ ExecReScanMaterial()

void ExecReScanMaterial ( MaterialState node)

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

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