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

Go to the source code of this file.

Functions

GatherMergeStateExecInitGatherMerge (GatherMerge *node, EState *estate, int eflags)
 
void ExecEndGatherMerge (GatherMergeState *node)
 
void ExecReScanGatherMerge (GatherMergeState *node)
 
void ExecShutdownGatherMerge (GatherMergeState *node)
 

Function Documentation

◆ ExecEndGatherMerge()

void ExecEndGatherMerge ( GatherMergeState node)
extern

Definition at line 292 of file nodeGatherMerge.c.

293{
294 ExecEndNode(outerPlanState(node)); /* let children clean up first */
296}
void ExecEndNode(PlanState *node)
#define outerPlanState(node)
Definition execnodes.h:1273
void ExecShutdownGatherMerge(GatherMergeState *node)

References ExecEndNode(), ExecShutdownGatherMerge(), and outerPlanState.

Referenced by ExecEndNode().

◆ ExecInitGatherMerge()

GatherMergeState * ExecInitGatherMerge ( GatherMerge node,
EState estate,
int  eflags 
)
extern

Definition at line 69 of file nodeGatherMerge.c.

70{
73 TupleDesc tupDesc;
74
75 /* Gather merge node doesn't have innerPlan node. */
76 Assert(innerPlan(node) == NULL);
77
78 /*
79 * create state structure
80 */
82 gm_state->ps.plan = (Plan *) node;
83 gm_state->ps.state = estate;
84 gm_state->ps.ExecProcNode = ExecGatherMerge;
85
86 gm_state->initialized = false;
87 gm_state->gm_initialized = false;
88 gm_state->tuples_needed = -1;
89
90 /*
91 * Miscellaneous initialization
92 *
93 * create expression context for node
94 */
95 ExecAssignExprContext(estate, &gm_state->ps);
96
97 /*
98 * GatherMerge doesn't support checking a qual (it's always more efficient
99 * to do it in the child node).
100 */
101 Assert(!node->plan.qual);
102
103 /*
104 * now initialize outer plan
105 */
106 outerNode = outerPlan(node);
107 outerPlanState(gm_state) = ExecInitNode(outerNode, estate, eflags);
108
109 /*
110 * Leader may access ExecProcNode result directly (if
111 * need_to_scan_locally), or from workers via tuple queue. So we can't
112 * trivially rely on the slot type being fixed for expressions evaluated
113 * within this node.
114 */
115 gm_state->ps.outeropsset = true;
116 gm_state->ps.outeropsfixed = false;
117
118 /*
119 * Store the tuple descriptor into gather merge state, so we can use it
120 * while initializing the gather merge slots.
121 */
123 gm_state->tupDesc = tupDesc;
124
125 /*
126 * Initialize result type and projection.
127 */
130
131 /*
132 * Without projections result slot type is not trivially known, see
133 * comment above.
134 */
135 if (gm_state->ps.ps_ProjInfo == NULL)
136 {
137 gm_state->ps.resultopsset = true;
138 gm_state->ps.resultopsfixed = false;
139 }
140
141 /*
142 * initialize sort-key information
143 */
144 if (node->numCols)
145 {
146 int i;
147
148 gm_state->gm_nkeys = node->numCols;
149 gm_state->gm_sortkeys = palloc0_array(SortSupportData, node->numCols);
150
151 for (i = 0; i < node->numCols; i++)
152 {
153 SortSupport sortKey = gm_state->gm_sortkeys + i;
154
156 sortKey->ssup_collation = node->collations[i];
157 sortKey->ssup_nulls_first = node->nullsFirst[i];
158 sortKey->ssup_attno = node->sortColIdx[i];
159
160 /*
161 * We don't perform abbreviated key conversion here, for the same
162 * reasons that it isn't used in MergeAppend
163 */
164 sortKey->abbreviate = false;
165
166 PrepareSortSupportFromOrderingOp(node->sortOperators[i], sortKey);
167 }
168 }
169
170 /* Now allocate the workspace for gather merge */
172
173 return gm_state;
174}
#define Assert(condition)
Definition c.h:945
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
void ExecInitResultTypeTL(PlanState *planstate)
TupleDesc ExecGetResultType(PlanState *planstate)
Definition execUtils.c:500
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition execUtils.c:490
void ExecConditionalAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc, int varno)
Definition execUtils.c:608
#define palloc0_array(type, count)
Definition fe_memutils.h:77
int i
Definition isn.c:77
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
static void gather_merge_setup(GatherMergeState *gm_state)
static TupleTableSlot * ExecGatherMerge(PlanState *pstate)
#define makeNode(_type_)
Definition nodes.h:161
#define innerPlan(node)
Definition plannodes.h:264
#define outerPlan(node)
Definition plannodes.h:265
static int fb(int x)
#define OUTER_VAR
Definition primnodes.h:244
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
List * qual
Definition plannodes.h:235
MemoryContext ssup_cxt
Definition sortsupport.h:66

