PostgreSQL Source Code  git master
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 320 of file nodeMergeAppend.c.

321 {
322  PlanState **mergeplans;
323  int nplans;
324  int i;
325 
326  /*
327  * get information from the node
328  */
329  mergeplans = node->mergeplans;
330  nplans = node->ms_nplans;
331 
332  /*
333  * shut down each of the subscans
334  */
335  for (i = 0; i < nplans; i++)
336  ExecEndNode(mergeplans[i]);
337 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
int i
Definition: isn.c:73
PlanState ** mergeplans
Definition: execnodes.h:1476

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  Bitmapset *validsubplans;
70  int nplans;
71  int i,
72  j;
73 
74  /* check for unsupported flags */
75  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
76 
77  /*
78  * create new MergeAppendState for our node
79  */
80  mergestate->ps.plan = (Plan *) node;
81  mergestate->ps.state = estate;
82  mergestate->ps.ExecProcNode = ExecMergeAppend;
83 
84  /* If run-time partition pruning is enabled, then set that up now */
85  if (node->part_prune_info != NULL)
86  {
87  PartitionPruneState *prunestate;
88 
89  /*
90  * Set up pruning data structure. This also initializes the set of
91  * subplans to initialize (validsubplans) by taking into account the
92  * result of performing initial pruning if any.
93  */
94  prunestate = ExecInitPartitionPruning(&mergestate->ps,
95  list_length(node->mergeplans),
96  node->part_prune_info,
97  &validsubplans);
98  mergestate->ms_prune_state = prunestate;
99  nplans = bms_num_members(validsubplans);
100 
101  /*
102  * When no run-time pruning is required and there's at least one
103  * subplan, we can fill ms_valid_subplans immediately, preventing
104  * later calls to ExecFindMatchingSubPlans.
105  */
106  if (!prunestate->do_exec_prune && nplans > 0)
107  mergestate->ms_valid_subplans = bms_add_range(NULL, 0, nplans - 1);
108  }
109  else
110  {
111  nplans = list_length(node->mergeplans);
112 
113  /*
114  * When run-time partition pruning is not enabled we can just mark all
115  * subplans as valid; they must also all be initialized.
116  */
117  Assert(nplans > 0);
118  mergestate->ms_valid_subplans = validsubplans =
119  bms_add_range(NULL, 0, nplans - 1);
120  mergestate->ms_prune_state = NULL;
121  }
122 
123  mergeplanstates = (PlanState **) palloc(nplans * sizeof(PlanState *));
124  mergestate->mergeplans = mergeplanstates;
125  mergestate->ms_nplans = nplans;
126 
127  mergestate->ms_slots = (TupleTableSlot **) palloc0(sizeof(TupleTableSlot *) * nplans);
128  mergestate->ms_heap = binaryheap_allocate(nplans, heap_compare_slots,
129  mergestate);
130 
131  /*
132  * Miscellaneous initialization
133  *
134  * MergeAppend nodes do have Result slots, which hold pointers to tuples,
135  * so we have to initialize them. FIXME
136  */
138 
139  /* node returns slots from each of its subnodes, therefore not fixed */
140  mergestate->ps.resultopsset = true;
141  mergestate->ps.resultopsfixed = false;
142 
143  /*
144  * call ExecInitNode on each of the valid plans to be executed and save
145  * the results into the mergeplanstates array.
146  */
147  j = 0;
148  i = -1;
149  while ((i = bms_next_member(validsubplans, i)) >= 0)
150  {
151  Plan *initNode = (Plan *) list_nth(node->mergeplans, i);
152 
153  mergeplanstates[j++] = ExecInitNode(initNode, estate, eflags);
154  }
155 
156  mergestate->ps.ps_ProjInfo = NULL;
157 
158  /*
159  * initialize sort-key information
160  */
161  mergestate->ms_nkeys = node->numCols;
162  mergestate->ms_sortkeys = palloc0(sizeof(SortSupportData) * node->numCols);
163 
164  for (i = 0; i < node->numCols; i++)
165  {
166  SortSupport sortKey = mergestate->ms_sortkeys + i;
167 
168  sortKey->ssup_cxt = CurrentMemoryContext;
169  sortKey->ssup_collation = node->collations[i];
170  sortKey->ssup_nulls_first = node->nullsFirst[i];
171  sortKey->ssup_attno = node->sortColIdx[i];
172 
173  /*
174  * It isn't feasible to perform abbreviated key conversion, since
175  * tuples are pulled into mergestate's binary heap as needed. It
176  * would likely be counter-productive to convert tuples into an
177  * abbreviated representation as they're pulled up, so opt out of that
178  * additional optimization entirely.
179  */
180  sortKey->abbreviate = false;
181 
182  PrepareSortSupportFromOrderingOp(node->sortOperators[i], sortKey);
183  }
184 
185  /*
186  * initialize to show we have not run the subplans yet
187  */
188  mergestate->ms_initialized = false;
189 
190  return mergestate;
191 }
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
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:751
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Definition: bitmapset.c:1019
PartitionPruneState * ExecInitPartitionPruning(PlanState *planstate, int n_total_subplans, PartitionPruneInfo *pruneinfo, 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:1886
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
int j
Definition: isn.c:74
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
Definition: mcxt.c:1334
MemoryContext CurrentMemoryContext
Definition: mcxt.c:131
void * palloc(Size size)
Definition: mcxt.c:1304
static int heap_compare_slots(Datum a, Datum b, void *arg)
static TupleTableSlot * ExecMergeAppend(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:155
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:1479
Bitmapset * ms_valid_subplans
Definition: execnodes.h:1484
PlanState ps
Definition: execnodes.h:1475
struct binaryheap * ms_heap
Definition: execnodes.h:1481
TupleTableSlot ** ms_slots
Definition: execnodes.h:1480
struct PartitionPruneState * ms_prune_state
Definition: execnodes.h:1483
struct PartitionPruneInfo * part_prune_info
Definition: plannodes.h:312
List * mergeplans
Definition: plannodes.h:292
bool resultopsset
Definition: execnodes.h:1201
Plan * plan
Definition: execnodes.h:1116
EState * state
Definition: execnodes.h:1118
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1156
bool resultopsfixed
Definition: execnodes.h:1197
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1122
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, Assert(), binaryheap_allocate(), bms_add_range(), bms_next_member(), bms_num_members(), CurrentMemoryContext, PartitionPruneState::do_exec_prune, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecInitNode(), ExecInitPartitionPruning(), 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_info, 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 340 of file nodeMergeAppend.c.

341 {
342  int i;
343 
344  /*
345  * If any PARAM_EXEC Params used in pruning expressions have changed, then
346  * we'd better unset the valid subplans so that they are reselected for
347  * the new parameter values.
348  */
349  if (node->ms_prune_state &&
350  bms_overlap(node->ps.chgParam,
352  {
354  node->ms_valid_subplans = NULL;
355  }
356 
357  for (i = 0; i < node->ms_nplans; i++)
358  {
359  PlanState *subnode = node->mergeplans[i];
360 
361  /*
362  * ExecReScan doesn't know about my subplans, so I have to do
363  * changed-parameter signaling myself.
364  */
365  if (node->ps.chgParam != NULL)
366  UpdateChangedParamSet(subnode, node->ps.chgParam);
367 
368  /*
369  * If chgParam of subnode is not null then plan will be re-scanned by
370  * first ExecProcNode.
371  */
372  if (subnode->chgParam == NULL)
373  ExecReScan(subnode);
374  }
375  binaryheap_reset(node->ms_heap);
376  node->ms_initialized = false;
377 }
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:76
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:844
Bitmapset * execparamids
Bitmapset * chgParam
Definition: execnodes.h:1148

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().