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

Go to the source code of this file.

Functions

RecursiveUnionStateExecInitRecursiveUnion (RecursiveUnion *node, EState *estate, int eflags)
 
void ExecEndRecursiveUnion (RecursiveUnionState *node)
 
void ExecReScanRecursiveUnion (RecursiveUnionState *node)
 

Function Documentation

void ExecEndRecursiveUnion ( RecursiveUnionState node)

Definition at line 268 of file nodeRecursiveunion.c.

References ExecClearTuple(), ExecEndNode(), innerPlanState, RecursiveUnionState::intermediate_table, MemoryContextDelete(), outerPlanState, RecursiveUnionState::ps, PlanState::ps_ResultTupleSlot, RecursiveUnionState::tableContext, RecursiveUnionState::tempContext, tuplestore_end(), and RecursiveUnionState::working_table.

Referenced by ExecEndNode().

269 {
270  /* Release tuplestores */
273 
274  /* free subsidiary stuff including hashtable */
275  if (node->tempContext)
277  if (node->tableContext)
279 
280  /*
281  * clean out the upper tuple table
282  */
284 
285  /*
286  * close down subplans
287  */
290 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
Tuplestorestate * intermediate_table
Definition: execnodes.h:1049
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
MemoryContext tempContext
Definition: execnodes.h:1053
#define outerPlanState(node)
Definition: execnodes.h:893
Tuplestorestate * working_table
Definition: execnodes.h:1048
MemoryContext tableContext
Definition: execnodes.h:1055
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:453
#define innerPlanState(node)
Definition: execnodes.h:892
RecursiveUnionState* ExecInitRecursiveUnion ( RecursiveUnion node,
EState estate,
int  eflags 
)

Definition at line 162 of file nodeRecursiveunion.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), Assert, build_hash_table(), CurrentMemoryContext, RecursiveUnion::dupOperators, RecursiveUnionState::eqfunctions, EState::es_param_exec_vals, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignResultTypeFromTL(), ExecInitNode(), ExecInitResultTupleSlot(), ParamExecData::execPlan, PlanState::ExecProcNode, ExecRecursiveUnion(), execTuplesHashPrepare(), RecursiveUnionState::hashfunctions, RecursiveUnionState::hashtable, innerPlan, innerPlanState, RecursiveUnionState::intermediate_empty, RecursiveUnionState::intermediate_table, ParamExecData::isnull, makeNode, NIL, RecursiveUnion::numCols, outerPlan, outerPlanState, RecursiveUnion::plan, PlanState::plan, PointerGetDatum, RecursiveUnionState::ps, PlanState::ps_ProjInfo, Plan::qual, RecursiveUnionState::recursing, PlanState::state, RecursiveUnionState::tableContext, RecursiveUnionState::tempContext, tuplestore_begin_heap(), ParamExecData::value, work_mem, RecursiveUnionState::working_table, and RecursiveUnion::wtParam.

Referenced by ExecInitNode().

