PostgreSQL Source Code  git master
execProcnode.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * execProcnode.c
4  * contains dispatch functions which call the appropriate "initialize",
5  * "get a tuple", and "cleanup" routines for the given node type.
6  * If the node has children, then it will presumably call ExecInitNode,
7  * ExecProcNode, or ExecEndNode on its subnodes and do the appropriate
8  * processing.
9  *
10  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
11  * Portions Copyright (c) 1994, Regents of the University of California
12  *
13  *
14  * IDENTIFICATION
15  * src/backend/executor/execProcnode.c
16  *
17  *-------------------------------------------------------------------------
18  */
19 /*
20  * NOTES
21  * This used to be three files. It is now all combined into
22  * one file so that it is easier to keep the dispatch routines
23  * in sync when new nodes are added.
24  *
25  * EXAMPLE
26  * Suppose we want the age of the manager of the shoe department and
27  * the number of employees in that department. So we have the query:
28  *
29  * select DEPT.no_emps, EMP.age
30  * from DEPT, EMP
31  * where EMP.name = DEPT.mgr and
32  * DEPT.name = "shoe"
33  *
34  * Suppose the planner gives us the following plan:
35  *
36  * Nest Loop (DEPT.mgr = EMP.name)
37  * / \
38  * / \
39  * Seq Scan Seq Scan
40  * DEPT EMP
41  * (name = "shoe")
42  *
43  * ExecutorStart() is called first.
44  * It calls InitPlan() which calls ExecInitNode() on
45  * the root of the plan -- the nest loop node.
46  *
47  * * ExecInitNode() notices that it is looking at a nest loop and
48  * as the code below demonstrates, it calls ExecInitNestLoop().
49  * Eventually this calls ExecInitNode() on the right and left subplans
50  * and so forth until the entire plan is initialized. The result
51  * of ExecInitNode() is a plan state tree built with the same structure
52  * as the underlying plan tree.
53  *
54  * * Then when ExecutorRun() is called, it calls ExecutePlan() which calls
55  * ExecProcNode() repeatedly on the top node of the plan state tree.
56  * Each time this happens, ExecProcNode() will end up calling
57  * ExecNestLoop(), which calls ExecProcNode() on its subplans.
58  * Each of these subplans is a sequential scan so ExecSeqScan() is
59  * called. The slots returned by ExecSeqScan() may contain
60  * tuples which contain the attributes ExecNestLoop() uses to
61  * form the tuples it returns.
62  *
63  * * Eventually ExecSeqScan() stops returning tuples and the nest
64  * loop join ends. Lastly, ExecutorEnd() calls ExecEndNode() which
65  * calls ExecEndNestLoop() which in turn calls ExecEndNode() on
66  * its subplans which result in ExecEndSeqScan().
67  *
68  * This should show how the executor works by having
69  * ExecInitNode(), ExecProcNode() and ExecEndNode() dispatch
70  * their work to the appropriate node support routines which may
71  * in turn call these routines themselves on their subplans.
72  */
73 #include "postgres.h"
74 
75 #include "executor/executor.h"
76 #include "executor/nodeAgg.h"
77 #include "executor/nodeAppend.h"
78 #include "executor/nodeBitmapAnd.h"
81 #include "executor/nodeBitmapOr.h"
82 #include "executor/nodeCtescan.h"
83 #include "executor/nodeCustom.h"
86 #include "executor/nodeGather.h"
88 #include "executor/nodeGroup.h"
89 #include "executor/nodeHash.h"
90 #include "executor/nodeHashjoin.h"
92 #include "executor/nodeIndexscan.h"
93 #include "executor/nodeLimit.h"
94 #include "executor/nodeLockRows.h"
95 #include "executor/nodeMaterial.h"
97 #include "executor/nodeMergejoin.h"
100 #include "executor/nodeNestloop.h"
101 #include "executor/nodeProjectSet.h"
103 #include "executor/nodeResult.h"
104 #include "executor/nodeSamplescan.h"
105 #include "executor/nodeSeqscan.h"
106 #include "executor/nodeSetOp.h"
107 #include "executor/nodeSort.h"
108 #include "executor/nodeSubplan.h"
111 #include "executor/nodeTidscan.h"
112 #include "executor/nodeUnique.h"
113 #include "executor/nodeValuesscan.h"
114 #include "executor/nodeWindowAgg.h"
116 #include "miscadmin.h"
117 #include "nodes/nodeFuncs.h"
118 
121 
122 
123 /* ------------------------------------------------------------------------
124  * ExecInitNode
125  *
126  * Recursively initializes all the nodes in the plan tree rooted
127  * at 'node'.
128  *
129  * Inputs:
130  * 'node' is the current node of the plan produced by the query planner
131  * 'estate' is the shared execution state for the plan tree
132  * 'eflags' is a bitwise OR of flag bits described in executor.h
133  *
134  * Returns a PlanState node corresponding to the given Plan node.
135  * ------------------------------------------------------------------------
136  */
137 PlanState *
138 ExecInitNode(Plan *node, EState *estate, int eflags)
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 }
396 
397 
398 /*
399  * If a node wants to change its ExecProcNode function after ExecInitNode()
400  * has finished, it should do so with this function. That way any wrapper
401  * functions can be reinstalled, without the node having to know how that
402  * works.
403  */
404 void
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 }
416 
417 
418 /*
419  * ExecProcNode wrapper that performs some one-time checks, before calling
420  * the relevant node method (possibly via an instrumentation wrapper).
421  */
422 static TupleTableSlot *
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 }
446 
447 
448 /*
449  * ExecProcNode wrapper that performs instrumentation calls. By keeping
450  * this a separate function, we avoid overhead in the normal case where
451  * no instrumentation is wanted.
452  */
453 static TupleTableSlot *
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 }
466 
467 
468 /* ----------------------------------------------------------------
469  * MultiExecProcNode
470  *
471  * Execute a node that doesn't return individual tuples
472  * (it might return a hashtable, bitmap, etc). Caller should
473  * check it got back the expected kind of Node.
474  *
475  * This has essentially the same responsibilities as ExecProcNode,
476  * but it does not do InstrStartNode/InstrStopNode (mainly because
477  * it can't tell how many returned tuples to count). Each per-node
478  * function must provide its own instrumentation support.
479  * ----------------------------------------------------------------
480  */
481 Node *
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 }
523 
524 
525 /* ----------------------------------------------------------------
526  * ExecEndNode
527  *
528  * Recursively cleans up all the nodes in the plan rooted
529  * at 'node'.
530  *
531  * After this operation, the query plan will not be able to be
532  * processed any further. This should be called only after
533  * the query plan has been fully executed.
534  * ----------------------------------------------------------------
535  */
536 void
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 }
733 
734 /*
735  * ExecShutdownNode
736  *
737  * Give execution nodes a chance to stop asynchronous resource consumption
738  * and release any resources still held.
739  */
740 bool
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 }
793 
794 /*
795  * ExecSetTupleBound
796  *
797  * Set a tuple bound for a planstate node. This lets child plan nodes
798  * optimize based on the knowledge that the maximum number of tuples that
799  * their parent will demand is limited. The tuple bound for a node may
800  * only be changed between scans (i.e., after node initialization or just
801  * before an ExecReScan call).
802  *
803  * Any negative tuples_needed value means "no limit", which should be the
804  * default assumption when this is not called at all for a particular node.
805  *
806  * Note: if this is called repeatedly on a plan tree, the exact same set
807  * of nodes must be updated with the new limit each time; be careful that
808  * only unchanging conditions are tested here.
809  */
810 void
811 ExecSetTupleBound(int64 tuples_needed, PlanState *child_node)
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 }
void ExecEndGroup(GroupState *node)
Definition: nodeGroup.c:227
MergeJoinState * ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)
void ExecEndSetOp(SetOpState *node)
Definition: nodeSetOp.c:583
#define NIL
Definition: pg_list.h:65
NamedTuplestoreScanState * ExecInitNamedTuplestoreScan(NamedTuplestoreScan *node, EState *estate, int eflags)
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:76
void ExecEndFunctionScan(FunctionScanState *node)
Definition: nodes.h:78
SortState * ExecInitSort(Sort *node, EState *estate, int eflags)
Definition: nodeSort.c:166
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
void ExecEndNestLoop(NestLoopState *node)
Definition: nodeNestloop.c:362
BitmapHeapScanState * ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
Definition: nodes.h:80
Instrumentation * instrument
Definition: execnodes.h:949
void ExecEndIndexScan(IndexScanState *node)
void ExecEndLimit(LimitState *node)
Definition: nodeLimit.c:402
GroupState * ExecInitGroup(Group *node, EState *estate, int eflags)
Definition: nodeGroup.c:162
MergeAppendState * ExecInitMergeAppend(MergeAppend *node, EState *estate, int eflags)
void ExecEndUnique(UniqueState *node)
Definition: nodeUnique.c:169
void ExecEndGatherMerge(GatherMergeState *node)
bool ExecShutdownNode(PlanState *node)
Definition: execProcnode.c:741
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:537
void ExecShutdownCustomScan(CustomScanState *node)
Definition: nodeCustom.c:222
GatherMergeState * ExecInitGatherMerge(GatherMerge *node, EState *estate, int eflags)
bool bounded
Definition: execnodes.h:1989
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
void ExecEndWorkTableScan(WorkTableScanState *node)
int64 bound
Definition: execnodes.h:1990
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
void ExecEndLockRows(LockRowsState *node)
Definition: nodeLockRows.c:382
void ExecEndNamedTuplestoreScan(NamedTuplestoreScanState *node)
void ExecEndBitmapAnd(BitmapAndState *node)
CteScanState * ExecInitCteScan(CteScan *node, EState *estate, int eflags)
Definition: nodeCtescan.c:175
Definition: nodes.h:525
void ExecShutdownHashJoin(HashJoinState *node)
Definition: nodes.h:49
Instrumentation * InstrAlloc(int n, int instrument_options)
Definition: instrument.c:30
Node * MultiExecHash(HashState *node)
Definition: nodeHash.c:104
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
void ExecEndRecursiveUnion(RecursiveUnionState *node)
void ExecShutdownHash(HashState *node)
Definition: nodeHash.c:2630
TupleTableSlot *(* ExecProcNodeMtd)(struct PlanState *pstate)
Definition: execnodes.h:926
void ExecSetTupleBound(int64 tuples_needed, PlanState *child_node)
Definition: execProcnode.c:811
SubPlanState * ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
Definition: nodeSubplan.c:789
void ExecEndSubqueryScan(SubqueryScanState *node)
void ExecEndHashJoin(HashJoinState *node)
Definition: nodeHashjoin.c:746
PlanState ps
Definition: execnodes.h:1326
void ExecEndTableFuncScan(TableFuncScanState *node)
void ExecEndResult(ResultState *node)
Definition: nodeResult.c:241
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)
void ExecEndAppend(AppendState *node)
Definition: nodeAppend.c:294
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:63
CustomScanState * ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
Definition: nodeCustom.c:29
void ExecEndForeignScan(ForeignScanState *node)
void ExecEndSort(SortState *node)
Definition: nodeSort.c:234
BitmapIndexScanState * ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags)
Definition: nodes.h:77
#define outerPlanState(node)
Definition: execnodes.h:1033
SampleScanState * ExecInitSampleScan(SampleScan *node, EState *estate, int eflags)
void ExecEndBitmapIndexScan(BitmapIndexScanState *node)
void check_stack_depth(void)
Definition: postgres.c:3302
void ExecEndValuesScan(ValuesScanState *node)
PlanState ** mergeplans
Definition: execnodes.h:1246
void ExecEndMergeJoin(MergeJoinState *node)
Node * MultiExecBitmapIndexScan(BitmapIndexScanState *node)
#define TupIsNull(slot)
Definition: tuptable.h:292
void ExecEndSeqScan(SeqScanState *node)
Definition: nodeSeqscan.c:184
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
int es_instrument
Definition: execnodes.h:556
void ExecEndIndexOnlyScan(IndexOnlyScanState *node)
PlanState * subplan
Definition: execnodes.h:1633
FunctionScanState * ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
void ExecEndTidScan(TidScanState *node)
Definition: nodeTidscan.c:469
Bitmapset * chgParam
Definition: execnodes.h:971
List * lappend(List *list, void *datum)
Definition: list.c:322
Node * MultiExecBitmapAnd(BitmapAndState *node)
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
Node * MultiExecBitmapOr(BitmapOrState *node)
Definition: nodeBitmapOr.c:111
void ExecShutdownGather(GatherState *node)
Definition: nodeGather.c:419
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
void ExecEndCteScan(CteScanState *node)
Definition: nodeCtescan.c:288
ExecProcNodeMtd ExecProcNodeReal
Definition: execnodes.h:946
void ExecEndCustomScan(CustomScanState *node)
Definition: nodeCustom.c:119
UniqueState * ExecInitUnique(Unique *node, EState *estate, int eflags)
Definition: nodeUnique.c:115
void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
Definition: execProcnode.c:405
void ExecEndBitmapOr(BitmapOrState *node)
Definition: nodeBitmapOr.c:196
Definition: nodes.h:83
void ExecEndSampleScan(SampleScanState *node)
void ExecShutdownGatherMerge(GatherMergeState *node)
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
void ExecEndWindowAgg(WindowAggState *node)
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
void ExecEndMergeAppend(MergeAppendState *node)
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
ExprState * qual
Definition: execnodes.h:960
Definition: nodes.h:84
TableFuncScanState * ExecInitTableFuncScan(TableFuncScan *node, EState *estate, int eflags)
ForeignScanState * ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
Node * MultiExecProcNode(PlanState *node)
Definition: execProcnode.c:482
PlanState ** appendplans
Definition: execnodes.h:1216
SeqScanState * ExecInitSeqScan(SeqScan *node, EState *estate, int eflags)
Definition: nodeSeqscan.c:123
static TupleTableSlot * ExecProcNodeInstr(PlanState *node)
Definition: execProcnode.c:454
List * initPlan
Definition: plannodes.h:146
Definition: nodes.h:81
#define elog(elevel,...)
Definition: elog.h:228
LimitState * ExecInitLimit(Limit *node, EState *estate, int eflags)
Definition: nodeLimit.c:336
int i
void ExecEndHash(HashState *node)
Definition: nodeHash.c:405
void ExecShutdownForeignScan(ForeignScanState *node)
void ExecEndProjectSet(ProjectSetState *node)
void ExecEndMaterial(MaterialState *node)
Definition: nodeMaterial.c:240
WorkTableScanState * ExecInitWorkTableScan(WorkTableScan *node, EState *estate, int eflags)
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
Definition: plannodes.h:806
void ExecEndBitmapHeapScan(BitmapHeapScanState *node)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:138
Definition: pg_list.h:50
bool planstate_tree_walker(PlanState *planstate, bool(*walker)(), void *context)
Definition: nodeFuncs.c:3867
void ExecEndAgg(AggState *node)
Definition: nodeAgg.c:3387
void ExecEndModifyTable(ModifyTableState *node)
MaterialState * ExecInitMaterial(Material *node, EState *estate, int eflags)
Definition: nodeMaterial.c:164
static TupleTableSlot * ExecProcNodeFirst(PlanState *node)
Definition: execProcnode.c:423
void ExecEndGather(GatherState *node)
Definition: nodeGather.c:249
int64 tuples_needed
Definition: execnodes.h:2194
Definition: nodes.h:86