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)
 
Size EstimateSetOpHashTableSpace (double nentries, Size tupleWidth)
 

Function Documentation

◆ EstimateSetOpHashTableSpace()

Size EstimateSetOpHashTableSpace ( double  nentries,
Size  tupleWidth 
)

Definition at line 115 of file nodeSetOp.c.

116{
117 return EstimateTupleHashTableSpace(nentries,
118 tupleWidth,
119 sizeof(SetOpStatePerGroupData));
120}
Size EstimateTupleHashTableSpace(double nentries, Size tupleWidth, Size additionalsize)
Definition: execGrouping.c:321

References EstimateTupleHashTableSpace().

Referenced by create_setop_path().

◆ ExecEndSetOp()

void ExecEndSetOp ( SetOpState node)

Definition at line 691 of file nodeSetOp.c.

692{
693 /* free subsidiary stuff including hashtable data */
694 if (node->tuplesContext)
696
699}
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1261
#define innerPlanState(node)
Definition: execnodes.h:1260
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:469
MemoryContext tuplesContext
Definition: execnodes.h:2875

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

Referenced by ExecEndNode().

◆ ExecInitSetOp()

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

Definition at line 572 of file nodeSetOp.c.

573{
574 SetOpState *setopstate;
575
576 /* check for unsupported flags */
578
579 /*
580 * create state structure
581 */
582 setopstate = makeNode(SetOpState);
583 setopstate->ps.plan = (Plan *) node;
584 setopstate->ps.state = estate;
585 setopstate->ps.ExecProcNode = ExecSetOp;
586
587 setopstate->setop_done = false;
588 setopstate->numOutput = 0;
589 setopstate->numCols = node->numCols;
590 setopstate->need_init = true;
591
592 /*
593 * create expression context
594 */
595 ExecAssignExprContext(estate, &setopstate->ps);
596
597 /*
598 * If hashing, we also need a longer-lived context to store the hash
599 * table. The table can't just be kept in the per-query context because
600 * we want to be able to throw it away in ExecReScanSetOp. We can use a
601 * BumpContext to save storage, because we will have no need to delete
602 * individual table entries.
603 */
604 if (node->strategy == SETOP_HASHED)
605 setopstate->tuplesContext =
607 "SetOp hashed tuples",
609
610 /*
611 * initialize child nodes
612 *
613 * If we are hashing then the child plans do not need to handle REWIND
614 * efficiently; see ExecReScanSetOp.
615 */
616 if (node->strategy == SETOP_HASHED)
617 eflags &= ~EXEC_FLAG_REWIND;
618 outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
619 innerPlanState(setopstate) = ExecInitNode(innerPlan(node), estate, eflags);
620
621 /*
622 * Initialize locally-allocated slots. In hashed mode, we just need a
623 * result slot. In sorted mode, we need one first-tuple-of-group slot for
624 * each input; we use the result slot for the left input's slot and create
625 * another for the right input. (Note: the nextTupleSlot slots are not
626 * ours, but just point to the last slot returned by the input plan node.)
627 */
629 if (node->strategy != SETOP_HASHED)
630 {
631 setopstate->leftInput.firstTupleSlot =
632 setopstate->ps.ps_ResultTupleSlot;
633 setopstate->rightInput.firstTupleSlot =
635 setopstate->ps.ps_ResultTupleDesc,
637 }
638
639 /* Setop nodes do no projections. */
640 setopstate->ps.ps_ProjInfo = NULL;
641
642 /*
643 * Precompute fmgr lookup data for inner loop. We need equality and
644 * hashing functions to do it by hashing, while for sorting we need
645 * SortSupport data.
646 */
647 if (node->strategy == SETOP_HASHED)
649 node->cmpOperators,
650 &setopstate->eqfuncoids,
651 &setopstate->hashfunctions);
652 else
653 {
654 int nkeys = node->numCols;
655
656 setopstate->sortKeys = (SortSupport)
657 palloc0(nkeys * sizeof(SortSupportData));
658 for (int i = 0; i < nkeys; i++)
659 {
660 SortSupport sortKey = setopstate->sortKeys + i;
661
663 sortKey->ssup_collation = node->cmpCollations[i];
664 sortKey->ssup_nulls_first = node->cmpNullsFirst[i];
665 sortKey->ssup_attno = node->cmpColIdx[i];
666 /* abbreviated key conversion is not useful here */
667 sortKey->abbreviate = false;
668
669 PrepareSortSupportFromOrderingOp(node->cmpOperators[i], sortKey);
670 }
671 }
672
673 /* Create a hash table if needed */
674 if (node->strategy == SETOP_HASHED)
675 {
676 build_hash_table(setopstate);
677 setopstate->table_filled = false;
678 }
679
680 return setopstate;
681}
MemoryContext BumpContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition: bump.c:133
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
Definition: execGrouping.c:100
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:485
#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:1395
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
static void build_hash_table(SetOpState *setopstate)
Definition: nodeSetOp.c:84
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:168
@ SETOP_HASHED
Definition: nodes.h:417
#define makeNode(_type_)
Definition: nodes.h:161
#define innerPlan(node)
Definition: plannodes.h:260
#define outerPlan(node)
Definition: plannodes.h:261
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
Definition: sortsupport.c:134
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
Plan * plan
Definition: execnodes.h:1165
EState * state
Definition: execnodes.h:1167
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1202
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1203
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1205
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1171
TupleTableSlot * firstTupleSlot
Definition: execnodes.h:2852
bool need_init
Definition: execnodes.h:2869
SortSupport sortKeys
Definition: execnodes.h:2866
bool table_filled
Definition: execnodes.h:2876
SetOpStatePerInput rightInput
Definition: execnodes.h:2868
PlanState ps
Definition: execnodes.h:2860
Oid * eqfuncoids
Definition: execnodes.h:2872
FmgrInfo * hashfunctions
Definition: execnodes.h:2873
SetOpStatePerInput leftInput
Definition: execnodes.h:2867
int64 numOutput
Definition: execnodes.h:2862
bool setop_done
Definition: execnodes.h:2861
SetOpStrategy strategy
Definition: plannodes.h:1433
int numCols
Definition: plannodes.h:1436
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, Assert(), build_hash_table(), BumpContextCreate(), 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, TTSOpsMinimalTuple, and SetOpState::tuplesContext.

