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

Go to the source code of this file.

Functions

GatherStateExecInitGather (Gather *node, EState *estate, int eflags)
 
void ExecEndGather (GatherState *node)
 
void ExecShutdownGather (GatherState *node)
 
void ExecReScanGather (GatherState *node)
 

Function Documentation

◆ ExecEndGather()

void ExecEndGather ( GatherState node)

Definition at line 249 of file nodeGather.c.

References ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), ExecShutdownGather(), outerPlanState, GatherState::ps, and PlanState::ps_ResultTupleSlot.

Referenced by ExecEndNode().

250 {
251  ExecEndNode(outerPlanState(node)); /* let children clean up first */
252  ExecShutdownGather(node);
253  ExecFreeExprContext(&node->ps);
254  if (node->ps.ps_ResultTupleSlot)
256 }
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:537
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:977
#define outerPlanState(node)
Definition: execnodes.h:1033
PlanState ps
Definition: execnodes.h:2195
void ExecShutdownGather(GatherState *node)
Definition: nodeGather.c:419

◆ ExecInitGather()

GatherState* ExecInitGather ( Gather node,
EState estate,
int  eflags 
)

Definition at line 58 of file nodeGather.c.

References Assert, ExecAssignExprContext(), ExecConditionalAssignProjectionInfo(), ExecGather(), ExecGetResultType(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitResultTypeTL(), PlanState::ExecProcNode, GatherState::funnel_slot, GatherState::initialized, innerPlan, makeNode, GatherState::need_to_scan_locally, OUTER_VAR, PlanState::outeropsfixed, PlanState::outeropsset, outerPlan, outerPlanState, parallel_leader_participation, Gather::plan, PlanState::plan, GatherState::ps, PlanState::ps_ProjInfo, Plan::qual, PlanState::resultopsfixed, PlanState::resultopsset, Gather::single_copy, PlanState::state, TTSOpsHeapTuple, and GatherState::tuples_needed.

Referenced by ExecInitNode().

59 {
60  GatherState *gatherstate;
61  Plan *outerNode;
62  TupleDesc tupDesc;
63 
64  /* Gather node doesn't have innerPlan node. */
65  Assert(innerPlan(node) == NULL);
66 
67  /*
68  * create state structure
69  */
70  gatherstate = makeNode(GatherState);
71  gatherstate->ps.plan = (Plan *) node;
72  gatherstate->ps.state = estate;
73  gatherstate->ps.ExecProcNode = ExecGather;
74 
75  gatherstate->initialized = false;
76  gatherstate->need_to_scan_locally =
78  gatherstate->tuples_needed = -1;
79 
80  /*
81  * Miscellaneous initialization
82  *
83  * create expression context for node
84  */
85  ExecAssignExprContext(estate, &gatherstate->ps);
86 
87  /*
88  * now initialize outer plan
89  */
90  outerNode = outerPlan(node);
91  outerPlanState(gatherstate) = ExecInitNode(outerNode, estate, eflags);
92  tupDesc = ExecGetResultType(outerPlanState(gatherstate));
93 
94  /*
95  * Leader may access ExecProcNode result directly (if
96  * need_to_scan_locally), or from workers via tuple queue. So we can't
97  * trivially rely on the slot type being fixed for expressions evaluated
98  * within this node.
99  */
100  gatherstate->ps.outeropsset = true;
101  gatherstate->ps.outeropsfixed = false;
102 
103  /*
104  * Initialize result type and projection.
105  */
106  ExecInitResultTypeTL(&gatherstate->ps);
107  ExecConditionalAssignProjectionInfo(&gatherstate->ps, tupDesc, OUTER_VAR);
108 
109  /*
110  * Without projections result slot type is not trivially known, see
111  * comment above.
112  */
113  if (gatherstate->ps.ps_ProjInfo == NULL)
114  {
115  gatherstate->ps.resultopsset = true;
116  gatherstate->ps.resultopsfixed = false;
117  }
118 
119  /*
120  * Initialize funnel slot to same tuple descriptor as outer plan.
121  */
122  gatherstate->funnel_slot = ExecInitExtraTupleSlot(estate, tupDesc,
123  &TTSOpsHeapTuple);
124 
125  /*
126  * Gather doesn't support checking a qual (it's always more efficient to
127  * do it in the child node).
128  */
129  Assert(!node->plan.qual);
130 
131  return gatherstate;
132 }
List * qual
Definition: plannodes.h:141
static TupleTableSlot * ExecGather(PlanState *pstate)
Definition: nodeGather.c:142
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1801
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:979
bool need_to_scan_locally
Definition: execnodes.h:2197
EState * state
Definition: execnodes.h:941
void ExecConditionalAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc, Index varno)
Definition: execUtils.c:519
bool initialized
Definition: execnodes.h:2196
Plan plan
Definition: plannodes.h:871
bool single_copy
Definition: plannodes.h:874
#define outerPlanState(node)
Definition: execnodes.h:1033
#define innerPlan(node)
Definition: plannodes.h:169
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1725
PlanState ps
Definition: execnodes.h:2195
bool outeropsset
Definition: execnodes.h:1020
bool resultopsset
Definition: execnodes.h:1022
#define outerPlan(node)
Definition: plannodes.h:170
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:945
TupleTableSlot * funnel_slot
Definition: execnodes.h:2200
Plan * plan
Definition: execnodes.h:939
bool parallel_leader_participation
Definition: planner.c:71
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
bool outeropsfixed
Definition: execnodes.h:1016
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:454
bool resultopsfixed
Definition: execnodes.h:1018
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:84
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:138
#define OUTER_VAR
Definition: primnodes.h:158
int64 tuples_needed
Definition: execnodes.h:2198

