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

584 {
585  /* free subsidiary stuff including hashtable */
586  if (node->tableContext)
588 
590 }
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define outerPlanState(node)
Definition: execnodes.h:1214
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
MemoryContext tableContext
Definition: execnodes.h:2792

References ExecEndNode(), MemoryContextDelete(), outerPlanState, and SetOpState::tableContext.

Referenced by ExecEndNode().

◆ ExecInitSetOp()

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

Definition at line 481 of file nodeSetOp.c.

482 {
483  SetOpState *setopstate;
484  TupleDesc outerDesc;
485 
486  /* check for unsupported flags */
487  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
488 
489  /*
490  * create state structure
491  */
492  setopstate = makeNode(SetOpState);
493  setopstate->ps.plan = (Plan *) node;
494  setopstate->ps.state = estate;
495  setopstate->ps.ExecProcNode = ExecSetOp;
496 
497  setopstate->eqfuncoids = NULL;
498  setopstate->hashfunctions = NULL;
499  setopstate->setop_done = false;
500  setopstate->numOutput = 0;
501  setopstate->pergroup = NULL;
502  setopstate->grp_firstTuple = NULL;
503  setopstate->hashtable = NULL;
504  setopstate->tableContext = NULL;
505 
506  /*
507  * create expression context
508  */
509  ExecAssignExprContext(estate, &setopstate->ps);
510 
511  /*
512  * If hashing, we also need a longer-lived context to store the hash
513  * table. The table can't just be kept in the per-query context because
514  * we want to be able to throw it away in ExecReScanSetOp.
515  */
516  if (node->strategy == SETOP_HASHED)
517  setopstate->tableContext =
519  "SetOp hash table",
521 
522  /*
523  * initialize child nodes
524  *
525  * If we are hashing then the child plan does not need to handle REWIND
526  * efficiently; see ExecReScanSetOp.
527  */
528  if (node->strategy == SETOP_HASHED)
529  eflags &= ~EXEC_FLAG_REWIND;
530  outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
531  outerDesc = ExecGetResultType(outerPlanState(setopstate));
532 
533  /*
534  * Initialize result slot and type. Setop nodes do no projections, so
535  * initialize projection info for this node appropriately.
536  */
537  ExecInitResultTupleSlotTL(&setopstate->ps,
538  node->strategy == SETOP_HASHED ?
540  setopstate->ps.ps_ProjInfo = NULL;
541 
542  /*
543  * Precompute fmgr lookup data for inner loop. We need both equality and
544  * hashing functions to do it by hashing, but only equality if not
545  * hashing.
546  */
547  if (node->strategy == SETOP_HASHED)
549  node->dupOperators,
550  &setopstate->eqfuncoids,
551  &setopstate->hashfunctions);
552  else
553  setopstate->eqfunction =
554  execTuplesMatchPrepare(outerDesc,
555  node->numCols,
556  node->dupColIdx,
557  node->dupOperators,
558  node->dupCollations,
559  &setopstate->ps);
560 
561  if (node->strategy == SETOP_HASHED)
562  {
563  build_hash_table(setopstate);
564  setopstate->table_filled = false;
565  }
566  else
567  {
568  setopstate->pergroup =
570  }
571 
572  return setopstate;
573 }
#define Assert(condition)
Definition: c.h:858
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
Definition: execGrouping.c:95
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:58
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1886
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:85
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:493
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:483
struct SetOpStatePerGroupData * SetOpStatePerGroup
Definition: execnodes.h:2777
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_REWIND
Definition: executor.h:67
#define EXEC_FLAG_MARK
Definition: executor.h:69
void * palloc0(Size size)
Definition: mcxt.c:1346
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(SetOpState *setopstate)
Definition: nodeSetOp.c:120
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:190
@ SETOP_HASHED
Definition: nodes.h:406
#define makeNode(_type_)
Definition: nodes.h:155
#define outerPlan(node)
Definition: plannodes.h:182
Plan * plan
Definition: execnodes.h:1118
EState * state
Definition: execnodes.h:1120
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1158
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1124
long numOutput
Definition: execnodes.h:2786
HeapTuple grp_firstTuple
Definition: execnodes.h:2789
SetOpStatePerGroup pergroup
Definition: execnodes.h:2788
ExprState * eqfunction
Definition: execnodes.h:2782
bool table_filled
Definition: execnodes.h:2793
PlanState ps
Definition: execnodes.h:2781
Oid * eqfuncoids
Definition: execnodes.h:2783
TupleHashTable hashtable
Definition: execnodes.h:2791
FmgrInfo * hashfunctions
Definition: execnodes.h:2784
bool setop_done
Definition: execnodes.h:2785
SetOpStrategy strategy
Definition: plannodes.h:1225
int numCols
Definition: plannodes.h:1228

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, build_hash_table(), CurrentMemoryContext, 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, SetOpState::tableContext, TTSOpsHeapTuple, and TTSOpsMinimalTuple.

Referenced by ExecInitNode().

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)

Definition at line 594 of file nodeSetOp.c.

595 {
597 
599  node->setop_done = false;
600  node->numOutput = 0;
601 
602  if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
603  {
604  /*
605  * In the hashed case, if we haven't yet built the hash table then we
606  * can just return; nothing done yet, so nothing to undo. If subnode's
607  * chgParam is not NULL then it will be re-scanned by ExecProcNode,
608  * else no reason to re-scan it at all.
609  */
610  if (!node->table_filled)
611  return;
612 
613  /*
614  * If we do have the hash table and the subplan does not have any
615  * parameter changes, then we can just rescan the existing hash table;
616  * no need to build it again.
617  */
618  if (outerPlan->chgParam == NULL)
619  {
621  return;
622  }
623  }
624 
625  /* Release first tuple of group, if we have made a copy */
626  if (node->grp_firstTuple != NULL)
627  {
629  node->grp_firstTuple = NULL;
630  }
631 
632  /* Release any hashtable storage */
633  if (node->tableContext)
635 
636  /* And rebuild empty hashtable if needed */
637  if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
638  {
640  node->table_filled = false;
641  }
642 
643  /*
644  * if chgParam of subnode is not null then plan will be re-scanned by
645  * first ExecProcNode.
646  */
647  if (outerPlan->chgParam == NULL)
649 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void ResetTupleHashTable(TupleHashTable hashtable)
Definition: execGrouping.c:284
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:846
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1434
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1156
TupleHashIterator hashiter
Definition: execnodes.h:2794
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:454

References ExecClearTuple(), ExecReScan(), SetOpState::grp_firstTuple, SetOpState::hashiter, SetOpState::hashtable, heap_freetuple(), MemoryContextReset(), SetOpState::numOutput, outerPlan, outerPlanState, PlanState::plan, SetOpState::ps, PlanState::ps_ResultTupleSlot, ResetTupleHashIterator, ResetTupleHashTable(), SetOpState::setop_done, SETOP_HASHED, SetOpState::table_filled, and SetOpState::tableContext.

Referenced by ExecReScan().