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

Go to the source code of this file.

Functions

AppendStateExecInitAppend (Append *node, EState *estate, int eflags)
 
TupleTableSlotExecAppend (AppendState *node)
 
void ExecEndAppend (AppendState *node)
 
void ExecReScanAppend (AppendState *node)
 

Function Documentation

TupleTableSlot* ExecAppend ( AppendState node)

Definition at line 200 of file nodeAppend.c.

References AppendState::appendplans, AppendState::as_whichplan, EState::es_direction, exec_append_initialize_next(), ExecClearTuple(), ExecProcNode(), AppendState::ps, PlanState::ps_ResultTupleSlot, result, ScanDirectionIsForward, PlanState::state, and TupIsNull.

Referenced by ExecProcNode().

201 {
202  for (;;)
203  {
204  PlanState *subnode;
206 
207  /*
208  * figure out which subplan we are currently processing
209  */
210  subnode = node->appendplans[node->as_whichplan];
211 
212  /*
213  * get a tuple from the subplan
214  */
215  result = ExecProcNode(subnode);
216 
217  if (!TupIsNull(result))
218  {
219  /*
220  * If the subplan gave us something then return it as-is. We do
221  * NOT make use of the result slot that was set up in
222  * ExecInitAppend; there's no need for it.
223  */
224  return result;
225  }
226 
227  /*
228  * Go on to the "next" subplan in the appropriate direction. If no
229  * more subplans, return the empty slot set up for us by
230  * ExecInitAppend.
231  */
233  node->as_whichplan++;
234  else
235  node->as_whichplan--;
236  if (!exec_append_initialize_next(node))
237  return ExecClearTuple(node->ps.ps_ResultTupleSlot);
238 
239  /* Else loop back and try to get a tuple from the new subplan */
240  }
241 }
TupleTableSlot * ExecProcNode(PlanState *node)
Definition: execProcnode.c:398
#define ScanDirectionIsForward(direction)
Definition: sdir.h:55
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
return result
Definition: formatting.c:1632
EState * state
Definition: execnodes.h:815
ScanDirection es_direction
Definition: execnodes.h:408
PlanState ps
Definition: execnodes.h:960
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:842
#define TupIsNull(slot)
Definition: tuptable.h:138
int as_whichplan
Definition: execnodes.h:963
static bool exec_append_initialize_next(AppendState *appendstate)
Definition: nodeAppend.c:75
PlanState ** appendplans
Definition: execnodes.h:961
void ExecEndAppend ( AppendState node)

Definition at line 252 of file nodeAppend.c.

References AppendState::appendplans, AppendState::as_nplans, ExecEndNode(), and i.

Referenced by ExecEndNode().