163 {
164  RecursiveUnionState *rustate;
165  ParamExecData *prmdata;
166 
167  /* check for unsupported flags */
168  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
169 
170  /*
171  * create state structure
172  */
173  rustate = makeNode(RecursiveUnionState);
174  rustate->ps.plan = (Plan *) node;
175  rustate->ps.state = estate;
177 
178  rustate->eqfunctions = NULL;
179  rustate->hashfunctions = NULL;
180  rustate->hashtable = NULL;
181  rustate->tempContext = NULL;
182  rustate->tableContext = NULL;
183 
184  /* initialize processing state */
185  rustate->recursing = false;
186  rustate->intermediate_empty = true;
187  rustate->working_table = tuplestore_begin_heap(false, false, work_mem);
188  rustate->intermediate_table = tuplestore_begin_heap(false, false, work_mem);
189 
190  /*
191  * If hashing, we need a per-tuple memory context for comparisons, and a
192  * longer-lived context to store the hash table. The table can't just be
193  * kept in the per-query context because we want to be able to throw it
194  * away when rescanning.
195  */
196  if (node->numCols > 0)
197  {
198  rustate->tempContext =
200  "RecursiveUnion",
202  rustate->tableContext =
204  "RecursiveUnion hash table",
206  }
207 
208  /*
209  * Make the state structure available to descendant WorkTableScan nodes
210  * via the Param slot reserved for it.
211  */
212  prmdata = &(estate->es_param_exec_vals[node->wtParam]);
213  Assert(prmdata->execPlan == NULL);
214  prmdata->value = PointerGetDatum(rustate);
215  prmdata->isnull = false;
216 
217  /*
218  * Miscellaneous initialization
219  *
220  * RecursiveUnion plans don't have expression contexts because they never
221  * call ExecQual or ExecProject.
222  */
223  Assert(node->plan.qual == NIL);
224 
225  /*
226  * RecursiveUnion nodes still have Result slots, which hold pointers to
227  * tuples, so we have to initialize them.
228  */
229  ExecInitResultTupleSlot(estate, &rustate->ps);
230 
231  /*
232  * Initialize result tuple type and projection info. (Note: we have to
233  * set up the result type before initializing child nodes, because
234  * nodeWorktablescan.c expects it to be valid.)
235  */
236  ExecAssignResultTypeFromTL(&rustate->ps);
237  rustate->ps.ps_ProjInfo = NULL;
238 
239  /*
240  * initialize child nodes
241  */
242  outerPlanState(rustate) = ExecInitNode(outerPlan(node), estate, eflags);
243  innerPlanState(rustate) = ExecInitNode(innerPlan(node), estate, eflags);
244 
245  /*
246  * If hashing, precompute fmgr lookup data for inner loop, and create the
247  * hash table.
248  */
249  if (node->numCols > 0)
250  {
252  node->dupOperators,
253  &rustate->eqfunctions,
254  &rustate->hashfunctions);
255  build_hash_table(rustate);
256  }
257 
258  return rustate;
259 }
#define NIL
Definition: pg_list.h:69
List * qual
Definition: plannodes.h:145
void * execPlan
Definition: params.h:99
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:882
Tuplestorestate * intermediate_table
Definition: execnodes.h:1049
#define PointerGetDatum(X)
Definition: postgres.h:562
FmgrInfo * hashfunctions
Definition: execnodes.h:1052
EState * state
Definition: execnodes.h:849
void execTuplesHashPrepare(int numCols, Oid *eqOperators, FmgrInfo **eqFunctions, FmgrInfo **hashFunctions)
Definition: execGrouping.c:233
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
ParamExecData * es_param_exec_vals
Definition: execnodes.h:466
bool isnull
Definition: params.h:101
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:165
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
MemoryContext tempContext
Definition: execnodes.h:1053
#define outerPlanState(node)
Definition: execnodes.h:893
#define innerPlan(node)
Definition: plannodes.h:173
FmgrInfo * eqfunctions
Definition: execnodes.h:1051
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
TupleHashTable hashtable
Definition: execnodes.h:1054
static TupleTableSlot * ExecRecursiveUnion(PlanState *pstate)
Tuplestorestate * working_table
Definition: execnodes.h:1048
#define outerPlan(node)
Definition: plannodes.h:174
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
int work_mem
Definition: globals.c:113
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:558
MemoryContext tableContext
Definition: execnodes.h:1055
#define Assert(condition)
Definition: c.h:681
#define EXEC_FLAG_MARK
Definition: executor.h:61
Oid * dupOperators
Definition: plannodes.h:288
static void build_hash_table(RecursiveUnionState *rustate)
Datum value
Definition: params.h:100
#define innerPlanState(node)
Definition: execnodes.h:892
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
void ExecReScanRecursiveUnion ( RecursiveUnionState node)

Definition at line 299 of file nodeRecursiveunion.c.

References bms_add_member(), build_hash_table(), PlanState::chgParam, ExecReScan(), innerPlan, innerPlanState, RecursiveUnionState::intermediate_empty, RecursiveUnionState::intermediate_table, MemoryContextResetAndDeleteChildren, RecursiveUnion::numCols, outerPlan, outerPlanState, PlanState::plan, RecursiveUnionState::ps, RecursiveUnionState::recursing, RecursiveUnionState::tableContext, tuplestore_clear(), RecursiveUnionState::working_table, and RecursiveUnion::wtParam.

Referenced by ExecReScan().

300 {
303  RecursiveUnion *plan = (RecursiveUnion *) node->ps.plan;
304 
305  /*
306  * Set recursive term's chgParam to tell it that we'll modify the working
307  * table and therefore it has to rescan.
308  */
309  innerPlan->chgParam = bms_add_member(innerPlan->chgParam, plan->wtParam);
310 
311  /*
312  * if chgParam of subnode is not null then plan will be re-scanned by
313  * first ExecProcNode. Because of above, we only have to do this to the
314  * non-recursive term.
315  */
316  if (outerPlan->chgParam == NULL)
317  ExecReScan(outerPlan);
318 
319  /* Release any hashtable storage */
320  if (node->tableContext)
322 
323  /* And rebuild empty hashtable if needed */
324  if (plan->numCols > 0)
325  build_hash_table(node);
326 
327  /* reset processing state */
328  node->recursing = false;
329  node->intermediate_empty = true;
332 }
Tuplestorestate * intermediate_table
Definition: execnodes.h:1049
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void tuplestore_clear(Tuplestorestate *state)
Definition: tuplestore.c:418
#define outerPlanState(node)
Definition: execnodes.h:893
#define innerPlan(node)
Definition: plannodes.h:173
Bitmapset * chgParam
Definition: execnodes.h:875
Tuplestorestate * working_table
Definition: execnodes.h:1048
#define outerPlan(node)
Definition: plannodes.h:174
#define MemoryContextResetAndDeleteChildren(ctx)
Definition: memutils.h:67
Plan * plan
Definition: execnodes.h:847
MemoryContext tableContext
Definition: execnodes.h:1055
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:698
static void build_hash_table(RecursiveUnionState *rustate)
#define innerPlanState(node)
Definition: execnodes.h:892