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.

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

Referenced by ExecEndNode().

584 {
585  /* clean up tuple table */
587 
588  /* free subsidiary stuff including hashtable */
589  if (node->tableContext)
591  ExecFreeExprContext(&node->ps);
592 
594 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
MemoryContext tableContext
Definition: execnodes.h:2307
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
PlanState ps
Definition: execnodes.h:2296
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:614
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
#define outerPlanState(node)
Definition: execnodes.h:1034

◆ ExecInitSetOp()

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

Definition at line 481 of file nodeSetOp.c.

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

Referenced by ExecInitNode().

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 }
SetOpStrategy strategy
Definition: plannodes.h:931
#define AllocSetContextCreate
Definition: memutils.h:170
MemoryContext tableContext
Definition: execnodes.h:2307
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:980
struct SetOpStatePerGroupData * SetOpStatePerGroup
Definition: execnodes.h:2292
ExprState * eqfunction
Definition: execnodes.h:2297
Oid * eqfuncoids
Definition: execnodes.h:2298
Oid * dupCollations
Definition: plannodes.h:936
PlanState ps
Definition: execnodes.h:2296
AttrNumber * dupColIdx
Definition: plannodes.h:934
HeapTuple grp_firstTuple
Definition: execnodes.h:2304
EState * state
Definition: execnodes.h:942
int numCols
Definition: plannodes.h:932
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
Definition: execGrouping.c:96
static void build_hash_table(SetOpState *setopstate)
Definition: nodeSetOp.c:120
Oid * dupOperators
Definition: plannodes.h:935
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1034
bool table_filled
Definition: execnodes.h:2308
long numOutput
Definition: execnodes.h:2301
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define EXEC_FLAG_REWIND
Definition: executor.h:57
#define outerPlan(node)
Definition: plannodes.h:170
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:190
void * palloc0(Size size)
Definition: mcxt.c:980
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:946
FmgrInfo * hashfunctions
Definition: execnodes.h:2299
Plan * plan
Definition: execnodes.h:940
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:732
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:59
#define EXEC_FLAG_MARK
Definition: executor.h:59
bool setop_done
Definition: execnodes.h:2300
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:444
SetOpStatePerGroup pergroup
Definition: execnodes.h:2303
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1764
TupleDesc ExecGetResultType(PlanState *planstate)
Definition: execUtils.c:454
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:85
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
TupleHashTable hashtable
Definition: execnodes.h:2306

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)

Definition at line 598 of file nodeSetOp.c.

References 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, ResetTupleHashTable(), SetOpState::setop_done, SETOP_HASHED, SetOpState::table_filled, and SetOpState::tableContext.

Referenced by ExecReScan().

599 {
601  node->setop_done = false;
602  node->numOutput = 0;
603 
604  if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
605  {
606  /*
607  * In the hashed case, if we haven't yet built the hash table then we
608  * can just return; nothing done yet, so nothing to undo. If subnode's
609  * chgParam is not NULL then it will be re-scanned by ExecProcNode,
610  * else no reason to re-scan it at all.
611  */
612  if (!node->table_filled)
613  return;
614 
615  /*
616  * If we do have the hash table and the subplan does not have any
617  * parameter changes, then we can just rescan the existing hash table;
618  * no need to build it again.
619  */
620  if (node->ps.lefttree->chgParam == NULL)
621  {
623  return;
624  }
625  }
626 
627  /* Release first tuple of group, if we have made a copy */
628  if (node->grp_firstTuple != NULL)
629  {
631  node->grp_firstTuple = NULL;
632  }
633 
634  /* Release any hashtable storage */
635  if (node->tableContext)
637 
638  /* And rebuild empty hashtable if needed */
639  if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
640  {
642  node->table_filled = false;
643  }
644 
645  /*
646  * if chgParam of subnode is not null then plan will be re-scanned by
647  * first ExecProcNode.
648  */
649  if (node->ps.lefttree->chgParam == NULL)
650  ExecReScan(node->ps.lefttree);
651 }
MemoryContext tableContext
Definition: execnodes.h:2307
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:426
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
PlanState ps
Definition: execnodes.h:2296
HeapTuple grp_firstTuple
Definition: execnodes.h:2304
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
void ResetTupleHashTable(TupleHashTable hashtable)
Definition: execGrouping.c:282
struct PlanState * lefttree
Definition: execnodes.h:962
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:978
bool table_filled
Definition: execnodes.h:2308
long numOutput
Definition: execnodes.h:2301
TupleHashIterator hashiter
Definition: execnodes.h:2309
Bitmapset * chgParam
Definition: execnodes.h:972
#define MemoryContextResetAndDeleteChildren(ctx)
Definition: memutils.h:67
Plan * plan
Definition: execnodes.h:940
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:722
bool setop_done
Definition: execnodes.h:2300
TupleHashTable hashtable
Definition: execnodes.h:2306