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/nodeIncrementalSort.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 543 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(), ExecEndIncrementalSort(), 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_IncrementalSortState, 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(), ExecEndIncrementalSort(), ExecEndLimit(), ExecEndLockRows(), ExecEndMaterial(), ExecEndMergeAppend(), ExecEndMergeJoin(), ExecEndModifyTable(), ExecEndNestLoop(), ExecEndPlan(), ExecEndProjectSet(), ExecEndRecursiveUnion(), ExecEndResult(), ExecEndSetOp(), ExecEndSort(), ExecEndSubqueryScan(), ExecEndUnique(), and ExecEndWindowAgg().

544 {
545  /*
546  * do nothing when we get to the end of a leaf on tree.
547  */
548  if (node == NULL)
549  return;
550 
551  /*
552  * Make sure there's enough stack available. Need to check here, in
553  * addition to ExecProcNode() (via ExecProcNodeFirst()), because it's not
554  * guaranteed that ExecProcNode() is reached for all nodes.
555  */
557 
558  if (node->chgParam != NULL)
559  {
560  bms_free(node->chgParam);
561  node->chgParam = NULL;
562  }
563 
564  switch (nodeTag(node))
565  {
566  /*
567  * control nodes
568  */
569  case T_ResultState:
570  ExecEndResult((ResultState *) node);
571  break;
572 
573  case T_ProjectSetState:
575  break;
576 
577  case T_ModifyTableState:
579  break;
580 
581  case T_AppendState:
582  ExecEndAppend((AppendState *) node);
583  break;
584 
585  case T_MergeAppendState:
587  break;
588 
591  break;
592 
593  case T_BitmapAndState:
595  break;
596 
597  case T_BitmapOrState:
598  ExecEndBitmapOr((BitmapOrState *) node);
599  break;
600 
601  /*
602  * scan nodes
603  */
604  case T_SeqScanState:
605  ExecEndSeqScan((SeqScanState *) node);
606  break;
607 
608  case T_SampleScanState:
610  break;
611 
612  case T_GatherState:
613  ExecEndGather((GatherState *) node);
614  break;
615 
616  case T_GatherMergeState:
618  break;
619 
620  case T_IndexScanState:
622  break;
623 
626  break;
627 
630  break;
631 
634  break;
635 
636  case T_TidScanState:
637  ExecEndTidScan((TidScanState *) node);
638  break;
639 
640  case T_SubqueryScanState:
642  break;
643 
644  case T_FunctionScanState:
646  break;
647 
650  break;
651 
652  case T_ValuesScanState:
654  break;
655 
656  case T_CteScanState:
657  ExecEndCteScan((CteScanState *) node);
658  break;
659 
662  break;
663 
666  break;
667 
668  case T_ForeignScanState:
670  break;
671 
672  case T_CustomScanState:
674  break;
675 
676  /*
677  * join nodes
678  */
679  case T_NestLoopState:
680  ExecEndNestLoop((NestLoopState *) node);
681  break;
682 
683  case T_MergeJoinState:
685  break;
686 
687  case T_HashJoinState:
688  ExecEndHashJoin((HashJoinState *) node);
689  break;
690 
691  /*
692  * materialization nodes
693  */
694  case T_MaterialState:
695  ExecEndMaterial((MaterialState *) node);
696  break;
697 
698  case T_SortState:
699  ExecEndSort((SortState *) node);
700  break;
701 
704  break;
705 
706  case T_GroupState:
707  ExecEndGroup((GroupState *) node);
708  break;
709 
710  case T_AggState:
711  ExecEndAgg((AggState *) node);
712  break;
713 
714  case T_WindowAggState:
716  break;
717 
718  case T_UniqueState:
719  ExecEndUnique((UniqueState *) node);
720  break;
721 
722  case T_HashState:
723  ExecEndHash((HashState *) node);
724  break;
725 
726  case T_SetOpState:
727  ExecEndSetOp((SetOpState *) node);
728  break;
729 
730  case T_LockRowsState:
731  ExecEndLockRows((LockRowsState *) node);
732  break;
733 
734  case T_LimitState:
735  ExecEndLimit((LimitState *) node);
736  break;
737 
738  default:
739  elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
740  break;
741  }
742 }
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:535
void ExecEndUnique(UniqueState *node)
Definition: nodeUnique.c:169
void ExecEndGatherMerge(GatherMergeState *node)
void ExecEndIncrementalSort(IncrementalSortState *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:765
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:294
void ExecEndForeignScan(ForeignScanState *node)
void ExecEndSort(SortState *node)
Definition: nodeSort.c:235
void ExecEndBitmapIndexScan(BitmapIndexScanState *node)
void check_stack_depth(void)
Definition: postgres.c:3312
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:468
Bitmapset * chgParam
Definition: execnodes.h:977
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:534
#define elog(elevel,...)
Definition: elog.h:214
void ExecEndHash(HashState *node)
Definition: nodeHash.c:406
void ExecEndProjectSet(ProjectSetState *node)
void ExecEndMaterial(MaterialState *node)
Definition: nodeMaterial.c:240
void ExecEndBitmapHeapScan(BitmapHeapScanState *node)
void ExecEndAgg(AggState *node)
Definition: nodeAgg.c:4480
void ExecEndModifyTable(ModifyTableState *node)
void ExecEndGather(GatherState *node)
Definition: nodeGather.c:249

◆ ExecInitNode()

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

Definition at line 139 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(), ExecInitIncrementalSort(), 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_IncrementalSort, 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(), ExecInitIncrementalSort(), ExecInitLimit(), ExecInitLockRows(), ExecInitMaterial(), ExecInitMergeAppend(), ExecInitMergeJoin(), ExecInitModifyTable(), ExecInitNestLoop(), ExecInitProjectSet(), ExecInitRecursiveUnion(), ExecInitResult(), ExecInitSetOp(), ExecInitSort(), ExecInitSubqueryScan(), ExecInitUnique(), ExecInitWindowAgg(), and InitPlan().

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

◆ ExecProcNodeFirst()

static TupleTableSlot * ExecProcNodeFirst ( PlanState node)
static

Definition at line 429 of file execProcnode.c.

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

Referenced by ExecSetExecProcNode().

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

◆ ExecProcNodeInstr()

static TupleTableSlot * ExecProcNodeInstr ( PlanState node)
static

Definition at line 460 of file execProcnode.c.

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

Referenced by ExecProcNodeFirst().

461 {
462  TupleTableSlot *result;
463 
464  InstrStartNode(node->instrument);
465 
466  result = node->ExecProcNodeReal(node);
467 
468  InstrStopNode(node->instrument, TupIsNull(result) ? 0.0 : 1.0);
469 
470  return result;
471 }
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:83
Instrumentation * instrument
Definition: execnodes.h:955
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:67
#define TupIsNull(slot)
Definition: tuptable.h:292
ExecProcNodeMtd ExecProcNodeReal
Definition: execnodes.h:952

◆ ExecSetExecProcNode()

void ExecSetExecProcNode ( PlanState node,
ExecProcNodeMtd  function 
)

Definition at line 411 of file execProcnode.c.

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

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

412 {
413  /*
414  * Add a wrapper around the ExecProcNode callback that checks stack depth
415  * during the first execution and maybe adds an instrumentation wrapper.
416  * When the callback is changed after execution has already begun that
417  * means we'll superfluously execute ExecProcNodeFirst, but that seems ok.
418  */
419  node->ExecProcNodeReal = function;
421 }
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:951
ExecProcNodeMtd ExecProcNodeReal
Definition: execnodes.h:952
static TupleTableSlot * ExecProcNodeFirst(PlanState *node)
Definition: execProcnode.c:429

◆ ExecSetTupleBound()

void ExecSetTupleBound ( int64  tuples_needed,
PlanState child_node 
)

Definition at line 821 of file execProcnode.c.

References AppendState::appendplans, AppendState::as_nplans, SortState::bound, IncrementalSortState::bound, SortState::bounded, IncrementalSortState::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().

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

◆ ExecShutdownNode()

bool ExecShutdownNode ( PlanState node)

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

752 {
753  if (node == NULL)
754  return false;
755 
757 
759 
760  /*
761  * Treat the node as running while we shut it down, but only if it's run
762  * at least once already. We don't expect much CPU consumption during
763  * node shutdown, but in the case of Gather or Gather Merge, we may shut
764  * down workers at this stage. If so, their buffer usage will get
765  * propagated into pgBufferUsage at this point, and we want to make sure
766  * that it gets associated with the Gather node. We skip this if the node
767  * has never been executed, so as to avoid incorrectly making it appear
768  * that it has.
769  */
770  if (node->instrument && node->instrument->running)
771  InstrStartNode(node->instrument);
772 
773  switch (nodeTag(node))
774  {
775  case T_GatherState:
777  break;
778  case T_ForeignScanState:
780  break;
781  case T_CustomScanState:
783  break;
784  case T_GatherMergeState:
786  break;
787  case T_HashState:
788  ExecShutdownHash((HashState *) node);
789  break;
790  case T_HashJoinState:
792  break;
793  default:
794  break;
795  }
796 
797  /* Stop the node if we started it above, reporting 0 tuples. */
798  if (node->instrument && node->instrument->running)
799  InstrStopNode(node->instrument, 0);
800 
801  return false;
802 }
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:83
Instrumentation * instrument
Definition: execnodes.h:955
bool ExecShutdownNode(PlanState *node)
Definition: execProcnode.c:751
void ExecShutdownCustomScan(CustomScanState *node)
Definition: nodeCustom.c:222
void ExecShutdownHashJoin(HashJoinState *node)
void ExecShutdownHash(HashState *node)
Definition: nodeHash.c:2640
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:67
void check_stack_depth(void)
Definition: postgres.c:3312
void ExecShutdownGather(GatherState *node)
Definition: nodeGather.c:419
void ExecShutdownGatherMerge(GatherMergeState *node)
#define nodeTag(nodeptr)
Definition: nodes.h:534
void ExecShutdownForeignScan(ForeignScanState *node)
bool planstate_tree_walker(PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3882

◆ MultiExecProcNode()

Node* MultiExecProcNode ( PlanState node)

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

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