PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 681 of file nodeSetOp.c.

682{
683 /* free subsidiary stuff including hashtable */
684 if (node->tableContext)
686
689}
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1255
#define innerPlanState(node)
Definition: execnodes.h:1254
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:485
MemoryContext tableContext
Definition: execnodes.h:2869

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

Referenced by ExecEndNode().

◆ ExecInitSetOp()

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

Definition at line 564 of file nodeSetOp.c.

565{
566 SetOpState *setopstate;
567
568 /* check for unsupported flags */
570
571 /*
572 * create state structure
573 */
574 setopstate = makeNode(SetOpState);
575 setopstate->ps.plan = (Plan *) node;
576 setopstate->ps.state = estate;
577 setopstate->ps.ExecProcNode = ExecSetOp;
578
579 setopstate->setop_done = false;
580 setopstate->numOutput = 0;
581 setopstate->numCols = node->numCols;
582 setopstate->need_init = true;
583
584 /*
585 * create expression context
586 */
587 ExecAssignExprContext(estate, &setopstate->ps);
588
589 /*
590 * If hashing, we also need a longer-lived context to store the hash
591 * table. The table can't just be kept in the per-query context because
592 * we want to be able to throw it away in ExecReScanSetOp.
593 */
594 if (node->strategy == SETOP_HASHED)
595 setopstate->tableContext =
597 "SetOp hash table",
599
600 /*
601 * initialize child nodes
602 *
603 * If we are hashing then the child plans do not need to handle REWIND
604 * efficiently; see ExecReScanSetOp.
605 */
606 if (node->strategy == SETOP_HASHED)
607 eflags &= ~EXEC_FLAG_REWIND;
608 outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
609 innerPlanState(setopstate) = ExecInitNode(innerPlan(node), estate, eflags);
610
611 /*
612 * Initialize locally-allocated slots. In hashed mode, we just need a
613 * result slot. In sorted mode, we need one first-tuple-of-group slot for
614 * each input; we use the result slot for the left input's slot and create
615 * another for the right input. (Note: the nextTupleSlot slots are not
616 * ours, but just point to the last slot returned by the input plan node.)
617 */
619 if (node->strategy != SETOP_HASHED)
620 {
621 setopstate->leftInput.firstTupleSlot =
622 setopstate->ps.ps_ResultTupleSlot;
623 setopstate->rightInput.firstTupleSlot =
625 setopstate->ps.ps_ResultTupleDesc,
627 }
628
629 /* Setop nodes do no projections. */
630 setopstate->ps.ps_ProjInfo = NULL;
631
632 /*
633 * Precompute fmgr lookup data for inner loop. We need equality and
634 * hashing functions to do it by hashing, while for sorting we need
635 * SortSupport data.
636 */
637 if (node->strategy == SETOP_HASHED)
639 node->cmpOperators,
640 &setopstate->eqfuncoids,
641 &setopstate->hashfunctions);
642 else
643 {
644 int nkeys = node->numCols;
645
646 setopstate->sortKeys = (SortSupport)
647 palloc0(nkeys * sizeof(SortSupportData));
648 for (int i = 0; i < nkeys; i++)
649 {
650 SortSupport sortKey = setopstate->sortKeys + i;
651
653 sortKey->ssup_collation = node->cmpCollations[i];
654 sortKey->ssup_nulls_first = node->cmpNullsFirst[i];
655 sortKey->ssup_attno = node->cmpColIdx[i];
656 /* abbreviated key conversion is not useful here */
657 sortKey->abbreviate = false;
658
659 PrepareSortSupportFromOrderingOp(node->cmpOperators[i], sortKey);
660 }
661 }
662
663 /* Create a hash table if needed */
664 if (node->strategy == SETOP_HASHED)
665 {
666 build_hash_table(setopstate);
667 setopstate->table_filled = false;
668 }
669
670 return setopstate;
671}
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
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:2020
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1988
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:486
#define EXEC_FLAG_BACKWARD
Definition: executor.h:69
#define EXEC_FLAG_MARK
Definition: executor.h:70
Assert(PointerIsAligned(start, uint64))
int i
Definition: isn.c:77
void * palloc0(Size size)
Definition: mcxt.c:1973
MemoryContext CurrentMemoryContext
Definition: mcxt.c:159
#define AllocSetContextCreate
Definition: memutils.h:149
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:180
static void build_hash_table(SetOpState *setopstate)
Definition: nodeSetOp.c:84
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:160
@ SETOP_HASHED
Definition: nodes.h:413
#define makeNode(_type_)
Definition: nodes.h:161
#define innerPlan(node)
Definition: plannodes.h:240
#define outerPlan(node)
Definition: plannodes.h:241
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
Definition: sortsupport.c:134
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
Plan * plan
Definition: execnodes.h:1159
EState * state
Definition: execnodes.h:1161
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1196
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1197
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1199
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1165
TupleTableSlot * firstTupleSlot
Definition: execnodes.h:2846
bool need_init
Definition: execnodes.h:2863
SortSupport sortKeys
Definition: execnodes.h:2860
bool table_filled
Definition: execnodes.h:2870
SetOpStatePerInput rightInput
Definition: execnodes.h:2862
PlanState ps
Definition: execnodes.h:2854
Oid * eqfuncoids
Definition: execnodes.h:2866
FmgrInfo * hashfunctions
Definition: execnodes.h:2867
SetOpStatePerInput leftInput
Definition: execnodes.h:2861
int64 numOutput
Definition: execnodes.h:2856
bool setop_done
Definition: execnodes.h:2855
SetOpStrategy strategy
Definition: plannodes.h:1383
int numCols
Definition: plannodes.h:1386
AttrNumber ssup_attno
Definition: sortsupport.h:81
bool ssup_nulls_first
Definition: sortsupport.h:75
MemoryContext ssup_cxt
Definition: sortsupport.h:66

