PostgreSQL Source Code  git master
execProcnode.c File Reference
#include "postgres.h"
#include "executor/executor.h"
#include "executor/nodeAgg.h"
#include "executor/nodeAppend.h"
#include "executor/nodeBitmapAnd.h"
#include "executor/nodeBitmapHeapscan.h"
#include "executor/nodeBitmapIndexscan.h"
#include "executor/nodeBitmapOr.h"
#include "executor/nodeCtescan.h"
#include "executor/nodeCustom.h"
#include "executor/nodeForeignscan.h"
#include "executor/nodeFunctionscan.h"
#include "executor/nodeGather.h"
#include "executor/nodeGatherMerge.h"
#include "executor/nodeGroup.h"
#include "executor/nodeHash.h"
#include "executor/nodeHashjoin.h"
#include "executor/nodeIndexonlyscan.h"
#include "executor/nodeIndexscan.h"
#include "executor/nodeLimit.h"
#include "executor/nodeLockRows.h"
#include "executor/nodeMaterial.h"
#include "executor/nodeMergeAppend.h"
#include "executor/nodeMergejoin.h"
#include "executor/nodeModifyTable.h"
#include "executor/nodeNamedtuplestorescan.h"
#include "executor/nodeNestloop.h"
#include "executor/nodeProjectSet.h"
#include "executor/nodeRecursiveunion.h"
#include "executor/nodeResult.h"
#include "executor/nodeSamplescan.h"
#include "executor/nodeSeqscan.h"
#include "executor/nodeSetOp.h"
#include "executor/nodeSort.h"
#include "executor/nodeSubplan.h"
#include "executor/nodeSubqueryscan.h"
#include "executor/nodeTableFuncscan.h"
#include "executor/nodeTidscan.h"
#include "executor/nodeUnique.h"
#include "executor/nodeValuesscan.h"
#include "executor/nodeWindowAgg.h"
#include "executor/nodeWorktablescan.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
Include dependency graph for execProcnode.c:

Go to the source code of this file.

Functions

static TupleTableSlotExecProcNodeFirst (PlanState *node)
 
static TupleTableSlotExecProcNodeInstr (PlanState *node)
 
PlanStateExecInitNode (Plan *node, EState *estate, int eflags)
 
void ExecSetExecProcNode (PlanState *node, ExecProcNodeMtd function)
 
NodeMultiExecProcNode (PlanState *node)
 
void ExecEndNode (PlanState *node)
 
bool ExecShutdownNode (PlanState *node)
 
void ExecSetTupleBound (int64 tuples_needed, PlanState *child_node)
 

Function Documentation

◆ ExecEndNode()

void ExecEndNode ( PlanState node)

Definition at line 537 of file execProcnode.c.

