PostgreSQL Source Code  git master
nodeSetOp.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeSetOp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

SetOpStateExecInitSetOp (SetOp *node, EState *estate, int eflags)
 
void ExecEndSetOp (SetOpState *node)
 
void ExecReScanSetOp (SetOpState *node)
 

Function Documentation

◆ ExecEndSetOp()

void ExecEndSetOp ( SetOpState node)

Definition at line 582 of file nodeSetOp.c.

References ExecClearTuple(), ExecEndNode(), MemoryContextDelete(), outerPlanState, SetOpState::ps, PlanState::ps_ResultTupleSlot, SetOpState::tableContext, and SetOpState::tempContext.

Referenced by ExecEndNode().

583 {
584  /* clean up tuple table */
586 
587  /* free subsidiary stuff including hashtable */
589  if (node->tableContext)
591 
593 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:200
MemoryContext tableContext
Definition: execnodes.h:2020
MemoryContext tempContext
Definition: execnodes.h:2014
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
PlanState ps
Definition: execnodes.h:2009
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:882
#define outerPlanState(node)
Definition: execnodes.h:895

◆ ExecInitSetOp()

SetOpState* ExecInitSetOp ( SetOp node,
EState estate,
int  eflags 
)

Definition at line 476 of file nodeSetOp.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate(), Assert, build_hash_table(), CurrentMemoryContext, SetOp::dupOperators, SetOpState::eqfunctions, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAssignResultTypeFromTL(), ExecInitNode(), ExecInitResultTupleSlot(), PlanState::ExecProcNode, ExecSetOp(), execTuplesHashPrepare(), execTuplesMatchPrepare(), SetOpState::grp_firstTuple, SetOpState::hashfunctions, SetOpState::hashtable, makeNode, SetOp::numCols, SetOpState::numOutput, outerPlan, outerPlanState, palloc0(), SetOpState::pergroup, PlanState::plan, SetOpState::ps, PlanState::ps_ProjInfo, SetOpState::setop_done, SETOP_HASHED, PlanState::state, SetOp::strategy, SetOpState::table_filled, SetOpState::tableContext, and SetOpState::tempContext.

Referenced by ExecInitNode().

477 {
478  SetOpState *setopstate;
479 
480  /* check for unsupported flags */
481  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
482 
483  /*
484  * create state structure
485  */
486  setopstate = makeNode(SetOpState);
487  setopstate->ps.plan = (Plan *) node;
488  setopstate->ps.state = estate;
489  setopstate->ps.ExecProcNode = ExecSetOp;
490 
491  setopstate->eqfunctions = NULL;
492  setopstate->hashfunctions = NULL;
493  setopstate->setop_done = false;
494  setopstate->numOutput = 0;
495  setopstate->pergroup = NULL;
496  setopstate->grp_firstTuple = NULL;
497  setopstate->hashtable = NULL;
498  setopstate->tableContext = NULL;
499 
500  /*
501  * Miscellaneous initialization
502  *
503  * SetOp nodes have no ExprContext initialization because they never call
504  * ExecQual or ExecProject. But they do need a per-tuple memory context
505  * anyway for calling execTuplesMatch.
506  */
507  setopstate->tempContext =
509  "SetOp",
511 
512  /*
513  * If hashing, we also need a longer-lived context to store the hash
514  * table. The table can't just be kept in the per-query context because
515  * we want to be able to throw it away in ExecReScanSetOp.
516  */
517  if (node->strategy == SETOP_HASHED)
518  setopstate->tableContext =
520  "SetOp hash table",
522 
523  /*
524  * Tuple table initialization
525  */
526  ExecInitResultTupleSlot(estate, &setopstate->ps);
527 
528  /*
529  * initialize child nodes
530  *
531  * If we are hashing then the child plan does not need to handle REWIND
532  * efficiently; see ExecReScanSetOp.
533  */
534  if (node->strategy == SETOP_HASHED)
535  eflags &= ~EXEC_FLAG_REWIND;
536  outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
537 
538  /*
539  * setop nodes do no projections, so initialize projection info for this
540  * node appropriately
541  */
542  ExecAssignResultTypeFromTL(&setopstate->ps);
543  setopstate->ps.ps_ProjInfo = NULL;
544 
545  /*
546  * Precompute fmgr lookup data for inner loop. We need both equality and
547  * hashing functions to do it by hashing, but only equality if not
548  * hashing.
549  */
550  if (node->strategy == SETOP_HASHED)
552  node->dupOperators,
553  &setopstate->eqfunctions,
554  &setopstate->hashfunctions);
555  else
556  setopstate->eqfunctions =
558  node->dupOperators);
559 
560  if (node->strategy == SETOP_HASHED)
561  {
562  build_hash_table(setopstate);
563  setopstate->table_filled = false;
564  }
565  else
566  {
567  setopstate->pergroup =
569  }
570 
571  return setopstate;
572 }
SetOpStrategy strategy
Definition: plannodes.h:892
MemoryContext tableContext
Definition: execnodes.h:2020
MemoryContext tempContext
Definition: execnodes.h:2014
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:884
struct SetOpStatePerGroupData * SetOpStatePerGroup
Definition: execnodes.h:2005
PlanState ps
Definition: execnodes.h:2009
HeapTuple grp_firstTuple
Definition: execnodes.h:2017
EState * state
Definition: execnodes.h:851
int numCols
Definition: plannodes.h:893
void execTuplesHashPrepare(int numCols, Oid *eqOperators, FmgrInfo **eqFunctions, FmgrInfo **hashFunctions)
Definition: execGrouping.c:233
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:447
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
static void build_hash_table(SetOpState *setopstate)
Definition: nodeSetOp.c:120
Oid * dupOperators
Definition: plannodes.h:896
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:170
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:895
bool table_filled
Definition: execnodes.h:2021
long numOutput
Definition: execnodes.h:2013
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define EXEC_FLAG_REWIND
Definition: executor.h:59
#define outerPlan(node)
Definition: plannodes.h:174
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:184
MemoryContext AllocSetContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: aset.c:322
void * palloc0(Size size)
Definition: mcxt.c:877
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:855
FmgrInfo * hashfunctions
Definition: execnodes.h:2011
Plan * plan
Definition: execnodes.h:849
#define makeNode(_type_)
Definition: nodes.h:559
#define Assert(condition)
Definition: c.h:670
#define EXEC_FLAG_MARK
Definition: executor.h:61
bool setop_done
Definition: execnodes.h:2012
FmgrInfo * eqfunctions
Definition: execnodes.h:2010
SetOpStatePerGroup pergroup
Definition: execnodes.h:2016
FmgrInfo * execTuplesMatchPrepare(int numCols, Oid *eqOperators)
Definition: execGrouping.c:204
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
TupleHashTable hashtable
Definition: execnodes.h:2019

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)

