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 579 of file nodeSetOp.c.

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

Referenced by ExecEndNode().

580 {
581  /* clean up tuple table */
583 
584  /* free subsidiary stuff including hashtable */
585  if (node->tableContext)
587  ExecFreeExprContext(&node->ps);
588 
590 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:198
MemoryContext tableContext
Definition: execnodes.h:2095
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:539
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
PlanState ps
Definition: execnodes.h:2084
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:561
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:901
#define outerPlanState(node)
Definition: execnodes.h:914

◆ ExecInitSetOp()

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

Definition at line 480 of file nodeSetOp.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, build_hash_table(), CurrentMemoryContext, SetOp::dupColIdx, SetOp::dupOperators, SetOpState::eqfuncoids, SetOpState::eqfunction, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAssignExprContext(), ExecGetResultType(), ExecInitNode(), ExecInitResultTupleSlotTL(), 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, and SetOpState::tableContext.

Referenced by ExecInitNode().

481 {
482  SetOpState *setopstate;
483  TupleDesc outerDesc;
484 
485  /* check for unsupported flags */
486  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
487 
488  /*
489  * create state structure
490  */
491  setopstate = makeNode(SetOpState);
492  setopstate->ps.plan = (Plan *) node;
493  setopstate->ps.state = estate;
494  setopstate->ps.ExecProcNode = ExecSetOp;
495 
496  setopstate->eqfuncoids = NULL;
497  setopstate->hashfunctions = NULL;
498  setopstate->setop_done = false;
499  setopstate->numOutput = 0;
500  setopstate->pergroup = NULL;
501  setopstate->grp_firstTuple = NULL;
502  setopstate->hashtable = NULL;
503  setopstate->tableContext = NULL;
504 
505  /*
506  * create expression context
507  */
508  ExecAssignExprContext(estate, &setopstate->ps);
509 
510  /*
511  * If hashing, we also need a longer-lived context to store the hash
512  * table. The table can't just be kept in the per-query context because
513  * we want to be able to throw it away in ExecReScanSetOp.
514  */
515  if (node->strategy == SETOP_HASHED)
516  setopstate->tableContext =
518  "SetOp hash table",
520 
521  /*
522  * initialize child nodes
523  *
524  * If we are hashing then the child plan does not need to handle REWIND
525  * efficiently; see ExecReScanSetOp.
526  */
527  if (node->strategy == SETOP_HASHED)
528  eflags &= ~EXEC_FLAG_REWIND;
529  outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
530  outerDesc = ExecGetResultType(outerPlanState(setopstate));
531 
532  /*
533  * Initialize result slot and type. Setop nodes do no projections, so
534  * initialize projection info for this node appropriately.
535  */
536  ExecInitResultTupleSlotTL(estate, &setopstate->ps);
537  setopstate->ps.ps_ProjInfo = NULL;
538 
539  /*
540  * Precompute fmgr lookup data for inner loop. We need both equality and
541  * hashing functions to do it by hashing, but only equality if not
542  * hashing.
543  */
544  if (node->strategy == SETOP_HASHED)
546  node->dupOperators,
547  &setopstate->eqfuncoids,
548  &setopstate->hashfunctions);
549  else
550  setopstate->eqfunction =
551  execTuplesMatchPrepare(outerDesc,
552  node->numCols,
553  node->dupColIdx,
554  node->dupOperators,
555  &setopstate->ps);
556 
557  if (node->strategy == SETOP_HASHED)
558  {
559  build_hash_table(setopstate);
560  setopstate->table_filled = false;
561  }
562  else
563  {
564  setopstate->pergroup =
566  }
567 
568  return setopstate;
569 }
void execTuplesHashPrepare(int numCols, Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
Definition: execGrouping.c:95
SetOpStrategy strategy
Definition: plannodes.h:901
MemoryContext tableContext
Definition: execnodes.h:2095
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:903
struct SetOpStatePerGroupData * SetOpStatePerGroup
Definition: execnodes.h:2080
ExprState * eqfunction
Definition: execnodes.h:2085
Oid * eqfuncoids
Definition: execnodes.h:2086
PlanState ps
Definition: execnodes.h:2084
AttrNumber * dupColIdx
Definition: plannodes.h:904
HeapTuple grp_firstTuple
Definition: execnodes.h:2092
EState * state
Definition: execnodes.h:870
int numCols
Definition: plannodes.h:902
static void build_hash_table(SetOpState *setopstate)
Definition: nodeSetOp.c:120
Oid * dupOperators
Definition: plannodes.h:905
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
#define EXEC_FLAG_BACKWARD
Definition: executor.h:61
#define outerPlanState(node)
Definition: execnodes.h:914
bool table_filled
Definition: execnodes.h:2096
long numOutput
Definition: execnodes.h:2089
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define EXEC_FLAG_REWIND
Definition: executor.h:60
#define outerPlan(node)
Definition: plannodes.h:174
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:188
#define AllocSetContextCreate(parent, name, allocparams)
Definition: memutils.h:165
void * palloc0(Size size)
Definition: mcxt.c:864
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:874
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:870
FmgrInfo * hashfunctions
Definition: execnodes.h:2087
Plan * plan
Definition: execnodes.h:868
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, AttrNumber *keyColIdx, Oid *eqOperators, PlanState *parent)
Definition: execGrouping.c:60
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
#define EXEC_FLAG_MARK
Definition: executor.h:62
bool setop_done
Definition: execnodes.h:2088
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:425
SetOpStatePerGroup pergroup
Definition: execnodes.h:2091
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:435
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
TupleHashTable hashtable
Definition: execnodes.h:2094

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)

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

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