References bms_free(), check_stack_depth(), PlanState::chgParam, elog, ERROR, ExecEndAgg(), ExecEndAppend(), ExecEndBitmapAnd(), ExecEndBitmapHeapScan(), ExecEndBitmapIndexScan(), ExecEndBitmapOr(), ExecEndCteScan(), ExecEndCustomScan(), ExecEndForeignScan(), ExecEndFunctionScan(), ExecEndGather(), ExecEndGatherMerge(), ExecEndGroup(), ExecEndHash(), ExecEndHashJoin(), ExecEndIndexOnlyScan(), ExecEndIndexScan(), ExecEndLimit(), ExecEndLockRows(), ExecEndMaterial(), ExecEndMergeAppend(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNamedTuplestoreScan(), ExecEndNestLoop(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSampleScan(), ExecEndSeqScan(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndTableFuncScan(), ExecEndTidScan(), ExecEndUnique(), ExecEndValuesScan(), ExecEndWindowAgg(), ExecEndWorkTableScan(), nodeTag, T_AggState, T_AppendState, T_BitmapAndState, T_BitmapHeapScanState, T_BitmapIndexScanState, T_BitmapOrState, T_CteScanState, T_CustomScanState, T_ForeignScanState, T_FunctionScanState, T_GatherMergeState, T_GatherState, T_GroupState, T_HashJoinState, T_HashState, T_IndexOnlyScanState, T_IndexScanState, T_LimitState, T_LockRowsState, T_MaterialState, T_MergeAppendState, T_MergeJoinState, T_ModifyTableState, T_NamedTuplestoreScanState, T_NestLoopState, T_ProjectSetState, T_RecursiveUnionState, T_ResultState, T_SampleScanState, T_SeqScanState, T_SetOpState, T_SortState, T_SubqueryScanState, T_TableFuncScanState, T_TidScanState, T_UniqueState, T_ValuesScanState, T_WindowAggState, and T_WorkTableScanState.

Referenced by EvalPlanQualEnd(), ExecEndAgg(), ExecEndAppend(), ExecEndBitmapAnd(), ExecEndBitmapHeapScan(), ExecEndBitmapOr(), ExecEndForeignScan(), ExecEndGather(), ExecEndGatherMerge(), ExecEndGroup(), ExecEndHash(), ExecEndHashJoin(), ExecEndLimit(), ExecEndLockRows(), ExecEndMaterial(), ExecEndMergeAppend(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNestLoop(), ExecEndPlan(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndUnique(), and ExecEndWindowAgg().

538 {
539  /*
540  * do nothing when we get to the end of a leaf on tree.
541  */
542  if (node == NULL)
543  return;
544 
545  /*
546  * Make sure there's enough stack available. Need to check here, in
547  * addition to ExecProcNode() (via ExecProcNodeFirst()), because it's not
548  * guaranteed that ExecProcNode() is reached for all nodes.
549  */
551 
552  if (node->chgParam != NULL)
553  {
554  bms_free(node->chgParam);
555  node->chgParam = NULL;
556  }
557 
558  switch (nodeTag(node))
559  {
560  /*
561  * control nodes
562  */
563  case T_ResultState:
564  ExecEndResult((ResultState *) node);
565  break;
566 
567  case T_ProjectSetState:
569  break;
570 
571  case T_ModifyTableState:
573  break;
574 
575  case T_AppendState:
576  ExecEndAppend((AppendState *) node);
577  break;
578 
579  case T_MergeAppendState:
581  break;
582 
585  break;
586 
587  case T_BitmapAndState:
589  break;
590 
591  case T_BitmapOrState:
592  ExecEndBitmapOr((BitmapOrState *) node);
593  break;
594 
595  /*
596  * scan nodes
597  */
598  case T_SeqScanState:
599  ExecEndSeqScan((SeqScanState *) node);
600  break;
601 
602  case T_SampleScanState:
604  break;
605 
606  case T_GatherState:
607  ExecEndGather((GatherState *) node);
608  break;
609 
610  case T_GatherMergeState:
612  break;
613 
614  case T_IndexScanState:
616  break;
617 
620  break;
621 
624  break;
625 
628  break;
629 
630  case T_TidScanState:
631  ExecEndTidScan((TidScanState *) node);
632  break;
633 
634  case T_SubqueryScanState:
636  break;
637 
638  case T_FunctionScanState:
640  break;
641 
644  break;
645 
646  case T_ValuesScanState:
648  break;
649 
650  case T_CteScanState:
651  ExecEndCteScan((CteScanState *) node);
652  break;
653 
656  break;
657 
660  break;
661 
662  case T_ForeignScanState:
664  break;
665 
666  case T_CustomScanState:
668  break;
669 
670  /*
671  * join nodes
672  */
673  case T_NestLoopState:
674  ExecEndNestLoop((NestLoopState *) node);
675  break;
676 
677  case T_MergeJoinState:
679  break;
680 
681  case T_HashJoinState:
682  ExecEndHashJoin((HashJoinState *) node);
683  break;
684 
685  /*
686  * materialization nodes
687  */
688  case T_MaterialState:
689  ExecEndMaterial((MaterialState *) node);
690  break;
691 
692  case T_SortState:
693  ExecEndSort((SortState *) node);
694  break;
695 
696  case T_GroupState:
697  ExecEndGroup((GroupState *) node);
698  break;
699 
700  case T_AggState:
701  ExecEndAgg((AggState *) node);
702  break;
703 
704  case T_WindowAggState:
706  break;
707 
708  case T_UniqueState:
709  ExecEndUnique((UniqueState *) node);
710  break;
711 
712  case T_HashState:
713  ExecEndHash((HashState *) node);
714  break;
715 
716  case T_SetOpState:
717  ExecEndSetOp((SetOpState *) node);
718  break;
719 
720  case T_LockRowsState:
721  ExecEndLockRows((LockRowsState *) node);
722  break;
723 
724  case T_LimitState:
725  ExecEndLimit((LimitState *) node);
726  break;
727 
728  default:
729  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
730  break;
731  }
732 }
void ExecEndGroup(GroupState *node)
Definition: nodeGroup.c:227
void ExecEndSetOp(SetOpState *node)
Definition: nodeSetOp.c:583
void ExecEndFunctionScan(FunctionScanState *node)
void ExecEndNestLoop(NestLoopState *node)
Definition: nodeNestloop.c:362
void ExecEndIndexScan(IndexScanState *node)
void ExecEndLimit(LimitState *node)
Definition: nodeLimit.c:402
void ExecEndUnique(UniqueState *node)
Definition: nodeUnique.c:169
void ExecEndGatherMerge(GatherMergeState *node)
void ExecEndWorkTableScan(WorkTableScanState *node)
void ExecEndLockRows(LockRowsState *node)
Definition: nodeLockRows.c:382
void ExecEndNamedTuplestoreScan(NamedTuplestoreScanState *node)
void ExecEndBitmapAnd(BitmapAndState *node)
void ExecEndRecursiveUnion(RecursiveUnionState *node)
void ExecEndSubqueryScan(SubqueryScanState *node)
void ExecEndHashJoin(HashJoinState *node)
Definition: nodeHashjoin.c:746
void ExecEndTableFuncScan(TableFuncScanState *node)
void ExecEndResult(ResultState *node)
Definition: nodeResult.c:241
#define ERROR
Definition: elog.h:43
void ExecEndAppend(AppendState *node)
Definition: nodeAppend.c:314
void ExecEndForeignScan(ForeignScanState *node)
void ExecEndSort(SortState *node)
Definition: nodeSort.c:234
void ExecEndBitmapIndexScan(BitmapIndexScanState *node)
void check_stack_depth(void)
Definition: postgres.c:3284
void ExecEndValuesScan(ValuesScanState *node)
void ExecEndMergeJoin(MergeJoinState *node)
void ExecEndSeqScan(SeqScanState *node)
Definition: nodeSeqscan.c:184
void ExecEndIndexOnlyScan(IndexOnlyScanState *node)
void ExecEndTidScan(TidScanState *node)
Definition: nodeTidscan.c:469
Bitmapset * chgParam
Definition: execnodes.h:971
void ExecEndCteScan(CteScanState *node)
Definition: nodeCtescan.c:288
void ExecEndCustomScan(CustomScanState *node)
Definition: nodeCustom.c:119
void ExecEndBitmapOr(BitmapOrState *node)
Definition: nodeBitmapOr.c:196
void ExecEndSampleScan(SampleScanState *node)
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
void ExecEndWindowAgg(WindowAggState *node)
void ExecEndMergeAppend(MergeAppendState *node)
#define nodeTag(nodeptr)
Definition: nodes.h:530
#define elog(elevel,...)
Definition: elog.h:228
void ExecEndHash(HashState *node)
Definition: nodeHash.c:405
void ExecEndProjectSet(ProjectSetState *node)
void ExecEndMaterial(MaterialState *node)
Definition: nodeMaterial.c:240
void ExecEndBitmapHeapScan(BitmapHeapScanState *node)
void ExecEndAgg(AggState *node)
Definition: nodeAgg.c:3387
void ExecEndModifyTable(ModifyTableState *node)
void ExecEndGather(GatherState *node)
Definition: nodeGather.c:249

◆ ExecInitNode()

PlanState* ExecInitNode ( Plan node,
EState estate,
int  eflags 
)

Definition at line 138 of file execProcnode.c.

References Assert, check_stack_depth(), elog, ERROR, EState::es_instrument, ExecInitAgg(), ExecInitAppend(), ExecInitBitmapAnd(), ExecInitBitmapHeapScan(), ExecInitBitmapIndexScan(), ExecInitBitmapOr(), ExecInitCteScan(), ExecInitCustomScan(), ExecInitForeignScan(), ExecInitFunctionScan(), ExecInitGather(), ExecInitGatherMerge(), ExecInitGroup(), ExecInitHash(), ExecInitHashJoin(), ExecInitIndexOnlyScan(), ExecInitIndexScan(), ExecInitLimit(), ExecInitLockRows(), ExecInitMaterial(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNamedTuplestoreScan(), ExecInitNestLoop(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitResult(), ExecInitSampleScan(), ExecInitSeqScan(), ExecInitSetOp(), ExecInitSort(), ExecInitSubPlan(), ExecInitSubqueryScan(), ExecInitTableFuncScan(), ExecInitTidScan(), ExecInitUnique(), ExecInitValuesScan(), ExecInitWindowAgg(), ExecInitWorkTableScan(), PlanState::ExecProcNode, ExecSetExecProcNode(), Plan::initPlan, PlanState::initPlan, InstrAlloc(), PlanState::instrument, IsA, lappend(), lfirst, NIL, nodeTag, T_Agg, T_Append, T_BitmapAnd, T_BitmapHeapScan, T_BitmapIndexScan, T_BitmapOr, T_CteScan, T_CustomScan, T_ForeignScan, T_FunctionScan, T_Gather, T_GatherMerge, T_Group, T_Hash, T_HashJoin, T_IndexOnlyScan, T_IndexScan, T_Limit, T_LockRows, T_Material, T_MergeAppend, T_MergeJoin, T_ModifyTable, T_NamedTuplestoreScan, T_NestLoop, T_ProjectSet, T_RecursiveUnion, T_Result, T_SampleScan, T_SeqScan, T_SetOp, T_Sort, T_SubqueryScan, T_TableFuncScan, T_TidScan, T_Unique, T_ValuesScan, T_WindowAgg, and T_WorkTableScan.

Referenced by EvalPlanQualStart(), ExecInitAgg(), ExecInitAppend(), ExecInitBitmapAnd(), ExecInitBitmapHeapScan(), ExecInitBitmapOr(), ExecInitForeignScan(), ExecInitGather(), ExecInitGatherMerge(), ExecInitGroup(), ExecInitHash(), ExecInitHashJoin(), ExecInitLimit(), ExecInitLockRows(), ExecInitMaterial(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNestLoop(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitResult(), ExecInitSetOp(), ExecInitSort(), ExecInitSubqueryScan(), ExecInitUnique(), ExecInitWindowAgg(), and InitPlan().

139 {
140  PlanState *result;
141  List *subps;
142  ListCell *l;
143 
144  /*
145  * do nothing when we get to the end of a leaf on tree.
146  */
147  if (node == NULL)
148  return NULL;
149 
150  /*
151  * Make sure there's enough stack available. Need to check here, in
152  * addition to ExecProcNode() (via ExecProcNodeFirst()), to ensure the
153  * stack isn't overrun while initializing the node tree.
154  */
156 
157  switch (nodeTag(node))
158  {
159  /*
160  * control nodes
161  */
162  case T_Result:
163  result = (PlanState *) ExecInitResult((Result *) node,
164  estate, eflags);
165  break;
166 
167  case T_ProjectSet:
168  result = (PlanState *) ExecInitProjectSet((ProjectSet *) node,
169  estate, eflags);
170  break;
171 
172  case T_ModifyTable:
173  result = (PlanState *) ExecInitModifyTable((ModifyTable *) node,
174  estate, eflags);
175  break;
176 
177  case T_Append:
178  result = (PlanState *) ExecInitAppend((Append *) node,
179  estate, eflags);
180  break;
181 
182  case T_MergeAppend:
183  result = (PlanState *) ExecInitMergeAppend((MergeAppend *) node,
184  estate, eflags);
185  break;
186 
187  case T_RecursiveUnion:
188  result = (PlanState *) ExecInitRecursiveUnion((RecursiveUnion *) node,
189  estate, eflags);
190  break;
191 
192  case T_BitmapAnd:
193  result = (PlanState *) ExecInitBitmapAnd((BitmapAnd *) node,
194  estate, eflags);
195  break;
196 
197  case T_BitmapOr:
198  result = (PlanState *) ExecInitBitmapOr((BitmapOr *) node,
199  estate, eflags);
200  break;
201 
202  /*
203  * scan nodes
204  */
205  case T_SeqScan:
206  result = (PlanState *) ExecInitSeqScan((SeqScan *) node,
207  estate, eflags);
208  break;
209 
210  case T_SampleScan:
211  result = (PlanState *) ExecInitSampleScan((SampleScan *) node,
212  estate, eflags);
213  break;
214 
215  case T_IndexScan:
216  result = (PlanState *) ExecInitIndexScan((IndexScan *) node,
217  estate, eflags);
218  break;
219 
220  case T_IndexOnlyScan:
221  result = (PlanState *) ExecInitIndexOnlyScan((IndexOnlyScan *) node,
222  estate, eflags);
223  break;
224 
225  case T_BitmapIndexScan:
226  result = (PlanState *) ExecInitBitmapIndexScan((BitmapIndexScan *) node,
227  estate, eflags);
228  break;
229 
230  case T_BitmapHeapScan:
231  result = (PlanState *) ExecInitBitmapHeapScan((BitmapHeapScan *) node,
232  estate, eflags);
233  break;
234 
235  case T_TidScan:
236  result = (PlanState *) ExecInitTidScan((TidScan *) node,
237  estate, eflags);
238  break;
239 
240  case T_SubqueryScan:
241  result = (PlanState *) ExecInitSubqueryScan((SubqueryScan *) node,
242  estate, eflags);
243  break;
244 
245  case T_FunctionScan:
246  result = (PlanState *) ExecInitFunctionScan((FunctionScan *) node,
247  estate, eflags);
248  break;
249 
250  case T_TableFuncScan:
251  result = (PlanState *) ExecInitTableFuncScan((TableFuncScan *) node,
252  estate, eflags);
253  break;
254 
255  case T_ValuesScan:
256  result = (PlanState *) ExecInitValuesScan((ValuesScan *) node,
257  estate, eflags);
258  break;
259 
260  case T_CteScan:
261  result = (PlanState *) ExecInitCteScan((CteScan *) node,
262  estate, eflags);
263  break;
264 
267  estate, eflags);
268  break;
269 
270  case T_WorkTableScan:
271  result = (PlanState *) ExecInitWorkTableScan((WorkTableScan *) node,
272  estate, eflags);
273  break;
274 
275  case T_ForeignScan:
276  result = (PlanState *) ExecInitForeignScan((ForeignScan *) node,
277  estate, eflags);
278  break;
279 
280  case T_CustomScan:
281  result = (PlanState *) ExecInitCustomScan((CustomScan *) node,
282  estate, eflags);
283  break;
284 
285  /*
286  * join nodes
287  */
288  case T_NestLoop:
289  result = (PlanState *) ExecInitNestLoop((NestLoop *) node,
290  estate, eflags);
291  break;
292 
293  case T_MergeJoin:
294  result = (PlanState *) ExecInitMergeJoin((MergeJoin *) node,
295  estate, eflags);
296  break;
297 
298  case T_HashJoin:
299  result = (PlanState *) ExecInitHashJoin((HashJoin *) node,
300  estate, eflags);
301  break;
302 
303  /*
304  * materialization nodes
305  */
306  case T_Material:
307  result = (PlanState *) ExecInitMaterial((Material *) node,
308  estate, eflags);
309  break;
310 
311  case T_Sort:
312  result = (PlanState *) ExecInitSort((Sort *) node,
313  estate, eflags);
314  break;
315 
316  case T_Group:
317  result = (PlanState *) ExecInitGroup((Group *) node,
318  estate, eflags);
319  break;
320 
321  case T_Agg:
322  result = (PlanState *) ExecInitAgg((Agg *) node,
323  estate, eflags);
324  break;
325 
326  case T_WindowAgg:
327  result = (PlanState *) ExecInitWindowAgg((WindowAgg *) node,
328  estate, eflags);
329  break;
330 
331  case T_Unique:
332  result = (PlanState *) ExecInitUnique((Unique *) node,
333  estate, eflags);
334  break;
335 
336  case T_Gather:
337  result = (PlanState *) ExecInitGather((Gather *) node,
338  estate, eflags);
339  break;
340 
341  case T_GatherMerge:
342  result = (PlanState *) ExecInitGatherMerge((GatherMerge *) node,
343  estate, eflags);
344  break;
345 
346  case T_Hash:
347  result = (PlanState *) ExecInitHash((Hash *) node,
348  estate, eflags);
349  break;
350 
351  case T_SetOp:
352  result = (PlanState *) ExecInitSetOp((SetOp *) node,
353  estate, eflags);
354  break;
355 
356  case T_LockRows:
357  result = (PlanState *) ExecInitLockRows((LockRows *) node,
358  estate, eflags);
359  break;
360 
361  case T_Limit:
362  result = (PlanState *) ExecInitLimit((Limit *) node,
363  estate, eflags);
364  break;
365 
366  default:
367  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
368  result = NULL; /* keep compiler quiet */
369  break;
370  }
371 
372  ExecSetExecProcNode(result, result->ExecProcNode);
373 
374  /*
375  * Initialize any initPlans present in this node. The planner put them in
376  * a separate list for us.
377  */
378  subps = NIL;
379  foreach(l, node->initPlan)
380  {
381  SubPlan *subplan = (SubPlan *) lfirst(l);
382  SubPlanState *sstate;
383 
384  Assert(IsA(subplan, SubPlan));
385  sstate = ExecInitSubPlan(subplan, result);
386  subps = lappend(subps, sstate);
387  }
388  result->initPlan = subps;
389 
390  /* Set up instrumentation for this node if requested */
391  if (estate->es_instrument)
392  result->instrument = InstrAlloc(1, estate->es_instrument);
393 
394  return result;
395 }
MergeJoinState * ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)
#define NIL
Definition: pg_list.h:65
NamedTuplestoreScanState * ExecInitNamedTuplestoreScan(NamedTuplestoreScan *node, EState *estate, int eflags)
Definition: nodes.h:78
SortState * ExecInitSort(Sort *node, EState *estate, int eflags)
Definition: nodeSort.c:166
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
BitmapHeapScanState * ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
Definition: nodes.h:80
Instrumentation * instrument
Definition: execnodes.h:949
GroupState * ExecInitGroup(Group *node, EState *estate, int eflags)
Definition: nodeGroup.c:162
MergeAppendState * ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
GatherMergeState * ExecInitGatherMerge(GatherMerge *node, EState *estate, int eflags)
List * initPlan
Definition: execnodes.h:964
RecursiveUnionState * ExecInitRecursiveUnion(RecursiveUnion *node, EState *estate, int eflags)
NestLoopState * ExecInitNestLoop(NestLoop *node, EState *estate, int eflags)
Definition: nodeNestloop.c:263
LockRowsState * ExecInitLockRows(LockRows *node, EState *estate, int eflags)
Definition: nodeLockRows.c:288
HashState * ExecInitHash(Hash *node, EState *estate, int eflags)
Definition: nodeHash.c:352
CteScanState * ExecInitCteScan(CteScan *node, EState *estate, int eflags)
Definition: nodeCtescan.c:175
Definition: nodes.h:49
Instrumentation * InstrAlloc(int n, int instrument_options)
Definition: instrument.c:30
AppendState * ExecInitAppend(Append *node, EState *estate, int eflags)
Definition: nodeAppend.c:101
Definition: nodes.h:76
GatherState * ExecInitGather(Gather *node, EState *estate, int eflags)
Definition: nodeGather.c:58
SubPlanState * ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
Definition: nodeSubplan.c:789
AggState * ExecInitAgg(Agg *node, EState *estate, int eflags)
Definition: nodeAgg.c:2096
TidScanState * ExecInitTidScan(TidScan *node, EState *estate, int eflags)
Definition: nodeTidscan.c:499
Definition: nodes.h:46
#define ERROR
Definition: elog.h:43
IndexScanState * ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
CustomScanState * ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
Definition: nodeCustom.c:29
BitmapIndexScanState * ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags)
Definition: nodes.h:77
SampleScanState * ExecInitSampleScan(SampleScan *node, EState *estate, int eflags)
void check_stack_depth(void)
Definition: postgres.c:3284
ModifyTableState * ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
SubqueryScanState * ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
SetOpState * ExecInitSetOp(SetOp *node, EState *estate, int eflags)
Definition: nodeSetOp.c:481
FunctionScanState * ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
List * lappend(List *list, void *datum)
Definition: list.c:322
ValuesScanState * ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
BitmapAndState * ExecInitBitmapAnd(BitmapAnd *node, EState *estate, int eflags)
Definition: nodeBitmapAnd.c:55
HashJoinState * ExecInitHashJoin(HashJoin *node, EState *estate, int eflags)
Definition: nodeHashjoin.c:598
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
UniqueState * ExecInitUnique(Unique *node, EState *estate, int eflags)
Definition: nodeUnique.c:115
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:405
Definition: nodes.h:83
BitmapOrState * ExecInitBitmapOr(BitmapOr *node, EState *estate, int eflags)
Definition: nodeBitmapOr.c:56
IndexOnlyScanState * ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags)
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
ResultState * ExecInitResult(Result *node, EState *estate, int eflags)
Definition: nodeResult.c:181
WindowAggState * ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
ProjectSetState * ExecInitProjectSet(ProjectSet *node, EState *estate, int eflags)
#define nodeTag(nodeptr)
Definition: nodes.h:530
Definition: nodes.h:84
TableFuncScanState * ExecInitTableFuncScan(TableFuncScan *node, EState *estate, int eflags)
ForeignScanState * ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
SeqScanState * ExecInitSeqScan(SeqScan *node, EState *estate, int eflags)
Definition: nodeSeqscan.c:123
List * initPlan
Definition: plannodes.h:144
Definition: nodes.h:81
#define elog(elevel,...)
Definition: elog.h:228
LimitState * ExecInitLimit(Limit *node, EState *estate, int eflags)
Definition: nodeLimit.c:336
WorkTableScanState * ExecInitWorkTableScan(WorkTableScan *node, EState *estate, int eflags)
Definition: plannodes.h:802
Definition: pg_list.h:50
MaterialState * ExecInitMaterial(Material *node, EState *estate, int eflags)
Definition: nodeMaterial.c:164
Definition: nodes.h:86

◆ ExecProcNodeFirst()

static TupleTableSlot * ExecProcNodeFirst ( PlanState node)
static

Definition at line 423 of file execProcnode.c.

References check_stack_depth(), PlanState::ExecProcNode, ExecProcNodeInstr(), PlanState::ExecProcNodeReal, and PlanState::instrument.

Referenced by ExecSetExecProcNode().

424 {
425  /*
426  * Perform stack depth check during the first execution of the node. We
427  * only do so the first time round because it turns out to not be cheap on
428  * some common architectures (eg. x86). This relies on the assumption
429  * that ExecProcNode calls for a given plan node will always be made at
430  * roughly the same stack depth.
431  */
433 
434  /*
435  * If instrumentation is required, change the wrapper to one that just
436  * does instrumentation. Otherwise we can dispense with all wrappers and
437  * have ExecProcNode() directly call the relevant function from now on.
438  */
439  if (node->instrument)
441  else
442  node->ExecProcNode = node->ExecProcNodeReal;
443 
444  return node->ExecProcNode(node);
445 }
Instrumentation * instrument
Definition: execnodes.h:949
void check_stack_depth(void)
Definition: postgres.c:3284
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
ExecProcNodeMtd ExecProcNodeReal
Definition: execnodes.h:946
static TupleTableSlot * ExecProcNodeInstr(PlanState *node)
Definition: execProcnode.c:454

◆ ExecProcNodeInstr()

static TupleTableSlot * ExecProcNodeInstr ( PlanState node)
static

Definition at line 454 of file execProcnode.c.

References PlanState::ExecProcNodeReal, InstrStartNode(), InstrStopNode(), PlanState::instrument, and TupIsNull.

Referenced by ExecProcNodeFirst().

455 {
456  TupleTableSlot *result;
457 
458  InstrStartNode(node->instrument);
459 
460  result = node->ExecProcNodeReal(node);
461 
462  InstrStopNode(node->instrument, TupIsNull(result) ? 0.0 : 1.0);
463 
464  return result;
465 }
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:76
Instrumentation * instrument
Definition: execnodes.h:949
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:63
#define TupIsNull(slot)
Definition: tuptable.h:292
ExecProcNodeMtd ExecProcNodeReal
Definition: execnodes.h:946

◆ ExecSetExecProcNode()

void ExecSetExecProcNode ( PlanState node,
ExecProcNodeMtd  function 
)

Definition at line 405 of file execProcnode.c.

References PlanState::ExecProcNode, ExecProcNodeFirst(), and PlanState::ExecProcNodeReal.

Referenced by ExecHashJoinInitializeDSM(), ExecHashJoinInitializeWorker(), and ExecInitNode().

406 {
407  /*
408  * Add a wrapper around the ExecProcNode callback that checks stack depth
409  * during the first execution and maybe adds an instrumentation wrapper.
410  * When the callback is changed after execution has already begun that
411  * means we'll superfluously execute ExecProcNodeFirst, but that seems ok.
412  */
413  node->ExecProcNodeReal = function;
415 }
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
ExecProcNodeMtd ExecProcNodeReal
Definition: execnodes.h:946
static TupleTableSlot * ExecProcNodeFirst(PlanState *node)
Definition: execProcnode.c:423

◆ ExecSetTupleBound()

void ExecSetTupleBound ( int64  tuples_needed,
PlanState child_node 
)

Definition at line 811 of file execProcnode.c.

References AppendState::appendplans, AppendState::as_nplans, SortState::bound, SortState::bounded, ExecSetTupleBound(), i, IsA, MergeAppendState::mergeplans, MergeAppendState::ms_nplans, outerPlanState, ScanState::ps, PlanState::qual, SubqueryScanState::ss, SubqueryScanState::subplan, GatherState::tuples_needed, and GatherMergeState::tuples_needed.

Referenced by ExecSetTupleBound(), ParallelQueryMain(), and recompute_limits().

812 {
813  /*
814  * Since this function recurses, in principle we should check stack depth
815  * here. In practice, it's probably pointless since the earlier node
816  * initialization tree traversal would surely have consumed more stack.
817  */
818 
819  if (IsA(child_node, SortState))
820  {
821  /*
822  * If it is a Sort node, notify it that it can use bounded sort.
823  *
824  * Note: it is the responsibility of nodeSort.c to react properly to
825  * changes of these parameters. If we ever redesign this, it'd be a
826  * good idea to integrate this signaling with the parameter-change
827  * mechanism.
828  */
829  SortState *sortState = (SortState *) child_node;
830 
831  if (tuples_needed < 0)
832  {
833  /* make sure flag gets reset if needed upon rescan */
834  sortState->bounded = false;
835  }
836  else
837  {
838  sortState->bounded = true;
839  sortState->bound = tuples_needed;
840  }
841  }
842  else if (IsA(child_node, AppendState))
843  {
844  /*
845  * If it is an Append, we can apply the bound to any nodes that are
846  * children of the Append, since the Append surely need read no more
847  * than that many tuples from any one input.
848  */
849  AppendState *aState = (AppendState *) child_node;
850  int i;
851 
852  for (i = 0; i < aState->as_nplans; i++)
853  ExecSetTupleBound(tuples_needed, aState->appendplans[i]);
854  }
855  else if (IsA(child_node, MergeAppendState))
856  {
857  /*
858  * If it is a MergeAppend, we can apply the bound to any nodes that
859  * are children of the MergeAppend, since the MergeAppend surely need
860  * read no more than that many tuples from any one input.
861  */
862  MergeAppendState *maState = (MergeAppendState *) child_node;
863  int i;
864 
865  for (i = 0; i < maState->ms_nplans; i++)
866  ExecSetTupleBound(tuples_needed, maState->mergeplans[i]);
867  }
868  else if (IsA(child_node, ResultState))
869  {
870  /*
871  * Similarly, for a projecting Result, we can apply the bound to its
872  * child node.
873  *
874  * If Result supported qual checking, we'd have to punt on seeing a
875  * qual. Note that having a resconstantqual is not a showstopper: if
876  * that condition succeeds it affects nothing, while if it fails, no
877  * rows will be demanded from the Result child anyway.
878  */
879  if (outerPlanState(child_node))
880  ExecSetTupleBound(tuples_needed, outerPlanState(child_node));
881  }
882  else if (IsA(child_node, SubqueryScanState))
883  {
884  /*
885  * We can also descend through SubqueryScan, but only if it has no
886  * qual (otherwise it might discard rows).
887  */
888  SubqueryScanState *subqueryState = (SubqueryScanState *) child_node;
889 
890  if (subqueryState->ss.ps.qual == NULL)
891  ExecSetTupleBound(tuples_needed, subqueryState->subplan);
892  }
893  else if (IsA(child_node, GatherState))
894  {
895  /*
896  * A Gather node can propagate the bound to its workers. As with
897  * MergeAppend, no one worker could possibly need to return more
898  * tuples than the Gather itself needs to.
899  *
900  * Note: As with Sort, the Gather node is responsible for reacting
901  * properly to changes to this parameter.
902  */
903  GatherState *gstate = (GatherState *) child_node;
904 
905  gstate->tuples_needed = tuples_needed;
906 
907  /* Also pass down the bound to our own copy of the child plan */
908  ExecSetTupleBound(tuples_needed, outerPlanState(child_node));
909  }
910  else if (IsA(child_node, GatherMergeState))
911  {
912  /* Same comments as for Gather */
913  GatherMergeState *gstate = (GatherMergeState *) child_node;
914 
915  gstate->tuples_needed = tuples_needed;
916 
917  ExecSetTupleBound(tuples_needed, outerPlanState(child_node));
918  }
919 
920  /*
921  * In principle we could descend through any plan node type that is
922  * certain not to discard or combine input rows; but on seeing a node that
923  * can do that, we can't propagate the bound any further. For the moment
924  * it's unclear that any other cases are worth checking here.
925  */
926 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
bool bounded
Definition: execnodes.h:1993
int64 bound
Definition: execnodes.h:1994
void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node)
Definition: execProcnode.c:811
PlanState ps
Definition: execnodes.h:1330
#define outerPlanState(node)
Definition: execnodes.h:1033
PlanState ** mergeplans
Definition: execnodes.h:1249
PlanState * subplan
Definition: execnodes.h:1637
ExprState * qual
Definition: execnodes.h:960
PlanState ** appendplans
Definition: execnodes.h:1217
int i
int64 tuples_needed
Definition: execnodes.h:2198

◆ ExecShutdownNode()

bool ExecShutdownNode ( PlanState node)

Definition at line 741 of file execProcnode.c.

References check_stack_depth(), ExecShutdownCustomScan(), ExecShutdownForeignScan(), ExecShutdownGather(), ExecShutdownGatherMerge(), ExecShutdownHash(), ExecShutdownHashJoin(), ExecShutdownNode(), InstrStartNode(), InstrStopNode(), PlanState::instrument, nodeTag, planstate_tree_walker(), Instrumentation::running, T_CustomScanState, T_ForeignScanState, T_GatherMergeState, T_GatherState, T_HashJoinState, and T_HashState.

Referenced by ExecShutdownNode(), and ExecutePlan().

742 {
743  if (node == NULL)
744  return false;
745 
747 
749 
750  /*
751  * Treat the node as running while we shut it down, but only if it's run
752  * at least once already. We don't expect much CPU consumption during
753  * node shutdown, but in the case of Gather or Gather Merge, we may shut
754  * down workers at this stage. If so, their buffer usage will get
755  * propagated into pgBufferUsage at this point, and we want to make sure
756  * that it gets associated with the Gather node. We skip this if the node
757  * has never been executed, so as to avoid incorrectly making it appear
758  * that it has.
759  */
760  if (node->instrument && node->instrument->running)
761  InstrStartNode(node->instrument);
762 
763  switch (nodeTag(node))
764  {
765  case T_GatherState:
767  break;
768  case T_ForeignScanState:
770  break;
771  case T_CustomScanState:
773  break;
774  case T_GatherMergeState:
776  break;
777  case T_HashState:
778  ExecShutdownHash((HashState *) node);
779  break;
780  case T_HashJoinState:
782  break;
783  default:
784  break;
785  }
786 
787  /* Stop the node if we started it above, reporting 0 tuples. */
788  if (node->instrument && node->instrument->running)
789  InstrStopNode(node->instrument, 0);
790 
791  return false;
792 }
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:76
Instrumentation * instrument
Definition: execnodes.h:949
bool ExecShutdownNode(PlanState *node)
Definition: execProcnode.c:741
void ExecShutdownCustomScan(CustomScanState *node)
Definition: nodeCustom.c:222
void ExecShutdownHashJoin(HashJoinState *node)
void ExecShutdownHash(HashState *node)
Definition: nodeHash.c:2630
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:63
void check_stack_depth(void)
Definition: postgres.c:3284
void ExecShutdownGather(GatherState *node)
Definition: nodeGather.c:419
void ExecShutdownGatherMerge(GatherMergeState *node)
#define nodeTag(nodeptr)
Definition: nodes.h:530
void ExecShutdownForeignScan(ForeignScanState *node)
bool planstate_tree_walker(PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3867

◆ MultiExecProcNode()

Node* MultiExecProcNode ( PlanState node)

Definition at line 482 of file execProcnode.c.

References CHECK_FOR_INTERRUPTS, check_stack_depth(), PlanState::chgParam, elog, ERROR, ExecReScan(), MultiExecBitmapAnd(), MultiExecBitmapIndexScan(), MultiExecBitmapOr(), MultiExecHash(), nodeTag, T_BitmapAndState, T_BitmapIndexScanState, T_BitmapOrState, and T_HashState.

Referenced by BitmapHeapNext(), ExecHashJoinImpl(), MultiExecBitmapAnd(), and MultiExecBitmapOr().

483 {
484  Node *result;
485 
487 
489 
490  if (node->chgParam != NULL) /* something changed */
491  ExecReScan(node); /* let ReScan handle this */
492 
493  switch (nodeTag(node))
494  {
495  /*
496  * Only node types that actually support multiexec will be listed
497  */
498 
499  case T_HashState:
500  result = MultiExecHash((HashState *) node);
501  break;
502 
505  break;
506 
507  case T_BitmapAndState:
508  result = MultiExecBitmapAnd((BitmapAndState *) node);
509  break;
510 
511  case T_BitmapOrState:
512  result = MultiExecBitmapOr((BitmapOrState *) node);
513  break;
514 
515  default:
516  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
517  result = NULL;
518  break;
519  }
520 
521  return result;
522 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
Definition: nodes.h:525
Node * MultiExecHash(HashState *node)
Definition: nodeHash.c:104
#define ERROR
Definition: elog.h:43
void check_stack_depth(void)
Definition: postgres.c:3284
Node * MultiExecBitmapIndexScan(BitmapIndexScanState *node)
Bitmapset * chgParam
Definition: execnodes.h:971
Node * MultiExecBitmapAnd(BitmapAndState *node)
Node * MultiExecBitmapOr(BitmapOrState *node)
Definition: nodeBitmapOr.c:111
#define nodeTag(nodeptr)
Definition: nodes.h:530
#define elog(elevel,...)
Definition: elog.h:228
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99