253 {
254  PlanState **appendplans;
255  int nplans;
256  int i;
257 
258  /*
259  * get information from the node
260  */
261  appendplans = node->appendplans;
262  nplans = node->as_nplans;
263 
264  /*
265  * shut down each of the subscans
266  */
267  for (i = 0; i < nplans; i++)
268  ExecEndNode(appendplans[i]);
269 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:654
PlanState ** appendplans
Definition: execnodes.h:961
int as_nplans
Definition: execnodes.h:962
int i
AppendState* ExecInitAppend ( Append node,
EState estate,
int  eflags 
)

Definition at line 120 of file nodeAppend.c.

References Append::appendplans, AppendState::appendplans, AppendState::as_nplans, AppendState::as_whichplan, Assert, exec_append_initialize_next(), EXEC_FLAG_MARK, ExecAssignResultTypeFromTL(), ExecInitNode(), ExecInitResultTupleSlot(), ExecLockNonLeafAppendTables(), i, lfirst, list_length(), makeNode, NULL, palloc0(), Append::partitioned_rels, PlanState::plan, AppendState::ps, PlanState::ps_ProjInfo, and PlanState::state.

Referenced by ExecInitNode().

121 {
122  AppendState *appendstate = makeNode(AppendState);
123  PlanState **appendplanstates;
124  int nplans;
125  int i;
126  ListCell *lc;
127 
128  /* check for unsupported flags */
129  Assert(!(eflags & EXEC_FLAG_MARK));
130 
131  /*
132  * Lock the non-leaf tables in the partition tree controlled by this node.
133  * It's a no-op for non-partitioned parent tables.
134  */
136 
137  /*
138  * Set up empty vector of subplan states
139  */
140  nplans = list_length(node->appendplans);
141 
142  appendplanstates = (PlanState **) palloc0(nplans * sizeof(PlanState *));
143 
144  /*
145  * create new AppendState for our append node
146  */
147  appendstate->ps.plan = (Plan *) node;
148  appendstate->ps.state = estate;
149  appendstate->appendplans = appendplanstates;
150  appendstate->as_nplans = nplans;
151 
152  /*
153  * Miscellaneous initialization
154  *
155  * Append plans don't have expression contexts because they never call
156  * ExecQual or ExecProject.
157  */
158 
159  /*
160  * append nodes still have Result slots, which hold pointers to tuples, so
161  * we have to initialize them.
162  */
163  ExecInitResultTupleSlot(estate, &appendstate->ps);
164 
165  /*
166  * call ExecInitNode on each of the plans to be executed and save the
167  * results into the array "appendplans".
168  */
169  i = 0;
170  foreach(lc, node->appendplans)
171  {
172  Plan *initNode = (Plan *) lfirst(lc);
173 
174  appendplanstates[i] = ExecInitNode(initNode, estate, eflags);
175  i++;
176  }
177 
178  /*
179  * initialize output tuple type
180  */
181  ExecAssignResultTypeFromTL(&appendstate->ps);
182  appendstate->ps.ps_ProjInfo = NULL;
183 
184  /*
185  * initialize to scan first subplan
186  */
187  appendstate->as_whichplan = 0;
188  exec_append_initialize_next(appendstate);
189 
190  return appendstate;
191 }
void ExecLockNonLeafAppendTables(List *partitioned_rels, EState *estate)
Definition: execUtils.c:826
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:844
EState * state
Definition: execnodes.h:815
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:440
PlanState ps
Definition: execnodes.h:960
List * appendplans
Definition: plannodes.h:250
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
List * partitioned_rels
Definition: plannodes.h:249
void * palloc0(Size size)
Definition: mcxt.c:878
Plan * plan
Definition: execnodes.h:813
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
#define EXEC_FLAG_MARK
Definition: executor.h:61
int as_whichplan
Definition: execnodes.h:963
static int list_length(const List *l)
Definition: pg_list.h:89
static bool exec_append_initialize_next(AppendState *appendstate)
Definition: nodeAppend.c:75
PlanState ** appendplans
Definition: execnodes.h:961
int as_nplans
Definition: execnodes.h:962
int i
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:140
void ExecReScanAppend ( AppendState node)

Definition at line 272 of file nodeAppend.c.

References AppendState::appendplans, AppendState::as_nplans, AppendState::as_whichplan, PlanState::chgParam, exec_append_initialize_next(), ExecReScan(), i, NULL, AppendState::ps, and UpdateChangedParamSet().

Referenced by ExecReScan().

273 {
274  int i;
275 
276  for (i = 0; i < node->as_nplans; i++)
277  {
278  PlanState *subnode = node->appendplans[i];
279 
280  /*
281  * ExecReScan doesn't know about my subplans, so I have to do
282  * changed-parameter signaling myself.
283  */
284  if (node->ps.chgParam != NULL)
285  UpdateChangedParamSet(subnode, node->ps.chgParam);
286 
287  /*
288  * If chgParam of subnode is not null then plan will be re-scanned by
289  * first ExecProcNode.
290  */
291  if (subnode->chgParam == NULL)
292  ExecReScan(subnode);
293  }
294  node->as_whichplan = 0;
296 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
PlanState ps
Definition: execnodes.h:960
Bitmapset * chgParam
Definition: execnodes.h:837
void UpdateChangedParamSet(PlanState *node, Bitmapset *newchg)
Definition: execUtils.c:671
#define NULL
Definition: c.h:229
int as_whichplan
Definition: execnodes.h:963
static bool exec_append_initialize_next(AppendState *appendstate)
Definition: nodeAppend.c:75
PlanState ** appendplans
Definition: execnodes.h:961
int as_nplans
Definition: execnodes.h:962
int i