References Assert, CurrentMemoryContext, ExecAssignExprContext(), ExecConditionalAssignProjectionInfo(), ExecGatherMerge(), ExecGetResultType(), ExecInitNode(), ExecInitResultTypeTL(), fb(), gather_merge_setup(), i, innerPlan, makeNode, GatherMerge::numCols, OUTER_VAR, outerPlan, outerPlanState, palloc0_array, GatherMerge::plan, PrepareSortSupportFromOrderingOp(), Plan::qual, and SortSupportData::ssup_cxt.

Referenced by ExecInitNode().

◆ ExecReScanGatherMerge()

void ExecReScanGatherMerge ( GatherMergeState node)
extern

Definition at line 342 of file nodeGatherMerge.c.

343{
344 GatherMerge *gm = (GatherMerge *) node->ps.plan;
346
347 /* Make sure any existing workers are gracefully shut down */
349
350 /* Free any unused tuples, so we don't leak memory across rescans */
352
353 /* Mark node so that shared state will be rebuilt at next call */
354 node->initialized = false;
355 node->gm_initialized = false;
356
357 /*
358 * Set child node's chgParam to tell it that the next scan might deliver a
359 * different set of rows within the leader process. (The overall rowset
360 * shouldn't change, but the leader process's subset might; hence nodes
361 * between here and the parallel table scan node mustn't optimize on the
362 * assumption of an unchanging rowset.)
363 */
364 if (gm->rescan_param >= 0)
365 outerPlan->chgParam = bms_add_member(outerPlan->chgParam,
366 gm->rescan_param);
367
368 /*
369 * If chgParam of subnode is not null then plan will be re-scanned by
370 * first ExecProcNode. Note: because this does nothing if we have a
371 * rescan_param, it's currently guaranteed that parallel-aware child nodes
372 * will not see a ReScan call until after they get a ReInitializeDSM call.
373 * That ordering might not be something to rely on, though. A good rule
374 * of thumb is that ReInitializeDSM should reset only shared state, ReScan
375 * should reset only local state, and anything that depends on both of
376 * those steps being finished must wait until the first ExecProcNode call.
377 */
378 if (outerPlan->chgParam == NULL)
380}
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:799
void ExecReScan(PlanState *node)
Definition execAmi.c:78
static void gather_merge_clear_tuples(GatherMergeState *gm_state)
static void ExecShutdownGatherMergeWorkers(GatherMergeState *node)
Plan * plan
Definition execnodes.h:1177

References bms_add_member(), ExecReScan(), ExecShutdownGatherMergeWorkers(), fb(), gather_merge_clear_tuples(), GatherMergeState::gm_initialized, GatherMergeState::initialized, outerPlan, outerPlanState, PlanState::plan, and GatherMergeState::ps.

Referenced by ExecReScan().

◆ ExecShutdownGatherMerge()

void ExecShutdownGatherMerge ( GatherMergeState node)
extern

Definition at line 305 of file nodeGatherMerge.c.

306{
308
309 /* Now destroy the parallel context. */
310 if (node->pei != NULL)
311 {
313 node->pei = NULL;
314 }
315}
void ExecParallelCleanup(ParallelExecutorInfo *pei)
struct ParallelExecutorInfo * pei
Definition execnodes.h:2648

References ExecParallelCleanup(), ExecShutdownGatherMergeWorkers(), fb(), and GatherMergeState::pei.

Referenced by ExecEndGatherMerge(), and ExecShutdownNode_walker().