PostgreSQL Source Code  git master
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

◆ ExecEndRecursiveUnion()

void ExecEndRecursiveUnion ( RecursiveUnionState node)

Definition at line 270 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().

271 {
272  /* Release tuplestores */
275 
276  /* free subsidiary stuff including hashtable */
277  if (node->tempContext)
279  if (node->tableContext)
281 
282  /*
283  * clean out the upper tuple table
284  */
286 
287  /*
288  * close down subplans
289  */
292 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:198
Tuplestorestate * intermediate_table
Definition: execnodes.h:1072
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:539
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:901
MemoryContext tempContext
Definition: execnodes.h:1076
#define outerPlanState(node)
Definition: execnodes.h:914
Tuplestorestate * working_table
Definition: execnodes.h:1071
MemoryContext tableContext
Definition: execnodes.h:1078
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:453
#define innerPlanState(node)
Definition: execnodes.h:913

◆ ExecInitRecursiveUnion()

RecursiveUnionState* ExecInitRecursiveUnion ( RecursiveUnion node,
EState estate,
int  eflags 
)

Definition at line 165 of file nodeRecursiveunion.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, build_hash_table(), CurrentMemoryContext, RecursiveUnion::dupOperators, RecursiveUnionState::eqfuncoids, EState::es_param_exec_vals, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecInitNode(), ExecInitResultTupleSlotTL(), 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().

166 {
167  RecursiveUnionState *rustate;
168  ParamExecData *prmdata;
169 
170  /* check for unsupported flags */
171  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
172 
173  /*
174  * create state structure
175  */
176  rustate = makeNode(RecursiveUnionState);
177  rustate->ps.plan = (Plan *) node;
178  rustate->ps.state = estate;
180 
181  rustate->eqfuncoids = NULL;
182  rustate->hashfunctions = NULL;
183  rustate->hashtable = NULL;
184  rustate->tempContext = NULL;
185  rustate->tableContext = NULL;
186 
187  /* initialize processing state */
188  rustate->recursing = false;
189  rustate->intermediate_empty = true;
190  rustate->working_table = tuplestore_begin_heap(false, false, work_mem);
191  rustate->intermediate_table = tuplestore_begin_heap(false, false, work_mem);
192 
193  /*
194  * If hashing, we need a per-tuple memory context for comparisons, and a
195  * longer-lived context to store the hash table. The table can't just be
196  * kept in the per-query context because we want to be able to throw it
197  * away when rescanning.
198  */
199  if (node->numCols > 0)
200  {
201  rustate->tempContext =
203  "RecursiveUnion",
205  rustate->tableContext =
207  "RecursiveUnion hash table",
209  }
210 
211  /*
212  * Make the state structure available to descendant WorkTableScan nodes
213  * via the Param slot reserved for it.
214  */
215  prmdata = &(estate->es_param_exec_vals[node->wtParam]);
216  Assert(prmdata->execPlan == NULL);
217  prmdata->value = PointerGetDatum(rustate);
218  prmdata->isnull = false;
219 
220  /*
221  * Miscellaneous initialization
222  *
223  * RecursiveUnion plans don't have expression contexts because they never
224  * call ExecQual or ExecProject.
225  */
226  Assert(node->plan.qual == NIL);
227 
228  /*
229  * RecursiveUnion nodes still have Result slots, which hold pointers to
230  * tuples, so we have to initialize them.
231  */
232  ExecInitResultTupleSlotTL(estate, &rustate->ps);
233 
234  /*
235  * Initialize result tuple type. (Note: we have to set up the result type
236  * before initializing child nodes, because nodeWorktablescan.c expects it
237  * to be valid.)
238  */
239  rustate->ps.ps_ProjInfo = NULL;
240 
241  /*
242  * initialize child nodes
243  */
244  outerPlanState(rustate) = ExecInitNode(outerPlan(node), estate, eflags);
245  innerPlanState(rustate) = ExecInitNode(innerPlan(node), estate, eflags);
246 
247  /*
248  * If hashing, precompute fmgr lookup data for inner loop, and create the
249  * hash table.
250  */
251  if (node->numCols > 0)
252  {
254  node->dupOperators,
255  &rustate->eqfuncoids,
256  &rustate->hashfunctions);
257  build_hash_table(rustate);
258  }
259 
260  return rustate;
261 }
#define NIL
Definition: pg_list.h:69
List * qual
Definition: plannodes.h:145
void execTuplesHashPrepare(int numCols, Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
Definition: execGrouping.c:95
void * execPlan
Definition: params.h:147
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:903
Tuplestorestate * intermediate_table
Definition: execnodes.h:1072
#define PointerGetDatum(X)
Definition: postgres.h:539
FmgrInfo * hashfunctions
Definition: execnodes.h:1075
EState * state
Definition: execnodes.h:870
ParamExecData * es_param_exec_vals
Definition: execnodes.h:483
bool isnull
Definition: params.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
#define EXEC_FLAG_BACKWARD
Definition: executor.h:61
MemoryContext tempContext
Definition: execnodes.h:1076
#define outerPlanState(node)
Definition: execnodes.h:914
#define innerPlan(node)
Definition: plannodes.h:173
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
TupleHashTable hashtable
Definition: execnodes.h:1077
static TupleTableSlot * ExecRecursiveUnion(PlanState *pstate)
Tuplestorestate * working_table
Definition: execnodes.h:1071
#define outerPlan(node)
Definition: plannodes.h:174
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:165
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
int work_mem
Definition: globals.c:113
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
Plan * plan
Definition: execnodes.h:868
#define makeNode(_type_)
Definition: nodes.h:561
MemoryContext tableContext
Definition: execnodes.h:1078
#define Assert(condition)
Definition: c.h:688
#define EXEC_FLAG_MARK
Definition: executor.h:62
Oid * dupOperators
Definition: plannodes.h:290
static void build_hash_table(RecursiveUnionState *rustate)
Datum value
Definition: params.h:148
#define innerPlanState(node)
Definition: execnodes.h:913
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139

◆ ExecReScanRecursiveUnion()

void ExecReScanRecursiveUnion ( RecursiveUnionState node)

Definition at line 301 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().

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