Definition at line 597 of file nodeSetOp.c.

References build_hash_table(), PlanState::chgParam, ExecClearTuple(), ExecReScan(), SetOpState::grp_firstTuple, SetOpState::hashiter, SetOpState::hashtable, heap_freetuple(), PlanState::lefttree, MemoryContextResetAndDeleteChildren, SetOpState::numOutput, PlanState::plan, SetOpState::ps, PlanState::ps_ResultTupleSlot, ResetTupleHashIterator, SetOpState::setop_done, SETOP_HASHED, SetOpState::table_filled, and SetOpState::tableContext.

Referenced by ExecReScan().

598 {
600  node->setop_done = false;
601  node->numOutput = 0;
602 
603  if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
604  {
605  /*
606  * In the hashed case, if we haven't yet built the hash table then we
607  * can just return; nothing done yet, so nothing to undo. If subnode's
608  * chgParam is not NULL then it will be re-scanned by ExecProcNode,
609  * else no reason to re-scan it at all.
610  */
611  if (!node->table_filled)
612  return;
613 
614  /*
615  * If we do have the hash table and the subplan does not have any
616  * parameter changes, then we can just rescan the existing hash table;
617  * no need to build it again.
618  */
619  if (node->ps.lefttree->chgParam == NULL)
620  {
622  return;
623  }
624  }
625 
626  /* Release first tuple of group, if we have made a copy */
627  if (node->grp_firstTuple != NULL)
628  {
630  node->grp_firstTuple = NULL;
631  }
632 
633  /* Release any hashtable storage */
634  if (node->tableContext)
636 
637  /* And rebuild empty hashtable if needed */
638  if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
639  {
640  build_hash_table(node);
641  node->table_filled = false;
642  }
643 
644  /*
645  * if chgParam of subnode is not null then plan will be re-scanned by
646  * first ExecProcNode.
647  */
648  if (node->ps.lefttree->chgParam == NULL)
649  ExecReScan(node->ps.lefttree);
650 }
MemoryContext tableContext
Definition: execnodes.h:2020
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
PlanState ps
Definition: execnodes.h:2009
HeapTuple grp_firstTuple
Definition: execnodes.h:2017
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1373
struct PlanState * lefttree
Definition: execnodes.h:868
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:882
static void build_hash_table(SetOpState *setopstate)
Definition: nodeSetOp.c:120
bool table_filled
Definition: execnodes.h:2021
long numOutput
Definition: execnodes.h:2013
TupleHashIterator hashiter
Definition: execnodes.h:2022
Bitmapset * chgParam
Definition: execnodes.h:877
#define MemoryContextResetAndDeleteChildren(ctx)
Definition: memutils.h:67
Plan * plan
Definition: execnodes.h:849
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:634
bool setop_done
Definition: execnodes.h:2012
TupleHashTable hashtable
Definition: execnodes.h:2019