PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nodeMergeAppend.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeMergeAppend.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

MergeAppendStateExecInitMergeAppend (MergeAppend *node, EState *estate, int eflags)
 
void ExecEndMergeAppend (MergeAppendState *node)
 
void ExecReScanMergeAppend (MergeAppendState *node)
 

Function Documentation

◆ ExecEndMergeAppend()

void ExecEndMergeAppend ( MergeAppendState node)

Definition at line 335 of file nodeMergeAppend.c.

336{
337 PlanState **mergeplans;
338 int nplans;
339 int i;
340
341 /*
342 * get information from the node
343 */
344 mergeplans = node->mergeplans;
345 nplans = node->ms_nplans;
346
347 /*
348 * shut down each of the subscans
349 */
350 for (i = 0; i < nplans; i++)
351 ExecEndNode(mergeplans[i]);
352}
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
int i
Definition: isn.c:77
PlanState ** mergeplans
Definition: execnodes.h:1535

References ExecEndNode(), i, MergeAppendState::mergeplans, and MergeAppendState::ms_nplans.

Referenced by ExecEndNode().

◆ ExecInitMergeAppend()

MergeAppendState * ExecInitMergeAppend ( MergeAppend node,
EState estate,
int  eflags 
)

Definition at line 65 of file nodeMergeAppend.c.