Referenced by ExecInitNode().

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)

Definition at line 703 of file nodeSetOp.c.

704{
707
709 node->setop_done = false;
710 node->numOutput = 0;
711
712 if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
713 {
714 /*
715 * In the hashed case, if we haven't yet built the hash table then we
716 * can just return; nothing done yet, so nothing to undo. If subnode's
717 * chgParam is not NULL then it will be re-scanned by ExecProcNode,
718 * else no reason to re-scan it at all.
719 */
720 if (!node->table_filled)
721 return;
722
723 /*
724 * If we do have the hash table and the subplans do not have any
725 * parameter changes, then we can just rescan the existing hash table;
726 * no need to build it again.
727 */
728 if (outerPlan->chgParam == NULL && innerPlan->chgParam == NULL)
729 {
731 return;
732 }
733
734 /* Else, we must rebuild the hashtable */
736 node->table_filled = false;
737 }
738 else
739 {
740 /* Need to re-read first input from each side */
741 node->need_init = true;
742 }
743
744 /*
745 * if chgParam of subnode is not null then plan will be re-scanned by
746 * first ExecProcNode.
747 */
748 if (outerPlan->chgParam == NULL)
750 if (innerPlan->chgParam == NULL)
752}
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
void ResetTupleHashTable(TupleHashTable hashtable)
Definition: execGrouping.c:302
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:898
TupleHashIterator hashiter
Definition: execnodes.h:2877
TupleHashTable hashtable
Definition: execnodes.h:2874
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:457

References ExecClearTuple(), ExecReScan(), SetOpState::hashiter, SetOpState::hashtable, innerPlan, innerPlanState, SetOpState::need_init, SetOpState::numOutput, outerPlan, outerPlanState, PlanState::plan, SetOpState::ps, PlanState::ps_ResultTupleSlot, ResetTupleHashIterator, ResetTupleHashTable(), SetOpState::setop_done, SETOP_HASHED, and SetOpState::table_filled.

Referenced by ExecReScan().