PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 
)
extern

Definition at line 116 of file nodeSetOp.c.

117{
118 return EstimateTupleHashTableSpace(nentries,
120 sizeof(SetOpStatePerGroupData));
121}
Size EstimateTupleHashTableSpace(double nentries, Size tupleWidth, Size additionalsize)
static int fb(int x)

References EstimateTupleHashTableSpace(), and fb().

Referenced by create_setop_path().

◆ ExecEndSetOp()

void ExecEndSetOp ( SetOpState node)
extern

Definition at line 692 of file nodeSetOp.c.

693{
694 /* free subsidiary stuff including hashtable data */
695 if (node->tuplesContext)
697
700}
void ExecEndNode(PlanState *node)
#define outerPlanState(node)
Definition execnodes.h:1273
#define innerPlanState(node)
Definition execnodes.h:1272
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
MemoryContext tuplesContext
Definition execnodes.h:2726

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

Referenced by ExecEndNode().

◆ ExecInitSetOp()

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

Definition at line 573 of file nodeSetOp.c.

574{
576
577 /* check for unsupported flags */
579
580 /*
581 * create state structure
582 */
584 setopstate->ps.plan = (Plan *) node;
585 setopstate->ps.state = estate;
586 setopstate->ps.ExecProcNode = ExecSetOp;
587
588 setopstate->setop_done = false;
589 setopstate->numOutput = 0;
590 setopstate->numCols = node->numCols;
591 setopstate->need_init = true;
592
593 /*
594 * create expression context
595 */
596 ExecAssignExprContext(estate, &setopstate->ps);
597
598 /*
599 * If hashing, we also need a longer-lived context to store the hash
600 * table. The table can't just be kept in the per-query context because
601 * we want to be able to throw it away in ExecReScanSetOp. We can use a
602 * BumpContext to save storage, because we will have no need to delete
603 * individual table entries.
604 */
605 if (node->strategy == SETOP_HASHED)
606 setopstate->tuplesContext =
608 "SetOp hashed tuples",
610
611 /*
612 * initialize child nodes
613 *
614 * If we are hashing then the child plans do not need to handle REWIND
615 * efficiently; see ExecReScanSetOp.
616 */
617 if (node->strategy == SETOP_HASHED)
618 eflags &= ~EXEC_FLAG_REWIND;
619 outerPlanState(setopstate) = ExecInitNode(outerPlan(node), estate, eflags);
620 innerPlanState(setopstate) = ExecInitNode(innerPlan(node), estate, eflags);
621
622 /*
623 * Initialize locally-allocated slots. In hashed mode, we just need a
624 * result slot. In sorted mode, we need one first-tuple-of-group slot for
625 * each input; we use the result slot for the left input's slot and create
626 * another for the right input. (Note: the nextTupleSlot slots are not
627 * ours, but just point to the last slot returned by the input plan node.)
628 */
630 if (node->strategy != SETOP_HASHED)
631 {
632 setopstate->leftInput.firstTupleSlot =
633 setopstate->ps.ps_ResultTupleSlot;
634 setopstate->rightInput.firstTupleSlot =
636 setopstate->ps.ps_ResultTupleDesc,
638 }
639
640 /* Setop nodes do no projections. */
641 setopstate->ps.ps_ProjInfo = NULL;
642
643 /*
644 * Precompute fmgr lookup data for inner loop. We need equality and
645 * hashing functions to do it by hashing, while for sorting we need
646 * SortSupport data.
647 */
648 if (node->strategy == SETOP_HASHED)
650 node->cmpOperators,
651 &setopstate->eqfuncoids,
652 &setopstate->hashfunctions);
653 else
654 {
655 int nkeys = node->numCols;
656
657 setopstate->sortKeys = (SortSupport)
658 palloc0(nkeys * sizeof(SortSupportData));
659 for (int i = 0; i < nkeys; i++)
660 {
661 SortSupport sortKey = setopstate->sortKeys + i;
662
664 sortKey->ssup_collation = node->cmpCollations[i];
665 sortKey->ssup_nulls_first = node->cmpNullsFirst[i];
666 sortKey->ssup_attno = node->cmpColIdx[i];
667 /* abbreviated key conversion is not useful here */
668 sortKey->abbreviate = false;
669
670 PrepareSortSupportFromOrderingOp(node->cmpOperators[i], sortKey);
671 }
672 }
673
674 /* Create a hash table if needed */
675 if (node->strategy == SETOP_HASHED)
676 {
678 setopstate->table_filled = false;
679 }
680
681 return setopstate;
682}
MemoryContext BumpContextCreate(MemoryContext parent, const char *name, Size minContextSize, Size initBlockSize, Size maxBlockSize)
Definition bump.c:133
#define Assert(condition)
Definition c.h:945
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
const TupleTableSlotOps TTSOpsMinimalTuple
Definition execTuples.c:86
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition execUtils.c:490
struct SortSupportData * SortSupport
Definition execnodes.h:60
#define EXEC_FLAG_BACKWARD
Definition executor.h:70
#define EXEC_FLAG_MARK
Definition executor.h:71
int i
Definition isn.c:77
void * palloc0(Size size)
Definition mcxt.c:1417
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
static void build_hash_table(SetOpState *setopstate)
Definition nodeSetOp.c:85
static TupleTableSlot * ExecSetOp(PlanState *pstate)
Definition nodeSetOp.c:169
@ SETOP_HASHED
Definition nodes.h:417
#define makeNode(_type_)
Definition nodes.h:161
#define innerPlan(node)
Definition plannodes.h:264
#define outerPlan(node)
Definition plannodes.h:265
void PrepareSortSupportFromOrderingOp(Oid orderingOp, SortSupport ssup)
SetOpStrategy strategy
Definition plannodes.h:1450
int numCols
Definition plannodes.h:1453
MemoryContext ssup_cxt
Definition sortsupport.h:66

References ALLOCSET_DEFAULT_SIZES, Assert, build_hash_table(), BumpContextCreate(), CurrentMemoryContext, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitResultTupleSlotTL(), ExecSetOp(), execTuplesHashPrepare(), fb(), i, innerPlan, innerPlanState, makeNode, SetOp::numCols, outerPlan, outerPlanState, palloc0(), PrepareSortSupportFromOrderingOp(), SETOP_HASHED, SortSupportData::ssup_cxt, SetOp::strategy, and TTSOpsMinimalTuple.

Referenced by ExecInitNode().

◆ ExecReScanSetOp()

void ExecReScanSetOp ( SetOpState node)
extern

Definition at line 704 of file nodeSetOp.c.

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

References ExecClearTuple(), ExecReScan(), fb(), 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().