66{
68 PlanState **mergeplanstates;
69 const TupleTableSlotOps *mergeops;
70 Bitmapset *validsubplans;
71 int nplans;
72 int i,
73 j;
74
75 /* check for unsupported flags */
77
78 /*
79 * create new MergeAppendState for our node
80 */
81 mergestate->ps.plan = (Plan *) node;
82 mergestate->ps.state = estate;
83 mergestate->ps.ExecProcNode = ExecMergeAppend;
84
85 /* If run-time partition pruning is enabled, then set that up now */
86 if (node->part_prune_index >= 0)
87 {
88 PartitionPruneState *prunestate;
89
90 /*
91 * Set up pruning data structure. This also initializes the set of
92 * subplans to initialize (validsubplans) by taking into account the
93 * result of performing initial pruning if any.
94 */
95 prunestate = ExecInitPartitionExecPruning(&mergestate->ps,
97 node->part_prune_index,
98 node->apprelids,
99 &validsubplans);
100 mergestate->ms_prune_state = prunestate;
101 nplans = bms_num_members(validsubplans);
102
103 /*
104 * When no run-time pruning is required and there's at least one
105 * subplan, we can fill ms_valid_subplans immediately, preventing
106 * later calls to ExecFindMatchingSubPlans.
107 */
108 if (!prunestate->do_exec_prune && nplans > 0)
109 mergestate->ms_valid_subplans = bms_add_range(NULL, 0, nplans - 1);
110 }
111 else
112 {
113 nplans = list_length(node->mergeplans);
114
115 /*
116 * When run-time partition pruning is not enabled we can just mark all
117 * subplans as valid; they must also all be initialized.
118 */
119 Assert(nplans > 0);
120 mergestate->ms_valid_subplans = validsubplans =
121 bms_add_range(NULL, 0, nplans - 1);
122 mergestate->ms_prune_state = NULL;
123 }
124
125 mergeplanstates = (PlanState **) palloc(nplans * sizeof(PlanState *));
126 mergestate->mergeplans = mergeplanstates;
127 mergestate->ms_nplans = nplans;
128
129 mergestate->ms_slots = (TupleTableSlot **) palloc0(sizeof(TupleTableSlot *) * nplans);
130 mergestate->ms_heap = binaryheap_allocate(nplans, heap_compare_slots,
131 mergestate);
132
133 /*
134 * call ExecInitNode on each of the valid plans to be executed and save
135 * the results into the mergeplanstates array.
136 */
137 j = 0;
138 i = -1;
139 while ((i = bms_next_member(validsubplans, i)) >= 0)
140 {
141 Plan *initNode = (Plan *) list_nth(node->mergeplans, i);
142
143 mergeplanstates[j++] = ExecInitNode(initNode, estate, eflags);
144 }
145
146 /*
147 * Initialize MergeAppend's result tuple type and slot. If the child
148 * plans all produce the same fixed slot type, we can use that slot type;
149 * otherwise make a virtual slot. (Note that the result slot itself is
150 * used only to return a null tuple at end of execution; real tuples are
151 * returned to the caller in the children's own result slots. What we are
152 * doing here is allowing the parent plan node to optimize if the
153 * MergeAppend will return only one kind of slot.)
154 */
155 mergeops = ExecGetCommonSlotOps(mergeplanstates, j);
156 if (mergeops != NULL)
157 {
158 ExecInitResultTupleSlotTL(&mergestate->ps, mergeops);
159 }
160 else
161 {
163 /* show that the output slot type is not fixed */
164 mergestate->ps.resultopsset = true;
165 mergestate->ps.resultopsfixed = false;
166 }
167
168 /*
169 * Miscellaneous initialization
170 */
171 mergestate->ps.ps_ProjInfo = NULL;
172
173 /*
174 * initialize sort-key information
175 */
176 mergestate->ms_nkeys = node->numCols;
177 mergestate->ms_sortkeys = palloc0(sizeof(SortSupportData) * node->numCols);
178
179 for (i = 0; i < node->numCols; i++)
180 {
181 SortSupport sortKey = mergestate->ms_sortkeys + i;
182
184 sortKey->ssup_collation = node->collations[i];
185 sortKey->ssup_nulls_first = node->nullsFirst[i];
186 sortKey->ssup_attno = node->sortColIdx[i];
187
188 /*
189 * It isn't feasible to perform abbreviated key conversion, since
190 * tuples are pulled into mergestate's binary heap as needed. It
191 * would likely be counter-productive to convert tuples into an
192 * abbreviated representation as they're pulled up, so opt out of that
193 * additional optimization entirely.
194 */
195 sortKey->abbreviate = false;
196
197 PrepareSortSupportFromOrderingOp(node->sortOperators[i], sortKey);
198 }
199
200 /*
201 * initialize to show we have not run the subplans yet
202 */
203 mergestate->ms_initialized = false;
204
205 return mergestate;
206}
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
Definition: binaryheap.c:39
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1306
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Definition: bitmapset.c:1019
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:751
PartitionPruneState * ExecInitPartitionExecPruning(PlanState *planstate, int n_total_subplans, int part_prune_index, Bitmapset *relids, Bitmapset **initially_valid_subplans)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1988
const TupleTableSlotOps * ExecGetCommonSlotOps(PlanState **planstates, int nplans)
Definition: execUtils.c:537
#define EXEC_FLAG_BACKWARD
Definition: executor.h:69
#define EXEC_FLAG_MARK
Definition: executor.h:70
Assert(PointerIsAligned(start, uint64))
int j
Definition: isn.c:78
void * palloc0(Size size)
Definition: mcxt.c:1975
void * palloc(Size size)
Definition: mcxt.c:1945
MemoryContext CurrentMemoryContext
Definition: mcxt.c:159
static int heap_compare_slots(Datum a, Datum b, void *arg)
static TupleTableSlot * ExecMergeAppend(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:161
static int list_length(const List *l)
Definition: pg_list.h:152
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
Definition: sortsupport.c:134
SortSupport ms_sortkeys
Definition: execnodes.h:1538
Bitmapset * ms_valid_subplans
Definition: execnodes.h:1543
PlanState ps
Definition: execnodes.h:1534
struct binaryheap * ms_heap
Definition: execnodes.h:1540
TupleTableSlot ** ms_slots
Definition: execnodes.h:1539
struct PartitionPruneState * ms_prune_state
Definition: execnodes.h:1542
int part_prune_index
Definition: plannodes.h:407
Bitmapset * apprelids
Definition: plannodes.h:381
List * mergeplans
Definition: plannodes.h:383
bool resultopsset
Definition: execnodes.h:1244
Plan * plan
Definition: execnodes.h:1159
EState * state
Definition: execnodes.h:1161
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1199
bool resultopsfixed
Definition: execnodes.h:1240
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1165
AttrNumber ssup_attno
Definition: sortsupport.h:81
bool ssup_nulls_first
Definition: sortsupport.h:75
MemoryContext ssup_cxt
Definition: sortsupport.h:66

References SortSupportData::abbreviate, MergeAppend::apprelids, Assert(), binaryheap_allocate(), bms_add_range(), bms_next_member(), bms_num_members(), CurrentMemoryContext, PartitionPruneState::do_exec_prune, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecGetCommonSlotOps(), ExecInitNode(), ExecInitPartitionExecPruning(), ExecInitResultTupleSlotTL(), ExecMergeAppend(), PlanState::ExecProcNode, heap_compare_slots(), i, j, list_length(), list_nth(), makeNode, MergeAppendState::mergeplans, MergeAppend::mergeplans, MergeAppendState::ms_heap, MergeAppendState::ms_initialized, MergeAppendState::ms_nkeys, MergeAppendState::ms_nplans, MergeAppendState::ms_prune_state, MergeAppendState::ms_slots, MergeAppendState::ms_sortkeys, MergeAppendState::ms_valid_subplans, MergeAppend::numCols, palloc(), palloc0(), MergeAppend::part_prune_index, PlanState::plan, PrepareSortSupportFromOrderingOp(), MergeAppendState::ps, PlanState::ps_ProjInfo, PlanState::resultopsfixed, PlanState::resultopsset, SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, PlanState::state, and TTSOpsVirtual.

Referenced by ExecInitNode().

◆ ExecReScanMergeAppend()

void ExecReScanMergeAppend ( MergeAppendState node)

Definition at line 355 of file nodeMergeAppend.c.

356{
357 int i;
358
359 /*
360 * If any PARAM_EXEC Params used in pruning expressions have changed, then
361 * we'd better unset the valid subplans so that they are reselected for
362 * the new parameter values.
363 */
364 if (node->ms_prune_state &&
365 bms_overlap(node->ps.chgParam,
367 {
369 node->ms_valid_subplans = NULL;
370 }
371
372 for (i = 0; i < node->ms_nplans; i++)
373 {
374 PlanState *subnode = node->mergeplans[i];
375
376 /*
377 * ExecReScan doesn't know about my subplans, so I have to do
378 * changed-parameter signaling myself.
379 */
380 if (node->ps.chgParam != NULL)
381 UpdateChangedParamSet(subnode, node->ps.chgParam);
382
383 /*
384 * If chgParam of subnode is not null then plan will be re-scanned by
385 * first ExecProcNode.
386 */
387 if (subnode->chgParam == NULL)
388 ExecReScan(subnode);
389 }
391 node->ms_initialized = false;
392}
void binaryheap_reset(binaryheap *heap)
Definition: binaryheap.c:63
void bms_free(Bitmapset *a)
Definition: bitmapset.c:239
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:582
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:911
Bitmapset * execparamids
Bitmapset * chgParam
Definition: execnodes.h:1191

References binaryheap_reset(), bms_free(), bms_overlap(), PlanState::chgParam, PartitionPruneState::execparamids, ExecReScan(), i, MergeAppendState::mergeplans, MergeAppendState::ms_heap, MergeAppendState::ms_initialized, MergeAppendState::ms_nplans, MergeAppendState::ms_prune_state, MergeAppendState::ms_valid_subplans, MergeAppendState::ps, and UpdateChangedParamSet().

Referenced by ExecReScan().