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

671{
672 /* free subsidiary stuff including hashtable */
673 if (node->tableContext)
675
678}
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1221
#define innerPlanState(node)
Definition: execnodes.h:1220
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
MemoryContext tableContext
Definition: execnodes.h:2834

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

Referenced by ExecEndNode().

◆ ExecInitSetOp()

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

Definition at line 553 of file nodeSetOp.c.

554{
555 SetOpState *setopstate;
556
557 /* check for unsupported flags */
559
560 /*
561 * create state structure
562 */
563 setopstate = makeNode(SetOpState);
564 setopstate->ps.plan = (Plan *) node;
565 setopstate->ps.state = estate;
566 setopstate->ps.ExecProcNode = ExecSetOp;
567
568 setopstate->setop_done = false;
569 setopstate->numOutput = 0;
570 setopstate->numCols = node->numCols;
571 setopstate->need_init = true;
572
573 /*
574 * create expression context
575 */
576 ExecAssignExprContext(estate, &setopstate->ps);
577
578 /*
579 * If hashing, we also need a longer-lived context to store the hash
580 * table. The table can't just be kept in the per-query context because
581 * we want to be able to throw it away in ExecReScanSetOp.
582 */
583 if (node->strategy == SETOP_HASHED)
584 setopstate->tableContext =
586 "SetOp hash table",
588
589 /*
590 * initialize child nodes
591 *
592 * If we are hashing then the child plans do not need to handle REWIND
593 * efficiently; see ExecReScanSetOp.
594 */
595 if (node->strategy == SETOP_HASHED)
596 eflags &= ~EXEC_FLAG_REWIND;
597 outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
598 innerPlanState(setopstate) = ExecInitNode(innerPlan(node), estate, eflags);
599
600 /*
601 * Initialize locally-allocated slots. In hashed mode, we just need a
602 * result slot. In sorted mode, we need one first-tuple-of-group slot for
603 * each input; we use the result slot for the left input's slot and create
604 * another for the right input. (Note: the nextTupleSlot slots are not
605 * ours, but just point to the last slot returned by the input plan node.)
606 */
608 if (node->strategy != SETOP_HASHED)
609 {
610 setopstate->leftInput.firstTupleSlot =
611 setopstate->ps.ps_ResultTupleSlot;
612 setopstate->rightInput.firstTupleSlot =
614 setopstate->ps.ps_ResultTupleDesc,
616 }
617
618 /* Setop nodes do no projections. */
619 setopstate->ps.ps_ProjInfo = NULL;
620
621 /*
622 * Precompute fmgr lookup data for inner loop. We need equality and
623 * hashing functions to do it by hashing, while for sorting we need
624 * SortSupport data.
625 */
626 if (node->strategy == SETOP_HASHED)
628 node->cmpOperators,
629 &setopstate->eqfuncoids,
630 &setopstate->hashfunctions);
631 else
632 {
633 int nkeys = node->numCols;
634
635 setopstate->sortKeys = (SortSupport)
636 palloc0(nkeys * sizeof(SortSupportData));
637 for (int i = 0; i < nkeys; i++)
638 {
639 SortSupport sortKey = setopstate->sortKeys + i;
640
642 sortKey->ssup_collation = node->cmpCollations[i];
643 sortKey->ssup_nulls_first = node->cmpNullsFirst[i];
644 sortKey->ssup_attno = node->cmpColIdx[i];
645 /* abbreviated key conversion is not useful here */
646 sortKey->abbreviate = false;
647
648 PrepareSortSupportFromOrderingOp(node->cmpOperators[i], sortKey);
649 }
650 }
651
652 /* Create a hash table if needed */
653 if (node->strategy == SETOP_HASHED)
654 {
655 build_hash_table(setopstate);
656 setopstate->table_filled = false;
657 }
658
659 return setopstate;
660}
#define Assert(condition)
Definition: c.h:812
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:2018
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1986
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:86
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
int i
Definition: isn.c:72
void * palloc0(Size size)
Definition: mcxt.c:1347
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:84
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition: nodeSetOp.c:160
@ SETOP_HASHED
Definition: nodes.h:407
#define makeNode(_type_)
Definition: nodes.h:155
#define innerPlan(node)
Definition: plannodes.h:182
#define outerPlan(node)
Definition: plannodes.h:183
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
Definition: sortsupport.c:134
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
Plan * plan
Definition: execnodes.h:1125
EState * state
Definition: execnodes.h:1127
TupleDesc ps_ResultTupleDesc
Definition: execnodes.h:1162
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1163
ProjectionInfo * ps_ProjInfo
Definition: execnodes.h:1165
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1131
TupleTableSlot * firstTupleSlot
Definition: execnodes.h:2811
bool need_init
Definition: execnodes.h:2828
SortSupport sortKeys
Definition: execnodes.h:2825
bool table_filled
Definition: execnodes.h:2835
SetOpStatePerInput rightInput
Definition: execnodes.h:2827
PlanState ps
Definition: execnodes.h:2819
Oid * eqfuncoids
Definition: execnodes.h:2831
FmgrInfo * hashfunctions
Definition: execnodes.h:2832
SetOpStatePerInput leftInput
Definition: execnodes.h:2826
int64 numOutput
Definition: execnodes.h:2821
bool setop_done
Definition: execnodes.h:2820
SetOpStrategy strategy
Definition: plannodes.h:1226
int numCols
Definition: plannodes.h:1229
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 682 of file nodeSetOp.c.

683{
686
688 node->setop_done = false;
689 node->numOutput = 0;
690
691 if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
692 {
693 /*
694 * In the hashed case, if we haven't yet built the hash table then we
695 * can just return; nothing done yet, so nothing to undo. If subnode's
696 * chgParam is not NULL then it will be re-scanned by ExecProcNode,
697 * else no reason to re-scan it at all.
698 */
699 if (!node->table_filled)
700 return;
701
702 /*
703 * If we do have the hash table and the subplans do not have any
704 * parameter changes, then we can just rescan the existing hash table;
705 * no need to build it again.
706 */
707 if (outerPlan->chgParam == NULL && innerPlan->chgParam == NULL)
708 {
710 return;
711 }
712
713 /* Release any hashtable storage */
714 if (node->tableContext)
716
717 /* And rebuild an empty hashtable */
719 node->table_filled = false;
720 }
721 else
722 {
723 /* Need to re-read first input from each side */
724 node->need_init = true;
725 }
726
727 /*
728 * if chgParam of subnode is not null then plan will be re-scanned by
729 * first ExecProcNode.
730 */
731 if (outerPlan->chgParam == NULL)
733 if (innerPlan->chgParam == NULL)
735}
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void ResetTupleHashTable(TupleHashTable hashtable)
Definition: execGrouping.c:271
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:857
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
TupleHashIterator hashiter
Definition: execnodes.h:2836
TupleHashTable hashtable
Definition: execnodes.h:2833
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:454

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().