◆ ExecReScanGather()

void ExecReScanGather ( GatherState node)

Definition at line 443 of file nodeGather.c.

References bms_add_member(), ExecReScan(), ExecShutdownGatherWorkers(), GatherState::initialized, outerPlan, outerPlanState, PlanState::plan, GatherState::ps, and Gather::rescan_param.

Referenced by ExecReScan().

444 {
445  Gather *gather = (Gather *) node->ps.plan;
447 
448  /* Make sure any existing workers are gracefully shut down */
450 
451  /* Mark node so that shared state will be rebuilt at next call */
452  node->initialized = false;
453 
454  /*
455  * Set child node's chgParam to tell it that the next scan might deliver a
456  * different set of rows within the leader process. (The overall rowset
457  * shouldn't change, but the leader process's subset might; hence nodes
458  * between here and the parallel table scan node mustn't optimize on the
459  * assumption of an unchanging rowset.)
460  */
461  if (gather->rescan_param >= 0)
462  outerPlan->chgParam = bms_add_member(outerPlan->chgParam,
463  gather->rescan_param);
464 
465  /*
466  * If chgParam of subnode is not null then plan will be re-scanned by
467  * first ExecProcNode. Note: because this does nothing if we have a
468  * rescan_param, it's currently guaranteed that parallel-aware child nodes
469  * will not see a ReScan call until after they get a ReInitializeDSM call.
470  * That ordering might not be something to rely on, though. A good rule
471  * of thumb is that ReInitializeDSM should reset only shared state, ReScan
472  * should reset only local state, and anything that depends on both of
473  * those steps being finished must wait until the first ExecProcNode call.
474  */
475  if (outerPlan->chgParam == NULL)
477 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
bool initialized
Definition: execnodes.h:2196
static void ExecShutdownGatherWorkers(GatherState *node)
Definition: nodeGather.c:401
#define outerPlanState(node)
Definition: execnodes.h:1033
PlanState ps
Definition: execnodes.h:2195
#define outerPlan(node)
Definition: plannodes.h:170
Plan * plan
Definition: execnodes.h:939
int rescan_param
Definition: plannodes.h:873
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736

◆ ExecShutdownGather()

void ExecShutdownGather ( GatherState node)

Definition at line 419 of file nodeGather.c.

References ExecParallelCleanup(), ExecShutdownGatherWorkers(), and GatherState::pei.

Referenced by ExecEndGather(), and ExecShutdownNode().

420 {
422 
423  /* Now destroy the parallel context. */
424  if (node->pei != NULL)
425  {
426  ExecParallelCleanup(node->pei);
427  node->pei = NULL;
428  }
429 }
static void ExecShutdownGatherWorkers(GatherState *node)
Definition: nodeGather.c:401
struct ParallelExecutorInfo * pei
Definition: execnodes.h:2201
void ExecParallelCleanup(ParallelExecutorInfo *pei)