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 279 of file nodeRecursiveunion.c.

280 {
281  /* Release tuplestores */
284 
285  /* free subsidiary stuff including hashtable */
286  if (node->tempContext)
288  if (node->tableContext)
290 
291  /*
292  * close down subplans
293  */
296 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1224
#define innerPlanState(node)
Definition: execnodes.h:1223
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
MemoryContext tempContext
Definition: execnodes.h:1527
MemoryContext tableContext
Definition: execnodes.h:1529
Tuplestorestate * working_table
Definition: execnodes.h:1522
Tuplestorestate * intermediate_table
Definition: execnodes.h:1523
void tuplestore_end(Tuplestorestate *state)
Definition: tuplestore.c:492

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

Referenced by ExecEndNode().

◆ ExecInitRecursiveUnion()

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

Definition at line 174 of file nodeRecursiveunion.c.

175 {
176  RecursiveUnionState *rustate;
177  ParamExecData *prmdata;
178 
179  /* check for unsupported flags */
180  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
181 
182  /*
183  * create state structure
184  */
185  rustate = makeNode(RecursiveUnionState);
186  rustate->ps.plan = (Plan *) node;
187  rustate->ps.state = estate;
189 
190  rustate->eqfuncoids = NULL;
191  rustate->hashfunctions = NULL;
192  rustate->hashtable = NULL;
193  rustate->tempContext = NULL;
194  rustate->tableContext = NULL;
195 
196  /* initialize processing state */
197  rustate->recursing = false;
198  rustate->intermediate_empty = true;
199  rustate->working_table = tuplestore_begin_heap(false, false, work_mem);
200  rustate->intermediate_table = tuplestore_begin_heap(false, false, work_mem);
201 
202  /*
203  * If hashing, we need a per-tuple memory context for comparisons, and a
204  * longer-lived context to store the hash table. The table can't just be
205  * kept in the per-query context because we want to be able to throw it
206  * away when rescanning.
207  */
208  if (node->numCols > 0)
209  {
210  rustate->tempContext =
212  "RecursiveUnion",
214  rustate->tableContext =
216  "RecursiveUnion hash table",
218  }
219 
220  /*
221  * Make the state structure available to descendant WorkTableScan nodes
222  * via the Param slot reserved for it.
223  */
224  prmdata = &(estate->es_param_exec_vals[node->wtParam]);
225  Assert(prmdata->execPlan == NULL);
226  prmdata->value = PointerGetDatum(rustate);
227  prmdata->isnull = false;
228 
229  /*
230  * Miscellaneous initialization
231  *
232  * RecursiveUnion plans don't have expression contexts because they never
233  * call ExecQual or ExecProject.
234  */
235  Assert(node->plan.qual == NIL);
236 
237  /*
238  * RecursiveUnion nodes still have Result slots, which hold pointers to
239  * tuples, so we have to initialize them.
240  */
241  ExecInitResultTypeTL(&rustate->ps);
242 
243  /*
244  * Initialize result tuple type. (Note: we have to set up the result type
245  * before initializing child nodes, because nodeWorktablescan.c expects it
246  * to be valid.)
247  */
248  rustate->ps.ps_ProjInfo = NULL;
249 
250  /*
251  * initialize child nodes
252  */
253  outerPlanState(rustate) = ExecInitNode(outerPlan(node), estate, eflags);
254  innerPlanState(rustate) = ExecInitNode(innerPlan(node), estate, eflags);
255 
256  /*
257  * If hashing, precompute fmgr lookup data for inner loop, and create the
258  * hash table.
259  */
260  if (node->numCols > 0)
261  {
263  node->dupOperators,
264  &rustate->eqfuncoids,
265  &rustate->hashfunctions);
266  build_hash_table(rustate);
267  }
268 
269  return rustate;
270 }
#define Assert(condition)
Definition: c.h:861
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
Definition: execGrouping.c:97
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1842
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
int work_mem
Definition: globals.c:130
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
static void build_hash_table(RecursiveUnionState *rustate)
static TupleTableSlot * ExecRecursiveUnion(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:155
#define NIL
Definition: pg_list.h:68
#define innerPlan(node)
Definition: plannodes.h:182
#define outerPlan(node)
Definition: plannodes.h:183
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
ParamExecData * es_param_exec_vals
Definition: execnodes.h:670
bool isnull
Definition: params.h:150
Datum value
Definition: params.h:149
void * execPlan
Definition: params.h:148
Plan * plan
Definition: execnodes.h:1128
EState * state
Definition: execnodes.h:1130
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1168
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1134
List * qual
Definition: plannodes.h:154
FmgrInfo * hashfunctions
Definition: execnodes.h:1526
TupleHashTable hashtable
Definition: execnodes.h:1528
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:330

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

◆ ExecReScanRecursiveUnion()

void ExecReScanRecursiveUnion ( RecursiveUnionState node)

Definition at line 305 of file nodeRecursiveunion.c.

306 {
310 
311  /*
312  * Set recursive term's chgParam to tell it that we'll modify the working
313  * table and therefore it has to rescan.
314  */
315  innerPlan->chgParam = bms_add_member(innerPlan->chgParam, plan->wtParam);
316 
317  /*
318  * if chgParam of subnode is not null then plan will be re-scanned by
319  * first ExecProcNode. Because of above, we only have to do this to the
320  * non-recursive term.
321  */
322  if (outerPlan->chgParam == NULL)
324 
325  /* Release any hashtable storage */
326  if (node->tableContext)
328 
329  /* Empty hashtable if needed */
330  if (plan->numCols > 0)
332 
333  /* reset processing state */
334  node->recursing = false;
335  node->intermediate_empty = true;
338 }
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void ResetTupleHashTable(TupleHashTable hashtable)
Definition: execGrouping.c:286
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
#define plan(x)
Definition: pg_regress.c:162
void tuplestore_clear(Tuplestorestate *state)
Definition: tuplestore.c:430

References bms_add_member(), ExecReScan(), RecursiveUnionState::hashtable, innerPlan, innerPlanState, RecursiveUnionState::intermediate_empty, RecursiveUnionState::intermediate_table, MemoryContextReset(), outerPlan, outerPlanState, PlanState::plan, plan, RecursiveUnionState::ps, RecursiveUnionState::recursing, ResetTupleHashTable(), RecursiveUnionState::tableContext, tuplestore_clear(), and RecursiveUnionState::working_table.

Referenced by ExecReScan().