References SortSupportData::abbreviate, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), build_hash_table(), CurrentMemoryContext, SetOpState::eqfuncoids, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, ExecSetOp(), execTuplesHashPrepare(), SetOpStatePerInput::firstTupleSlot, SetOpState::hashfunctions, i, innerPlan, innerPlanState, SetOpState::leftInput, makeNode, SetOpState::need_init, SetOpState::numCols, SetOp::numCols, SetOpState::numOutput, outerPlan, outerPlanState, palloc0(), PlanState::plan, PrepareSortSupportFromOrderingOp(), SetOpState::ps, PlanState::ps_ProjInfo, PlanState::ps_ResultTupleDesc, PlanState::ps_ResultTupleSlot, SetOpState::rightInput, SetOpState::setop_done, SETOP_HASHED, SetOpState::sortKeys, SortSupportData::ssup_attno, SortSupportData::ssup_collation, SortSupportData::ssup_cxt, SortSupportData::ssup_nulls_first, PlanState::state, SetOp::strategy, SetOpState::table_filled, SetOpState::tableContext, and TTSOpsMinimalTuple.

Referenced by ExecInitNode().

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)

Definition at line 693 of file nodeSetOp.c.

694{
697
699 node->setop_done = false;
700 node->numOutput = 0;
701
702 if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
703 {
704 /*
705 * In the hashed case, if we haven't yet built the hash table then we
706 * can just return; nothing done yet, so nothing to undo. If subnode's
707 * chgParam is not NULL then it will be re-scanned by ExecProcNode,
708 * else no reason to re-scan it at all.
709 */
710 if (!node->table_filled)
711 return;
712
713 /*
714 * If we do have the hash table and the subplans do not have any
715 * parameter changes, then we can just rescan the existing hash table;
716 * no need to build it again.
717 */
718 if (outerPlan->chgParam == NULL && innerPlan->chgParam == NULL)
719 {
721 return;
722 }
723
724 /* Release any hashtable storage */
725 if (node->tableContext)
727
728 /* And rebuild an empty hashtable */
730 node->table_filled = false;
731 }
732 else
733 {
734 /* Need to re-read first input from each side */
735 node->need_init = true;
736 }
737
738 /*
739 * if chgParam of subnode is not null then plan will be re-scanned by
740 * first ExecProcNode.
741 */
742 if (outerPlan->chgParam == NULL)
744 if (innerPlan->chgParam == NULL)
746}
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
void ResetTupleHashTable(TupleHashTable hashtable)
Definition: execGrouping.c:274
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:891
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:414
TupleHashIterator hashiter
Definition: execnodes.h:2871
TupleHashTable hashtable
Definition: execnodes.h:2868
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:458

References ExecClearTuple(), ExecReScan(), SetOpState::hashiter, SetOpState::hashtable, innerPlan, innerPlanState, MemoryContextReset(), SetOpState::need_init, 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().