1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.108 2003/11/29 22:41:06 pgsql Exp $
12 *-------------------------------------------------------------------------
17 #include "access/relscan.h"
18 #include "executor/hashjoin.h"
19 #include "executor/tuptable.h"
21 #include "nodes/bitmapset.h"
22 #include "nodes/params.h"
23 #include "nodes/plannodes.h"
24 #include "utils/hsearch.h"
25 #include "utils/tuplestore.h"
29 * IndexInfo information
31 * this struct holds the information needed to construct new index
32 * entries for a particular index. Used for both index_build and
33 * retail creation of index entries.
35 * NumIndexAttrs number of columns in this index
36 * KeyAttrNumbers underlying-rel attribute numbers used as keys
37 * (zeroes indicate expressions)
38 * Expressions expr trees for expression entries, or NIL if none
39 * ExpressionsState exec state for expressions, or NIL if none
40 * Predicate partial-index predicate, or NIL if none
41 * PredicateState exec state for predicate, or NIL if none
42 * Unique is it a unique index?
45 typedef struct IndexInfo
49 AttrNumber ii_KeyAttrNumbers[INDEX_MAX_KEYS];
50 List *ii_Expressions; /* list of Expr */
51 List *ii_ExpressionsState; /* list of ExprState */
52 List *ii_Predicate; /* list of Expr */
53 List *ii_PredicateState; /* list of ExprState */
60 * List of callbacks to be called at ExprContext shutdown.
63 typedef void (*ExprContextCallbackFunction) (Datum arg);
65 typedef struct ExprContext_CB
67 struct ExprContext_CB *next;
68 ExprContextCallbackFunction function;
75 * This class holds the "current context" information
76 * needed to evaluate expressions for doing tuple qualifications
77 * and tuple projections. For example, if an expression refers
78 * to an attribute in the current inner tuple then we need to know
79 * what the current inner tuple is and so we look at the expression
82 * There are two memory contexts associated with an ExprContext:
83 * * ecxt_per_query_memory is a query-lifespan context, typically the same
84 * context the ExprContext node itself is allocated in. This context
85 * can be used for purposes such as storing function call cache info.
86 * * ecxt_per_tuple_memory is a short-term context for expression results.
87 * As the name suggests, it will typically be reset once per tuple,
88 * before we begin to evaluate expressions for that tuple. Each
89 * ExprContext normally has its very own per-tuple memory context.
91 * CurrentMemoryContext should be set to ecxt_per_tuple_memory before
92 * calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
95 typedef struct ExprContext
99 /* Tuples that Var nodes in expression may refer to */
100 TupleTableSlot *ecxt_scantuple;
101 TupleTableSlot *ecxt_innertuple;
102 TupleTableSlot *ecxt_outertuple;
104 /* Memory contexts for expression evaluation --- see notes above */
105 MemoryContext ecxt_per_query_memory;
106 MemoryContext ecxt_per_tuple_memory;
108 /* Values to substitute for Param nodes in expression */
109 ParamExecData *ecxt_param_exec_vals; /* for PARAM_EXEC params */
110 ParamListInfo ecxt_param_list_info; /* for other param types */
112 /* Values to substitute for Aggref nodes in expression */
113 Datum *ecxt_aggvalues; /* precomputed values for Aggref nodes */
114 bool *ecxt_aggnulls; /* null flags for Aggref nodes */
116 /* Value to substitute for CoerceToDomainValue nodes in expression */
117 Datum domainValue_datum;
118 bool domainValue_isNull;
120 /* Link to containing EState */
121 struct EState *ecxt_estate;
123 /* Functions to call back when ExprContext is shut down */
124 ExprContext_CB *ecxt_callbacks;
128 * Set-result status returned by ExecEvalExpr()
132 ExprSingleResult, /* expression does not return a set */
133 ExprMultipleResult, /* this result is an element of a set */
134 ExprEndResult /* there are no more elements in the set */
138 * Return modes for functions returning sets. Note values must be chosen
139 * as separate bits so that a bitmask can be formed to indicate supported
144 SFRM_ValuePerCall = 0x01, /* one value returned per call */
145 SFRM_Materialize = 0x02 /* result set instantiated in Tuplestore */
146 } SetFunctionReturnMode;
149 * When calling a function that might return a set (multiple rows),
150 * a node of this type is passed as fcinfo->resultinfo to allow
151 * return status to be passed back. A function returning set should
152 * raise an error if no such resultinfo is provided.
154 typedef struct ReturnSetInfo
157 /* values set by caller: */
158 ExprContext *econtext; /* context function is being called in */
159 TupleDesc expectedDesc; /* tuple descriptor expected by caller */
160 int allowedModes; /* bitmask: return modes caller can handle */
161 /* result status from function (but pre-initialized by caller): */
162 SetFunctionReturnMode returnMode; /* actual return mode */
163 ExprDoneCond isDone; /* status for ValuePerCall mode */
164 /* fields filled by function in Materialize return mode: */
165 Tuplestorestate *setResult; /* holds the complete returned tuple set */
166 TupleDesc setDesc; /* actual descriptor for returned tuples */
170 * ProjectionInfo node information
172 * This is all the information needed to perform projections ---
173 * that is, form new tuples by evaluation of targetlist expressions.
174 * Nodes which need to do projections create one of these.
175 * In theory, when a node wants to perform a projection
176 * it should just update this information as necessary and then
177 * call ExecProject(). -cim 6/3/91
179 * ExecProject() evaluates the tlist, forms a tuple, and stores it
180 * in the given slot. As a side-effect, the actual datum values and
181 * null indicators are placed in the work arrays tupValues/tupNulls.
183 * targetlist target list for projection
184 * exprContext expression context in which to evaluate targetlist
185 * slot slot to place projection result in
186 * tupValues array of computed values
187 * tupNull array of null indicators
188 * itemIsDone workspace for ExecProject
191 typedef struct ProjectionInfo
195 ExprContext *pi_exprContext;
196 TupleTableSlot *pi_slot;
199 ExprDoneCond *pi_itemIsDone;
205 * This class is used to store information regarding junk attributes.
206 * A junk attribute is an attribute in a tuple that is needed only for
207 * storing intermediate information in the executor, and does not belong
208 * in emitted tuples. For example, when we do an UPDATE query,
209 * the planner adds a "junk" entry to the targetlist so that the tuples
210 * returned to ExecutePlan() contain an extra attribute: the ctid of
211 * the tuple to be updated. This is needed to do the update, but we
212 * don't want the ctid to be part of the stored new tuple! So, we
213 * apply a "junk filter" to remove the junk attributes and form the
216 * targetList: the original target list (including junk attributes).
217 * length: the length of 'targetList'.
218 * tupType: the tuple descriptor for the "original" tuple
219 * (including the junk attributes).
220 * cleanTargetList: the "clean" target list (junk attributes removed).
221 * cleanLength: the length of 'cleanTargetList'
222 * cleanTupType: the tuple descriptor of the "clean" tuple (with
223 * junk attributes removed).
224 * cleanMap: A map with the correspondence between the non-junk
225 * attribute numbers of the "original" tuple and the
226 * attribute numbers of the "clean" tuple.
227 * resultSlot: tuple slot that can be used to hold cleaned tuple.
230 typedef struct JunkFilter
235 TupleDesc jf_tupType;
236 List *jf_cleanTargetList;
238 TupleDesc jf_cleanTupType;
239 AttrNumber *jf_cleanMap;
240 TupleTableSlot *jf_resultSlot;
244 * ResultRelInfo information
246 * Whenever we update an existing relation, we have to
247 * update indices on the relation, and perhaps also fire triggers.
248 * The ResultRelInfo class is used to hold all the information needed
249 * about a result relation, including indices.. -cim 10/15/89
251 * RangeTableIndex result relation's range table index
252 * RelationDesc relation descriptor for result relation
253 * NumIndices # of indices existing on result relation
254 * IndexRelationDescs array of relation descriptors for indices
255 * IndexRelationInfo array of key/attr info for indices
256 * TrigDesc triggers to be fired, if any
257 * TrigFunctions cached lookup info for trigger functions
258 * ConstraintExprs array of constraint-checking expr states
259 * junkFilter for removing junk attributes from tuples
262 typedef struct ResultRelInfo
265 Index ri_RangeTableIndex;
266 Relation ri_RelationDesc;
268 RelationPtr ri_IndexRelationDescs;
269 IndexInfo **ri_IndexRelationInfo;
270 TriggerDesc *ri_TrigDesc;
271 FmgrInfo *ri_TrigFunctions;
272 List **ri_ConstraintExprs;
273 JunkFilter *ri_junkFilter;
279 * Master working state for an Executor invocation
282 typedef struct EState
286 /* Basic state for all query types: */
287 ScanDirection es_direction; /* current scan direction */
288 Snapshot es_snapshot; /* time qual to use */
289 Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
290 List *es_range_table; /* List of RangeTableEntrys */
292 /* Info about target table for insert/update/delete queries: */
293 ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
294 int es_num_result_relations; /* length of array */
295 ResultRelInfo *es_result_relation_info; /* currently active array
297 JunkFilter *es_junkFilter; /* currently active junk filter */
298 Relation es_into_relation_descriptor; /* for SELECT INTO */
300 /* Parameter info: */
301 ParamListInfo es_param_list_info; /* values of external params */
302 ParamExecData *es_param_exec_vals; /* values of internal params */
304 /* Other working state: */
305 MemoryContext es_query_cxt; /* per-query context in which EState lives */
307 TupleTable es_tupleTable; /* Array of TupleTableSlots */
309 uint32 es_processed; /* # of tuples processed */
310 Oid es_lastoid; /* last oid processed (by INSERT) */
311 List *es_rowMark; /* not good place, but there is no other */
313 bool es_instrument; /* true requests runtime instrumentation */
314 bool es_force_oids; /* true forces result tuples to have
315 * (space for) OIDs --- used for SELECT
318 List *es_exprcontexts; /* List of ExprContexts within EState */
321 * this ExprContext is for per-output-tuple operations, such as
322 * constraint checks and index-value computations. It will be reset
323 * for each output tuple. Note that it will be created only if
326 ExprContext *es_per_tuple_exprcontext;
328 /* Below is to re-evaluate plan qual in READ COMMITTED mode */
329 Plan *es_topPlan; /* link to top of plan tree */
330 struct evalPlanQual *es_evalPlanQual; /* chain of PlanQual
332 bool *es_evTupleNull; /* local array of EPQ status */
333 HeapTuple *es_evTuple; /* shared array of EPQ substitute tuples */
334 bool es_useEvalPlan; /* evaluating EPQ tuples? */
338 /* ----------------------------------------------------------------
341 * All-in-memory tuple hash tables are used for a number of purposes.
342 * ----------------------------------------------------------------
344 typedef struct TupleHashEntryData *TupleHashEntry;
345 typedef struct TupleHashTableData *TupleHashTable;
347 typedef struct TupleHashEntryData
349 /* firstTuple must be the first field in this struct! */
350 HeapTuple firstTuple; /* copy of first tuple in this group */
351 /* there may be additional data beyond the end of this struct */
352 } TupleHashEntryData; /* VARIABLE LENGTH STRUCT */
354 typedef struct TupleHashTableData
356 HTAB *hashtab; /* underlying dynahash table */
357 int numCols; /* number of columns in lookup key */
358 AttrNumber *keyColIdx; /* attr numbers of key columns */
359 FmgrInfo *eqfunctions; /* lookup data for comparison functions */
360 FmgrInfo *hashfunctions; /* lookup data for hash functions */
361 MemoryContext tablecxt; /* memory context containing table */
362 MemoryContext tempcxt; /* context for function evaluations */
363 Size entrysize; /* actual size to make each hash entry */
364 TupleDesc tupdesc; /* tuple descriptor */
365 } TupleHashTableData;
367 typedef HASH_SEQ_STATUS TupleHashIterator;
369 #define ResetTupleHashIterator(htable, iter) \
370 hash_seq_init(iter, (htable)->hashtab)
371 #define ScanTupleHashTable(iter) \
372 ((TupleHashEntry) hash_seq_search(iter))
375 /* ----------------------------------------------------------------
376 * Expression State Trees
378 * Each executable expression tree has a parallel ExprState tree.
380 * Unlike PlanState, there is not an exact one-for-one correspondence between
381 * ExprState node types and Expr node types. Many Expr node types have no
382 * need for node-type-specific run-time state, and so they can use plain
383 * ExprState or GenericExprState as their associated ExprState node type.
384 * ----------------------------------------------------------------
390 * ExprState is the common superclass for all ExprState-type nodes.
392 * It can also be instantiated directly for leaf Expr nodes that need no
393 * local run-time state (such as Var, Const, or Param).
396 typedef struct ExprState
399 Expr *expr; /* associated Expr node */
403 * GenericExprState node
405 * This is used for Expr node types that need no local run-time state,
406 * but have one child Expr node.
409 typedef struct GenericExprState
412 ExprState *arg; /* state of my child node */
416 * AggrefExprState node
419 typedef struct AggrefExprState
422 ExprState *target; /* state of my child node */
423 int aggno; /* ID number for agg within its plan node */
427 * ArrayRefExprState node
429 * Note: array types can be fixed-length (typlen > 0), but only when the
430 * element type is itself fixed-length. Otherwise they are varlena structures
431 * and have typlen = -1. In any case, an array type is never pass-by-value.
434 typedef struct ArrayRefExprState
437 List *refupperindexpr; /* states for child nodes */
438 List *reflowerindexpr;
440 ExprState *refassgnexpr;
441 int16 refattrlength; /* typlen of array type */
442 int16 refelemlength; /* typlen of the array element type */
443 bool refelembyval; /* is the element type pass-by-value? */
444 char refelemalign; /* typalign of the element type */
450 * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
451 * and NullIf nodes; be careful to check what xprstate.expr is actually
455 typedef struct FuncExprState
458 List *args; /* states of argument expressions */
461 * Function manager's lookup info for the target function. If
462 * func.fn_oid is InvalidOid, we haven't initialized it yet.
467 * We also need to store argument values across calls when evaluating
468 * a function-returning-set.
470 * setArgsValid is true when we are evaluating a set-valued function and
471 * we are in the middle of a call series; we want to pass the same
472 * argument values to the function again (and again, until it returns
478 * Flag to remember whether we found a set-valued argument to the
479 * function. This causes the function result to be a set as well.
480 * Valid only when setArgsValid is true.
482 bool setHasSetArg; /* some argument returns a set */
485 * Current argument data for a set-valued function; contains valid
486 * data only if setArgsValid is true.
488 FunctionCallInfoData setArgs;
492 * ScalarArrayOpExprState node
494 * This is a FuncExprState plus some additional data.
497 typedef struct ScalarArrayOpExprState
499 FuncExprState fxprstate;
500 /* Cached info about array element type */
505 } ScalarArrayOpExprState;
511 typedef struct BoolExprState
514 List *args; /* states of argument expression(s) */
521 typedef struct SubPlanState
524 EState *sub_estate; /* subselect plan has its own EState */
525 struct PlanState *planstate; /* subselect plan's state tree */
526 List *exprs; /* states of combining expression(s) */
527 List *args; /* states of argument expression(s) */
528 bool needShutdown; /* TRUE = need to shutdown subplan */
529 HeapTuple curTuple; /* copy of most recent tuple from subplan */
530 /* these are used when hashing the subselect's output: */
531 ProjectionInfo *projLeft; /* for projecting lefthand exprs */
532 ProjectionInfo *projRight; /* for projecting subselect output */
533 TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
534 TupleHashTable hashnulls; /* hash table for rows with null(s) */
535 bool havehashrows; /* TRUE if hashtable is not empty */
536 bool havenullrows; /* TRUE if hashnulls is not empty */
537 MemoryContext tablecxt; /* memory context containing tables */
538 ExprContext *innerecontext; /* working context for comparisons */
539 AttrNumber *keyColIdx; /* control data for hash tables */
540 FmgrInfo *eqfunctions; /* comparison functions for hash tables */
541 FmgrInfo *hashfunctions; /* lookup data for hash functions */
548 typedef struct CaseExprState
551 List *args; /* the arguments (list of WHEN clauses) */
552 ExprState *defresult; /* the default result (ELSE clause) */
559 typedef struct CaseWhenState
562 ExprState *expr; /* condition expression */
563 ExprState *result; /* substitution result */
567 * ArrayExprState node
569 * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
573 typedef struct ArrayExprState
576 List *elements; /* states for child nodes */
577 int16 elemlength; /* typlen of the array element type */
578 bool elembyval; /* is the element type pass-by-value? */
579 char elemalign; /* typalign of the element type */
583 * CoalesceExprState node
586 typedef struct CoalesceExprState
589 List *args; /* the arguments */
593 * CoerceToDomainState node
596 typedef struct CoerceToDomainState
599 ExprState *arg; /* input expression */
600 /* Cached list of constraints that need to be checked */
601 List *constraints; /* list of DomainConstraintState nodes */
602 } CoerceToDomainState;
605 * DomainConstraintState - one item to check during CoerceToDomain
607 * Note: this is just a Node, and not an ExprState, because it has no
608 * corresponding Expr to link to. Nonetheless it is part of an ExprState
609 * tree, so we give it a name following the xxxState convention.
611 typedef enum DomainConstraintType
613 DOM_CONSTRAINT_NOTNULL,
615 } DomainConstraintType;
617 typedef struct DomainConstraintState
620 DomainConstraintType constrainttype; /* constraint type */
621 char *name; /* name of constraint (for error msgs) */
622 ExprState *check_expr; /* for CHECK, a boolean expression */
623 } DomainConstraintState;
626 /* ----------------------------------------------------------------
627 * Executor State Trees
629 * An executing query has a PlanState tree paralleling the Plan tree
630 * that describes the plan.
631 * ----------------------------------------------------------------
637 * We never actually instantiate any PlanState nodes; this is just the common
638 * abstract superclass for all PlanState-type nodes.
641 typedef struct PlanState
645 Plan *plan; /* associated Plan node */
647 EState *state; /* at execution time, state's of
648 * individual nodes point to one EState
649 * for the whole top-level plan */
651 struct Instrumentation *instrument; /* Optional runtime stats for this
655 * Common structural data for all Plan types. These links to
656 * subsidiary state trees parallel links in the associated plan tree
657 * (except for the subPlan list, which does not exist in the plan
660 List *targetlist; /* target list to be computed at this node */
661 List *qual; /* implicitly-ANDed qual conditions */
662 struct PlanState *lefttree; /* input plan tree(s) */
663 struct PlanState *righttree;
664 List *initPlan; /* Init SubPlanState nodes (un-correlated
665 * expr subselects) */
666 List *subPlan; /* SubPlanState nodes in my expressions */
669 * State for management of parameter-change-driven rescanning
671 Bitmapset *chgParam; /* set of IDs of changed Params */
674 * Other run-time state needed by most if not all node types.
676 TupleTableSlot *ps_OuterTupleSlot; /* slot for current "outer" tuple */
677 TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
678 ExprContext *ps_ExprContext; /* node's expression-evaluation context */
679 ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */
680 bool ps_TupFromTlist;/* state flag for processing set-valued
681 * functions in targetlist */
685 * these are are defined to avoid confusion problems with "left"
686 * and "right" and "inner" and "outer". The convention is that
687 * the "left" plan is the "outer" plan and the "right" plan is
688 * the inner plan, but these make the code more readable.
691 #define innerPlanState(node) (((PlanState *)(node))->righttree)
692 #define outerPlanState(node) (((PlanState *)(node))->lefttree)
696 * ResultState information
699 typedef struct ResultState
701 PlanState ps; /* its first field is NodeTag */
702 ExprState *resconstantqual;
703 bool rs_done; /* are we done? */
704 bool rs_checkqual; /* do we need to check the qual? */
708 * AppendState information
710 * nplans how many plans are in the list
711 * whichplan which plan is being executed (0 .. n-1)
712 * firstplan first plan to execute (usually 0)
713 * lastplan last plan to execute (usually n-1)
716 typedef struct AppendState
718 PlanState ps; /* its first field is NodeTag */
719 PlanState **appendplans; /* array of PlanStates for my inputs */
726 /* ----------------------------------------------------------------
727 * Scan State Information
728 * ----------------------------------------------------------------
732 * ScanState information
734 * ScanState extends PlanState for node types that represent
735 * scans of an underlying relation. It can also be used for nodes
736 * that scan the output of an underlying plan node --- in that case,
737 * only ScanTupleSlot is actually useful, and it refers to the tuple
738 * retrieved from the subplan.
740 * currentRelation relation being scanned (NULL if none)
741 * currentScanDesc current scan descriptor for scan (NULL if none)
742 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
745 typedef struct ScanState
747 PlanState ps; /* its first field is NodeTag */
748 Relation ss_currentRelation;
749 HeapScanDesc ss_currentScanDesc;
750 TupleTableSlot *ss_ScanTupleSlot;
754 * SeqScan uses a bare ScanState as its state node, since it needs
755 * no additional fields.
757 typedef ScanState SeqScanState;
760 * IndexScanState information
762 * NumIndices number of indices in this scan
763 * IndexPtr current index in use
764 * ScanKeys Skey structures to scan index rels
765 * NumScanKeys array of no of keys in each Skey struct
766 * RuntimeKeyInfo array of array of exprstates for Skeys
767 * that will be evaluated at runtime
768 * RuntimeContext expr context for evaling runtime Skeys
769 * RuntimeKeysReady true if runtime Skeys have been computed
770 * RelationDescs ptr to array of relation descriptors
771 * ScanDescs ptr to array of scan descriptors
772 * DupHash hashtable for recognizing dups in multiple scan
773 * MaxHash max # entries we will allow in hashtable
776 typedef struct IndexScanState
778 ScanState ss; /* its first field is NodeTag */
783 int iss_MarkIndexPtr;
784 ScanKey *iss_ScanKeys;
785 int *iss_NumScanKeys;
786 ExprState ***iss_RuntimeKeyInfo;
787 ExprContext *iss_RuntimeContext;
788 bool iss_RuntimeKeysReady;
789 RelationPtr iss_RelationDescs;
790 IndexScanDescPtr iss_ScanDescs;
796 * TidScanState information
798 * NumTids number of tids in this scan
799 * TidPtr current tid in use
800 * TidList evaluated item pointers
803 typedef struct TidScanState
805 ScanState ss; /* its first field is NodeTag */
806 List *tss_tideval; /* list of ExprState nodes */
810 ItemPointerData *tss_TidList;
811 HeapTupleData tss_htup;
815 * SubqueryScanState information
817 * SubqueryScanState is used for scanning a sub-query in the range table.
818 * The sub-query will have its own EState, which we save here.
819 * ScanTupleSlot references the current output tuple of the sub-query.
821 * SubEState exec state for sub-query
824 typedef struct SubqueryScanState
826 ScanState ss; /* its first field is NodeTag */
828 EState *sss_SubEState;
832 * FunctionScanState information
834 * Function nodes are used to scan the results of a
835 * function appearing in FROM (typically a function returning set).
837 * tupdesc expected return tuple description
838 * tuplestorestate private state of tuplestore.c
839 * funcexpr state for function expression being evaluated
842 typedef struct FunctionScanState
844 ScanState ss; /* its first field is NodeTag */
846 Tuplestorestate *tuplestorestate;
850 /* ----------------------------------------------------------------
851 * Join State Information
852 * ----------------------------------------------------------------
856 * JoinState information
858 * Superclass for state nodes of join plans.
861 typedef struct JoinState
865 List *joinqual; /* JOIN quals (in addition to ps.qual) */
869 * NestLoopState information
871 * NeedNewOuter true if need new outer tuple on next call
872 * MatchedOuter true if found a join match for current outer tuple
873 * NullInnerTupleSlot prepared null tuple for left outer joins
876 typedef struct NestLoopState
878 JoinState js; /* its first field is NodeTag */
879 bool nl_NeedNewOuter;
880 bool nl_MatchedOuter;
881 TupleTableSlot *nl_NullInnerTupleSlot;
885 * MergeJoinState information
887 * OuterSkipQual outerKey1 < innerKey1 ...
888 * InnerSkipQual outerKey1 > innerKey1 ...
889 * JoinState current "state" of join. see executor.h
890 * MatchedOuter true if found a join match for current outer tuple
891 * MatchedInner true if found a join match for current inner tuple
892 * OuterTupleSlot pointer to slot in tuple table for cur outer tuple
893 * InnerTupleSlot pointer to slot in tuple table for cur inner tuple
894 * MarkedTupleSlot pointer to slot in tuple table for marked tuple
895 * NullOuterTupleSlot prepared null tuple for right outer joins
896 * NullInnerTupleSlot prepared null tuple for left outer joins
899 typedef struct MergeJoinState
901 JoinState js; /* its first field is NodeTag */
902 List *mergeclauses; /* list of ExprState nodes */
903 List *mj_OuterSkipQual; /* list of ExprState nodes */
904 List *mj_InnerSkipQual; /* list of ExprState nodes */
906 bool mj_MatchedOuter;
907 bool mj_MatchedInner;
908 TupleTableSlot *mj_OuterTupleSlot;
909 TupleTableSlot *mj_InnerTupleSlot;
910 TupleTableSlot *mj_MarkedTupleSlot;
911 TupleTableSlot *mj_NullOuterTupleSlot;
912 TupleTableSlot *mj_NullInnerTupleSlot;
916 * HashJoinState information
918 * hj_HashTable hash table for the hashjoin
919 * hj_CurBucketNo bucket# for current outer tuple
920 * hj_CurTuple last inner tuple matched to current outer
921 * tuple, or NULL if starting search
922 * (CurBucketNo and CurTuple are meaningless
923 * unless OuterTupleSlot is nonempty!)
924 * hj_OuterHashKeys the outer hash keys in the hashjoin condition
925 * hj_InnerHashKeys the inner hash keys in the hashjoin condition
926 * hj_HashOperators the join operators in the hashjoin condition
927 * hj_OuterTupleSlot tuple slot for outer tuples
928 * hj_HashTupleSlot tuple slot for hashed tuples
929 * hj_NullInnerTupleSlot prepared null tuple for left outer joins
930 * hj_NeedNewOuter true if need new outer tuple on next call
931 * hj_MatchedOuter true if found a join match for current outer
932 * hj_hashdone true if hash-table-build phase is done
935 typedef struct HashJoinState
937 JoinState js; /* its first field is NodeTag */
938 List *hashclauses; /* list of ExprState nodes */
939 HashJoinTable hj_HashTable;
941 HashJoinTuple hj_CurTuple;
942 List *hj_OuterHashKeys; /* list of ExprState nodes */
943 List *hj_InnerHashKeys; /* list of ExprState nodes */
944 List *hj_HashOperators; /* list of operator OIDs */
945 TupleTableSlot *hj_OuterTupleSlot;
946 TupleTableSlot *hj_HashTupleSlot;
947 TupleTableSlot *hj_NullInnerTupleSlot;
948 bool hj_NeedNewOuter;
949 bool hj_MatchedOuter;
954 /* ----------------------------------------------------------------
955 * Materialization State Information
956 * ----------------------------------------------------------------
960 * MaterialState information
962 * materialize nodes are used to materialize the results
963 * of a subplan into a temporary file.
965 * ss.ss_ScanTupleSlot refers to output of underlying plan.
968 typedef struct MaterialState
970 ScanState ss; /* its first field is NodeTag */
971 void *tuplestorestate; /* private state of tuplestore.c */
972 bool eof_underlying; /* reached end of underlying plan? */
976 * SortState information
979 typedef struct SortState
981 ScanState ss; /* its first field is NodeTag */
982 bool sort_Done; /* sort completed yet? */
983 void *tuplesortstate; /* private state of tuplesort.c */
986 /* ---------------------
987 * GroupState information
988 * -------------------------
990 typedef struct GroupState
992 ScanState ss; /* its first field is NodeTag */
993 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
994 HeapTuple grp_firstTuple; /* copy of first tuple of current group */
995 bool grp_done; /* indicates completion of Group scan */
998 /* ---------------------
999 * AggState information
1001 * ss.ss_ScanTupleSlot refers to output of underlying plan.
1003 * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
1004 * ecxt_aggnulls arrays, which hold the computed agg values for the current
1005 * input group during evaluation of an Agg node's output tuple(s). We
1006 * create a second ExprContext, tmpcontext, in which to evaluate input
1007 * expressions and run the aggregate transition functions.
1008 * -------------------------
1010 /* these structs are private in nodeAgg.c: */
1011 typedef struct AggStatePerAggData *AggStatePerAgg;
1012 typedef struct AggStatePerGroupData *AggStatePerGroup;
1014 typedef struct AggState
1016 ScanState ss; /* its first field is NodeTag */
1017 List *aggs; /* all Aggref nodes in targetlist & quals */
1018 int numaggs; /* length of list (could be zero!) */
1019 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
1020 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1021 AggStatePerAgg peragg; /* per-Aggref information */
1022 MemoryContext aggcontext; /* memory context for long-lived data */
1023 ExprContext *tmpcontext; /* econtext for input expressions */
1024 bool agg_done; /* indicates completion of Agg scan */
1025 /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
1026 AggStatePerGroup pergroup; /* per-Aggref-per-group working state */
1027 HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1028 /* these fields are used in AGG_HASHED mode: */
1029 TupleHashTable hashtable; /* hash table with one entry per group */
1030 bool table_filled; /* hash table filled yet? */
1031 TupleHashIterator hashiter; /* for iterating through hash table */
1035 * UniqueState information
1037 * Unique nodes are used "on top of" sort nodes to discard
1038 * duplicate tuples returned from the sort phase. Basically
1039 * all it does is compare the current tuple from the subplan
1040 * with the previously fetched tuple stored in priorTuple.
1041 * If the two are identical in all interesting fields, then
1042 * we just fetch another tuple from the sort and try again.
1045 typedef struct UniqueState
1047 PlanState ps; /* its first field is NodeTag */
1048 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1049 HeapTuple priorTuple; /* most recently returned tuple, or NULL */
1050 MemoryContext tempContext; /* short-term context for comparisons */
1054 * HashState information
1057 typedef struct HashState
1059 PlanState ps; /* its first field is NodeTag */
1060 HashJoinTable hashtable; /* hash table for the hashjoin */
1061 List *hashkeys; /* list of ExprState nodes */
1062 /* hashkeys is same as parent's hj_InnerHashKeys */
1066 * SetOpState information
1068 * SetOp nodes are used "on top of" sort nodes to discard
1069 * duplicate tuples returned from the sort phase. These are
1070 * more complex than a simple Unique since we have to count
1071 * how many duplicates to return.
1074 typedef struct SetOpState
1076 PlanState ps; /* its first field is NodeTag */
1077 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1078 bool subplan_done; /* has subplan returned EOF? */
1079 long numLeft; /* number of left-input dups of cur group */
1080 long numRight; /* number of right-input dups of cur group */
1081 long numOutput; /* number of dups left to output */
1082 MemoryContext tempContext; /* short-term context for comparisons */
1086 * LimitState information
1088 * Limit nodes are used to enforce LIMIT/OFFSET clauses.
1089 * They just select the desired subrange of their subplan's output.
1091 * offset is the number of initial tuples to skip (0 does nothing).
1092 * count is the number of tuples to return after skipping the offset tuples.
1093 * If no limit count was specified, count is undefined and noCount is true.
1094 * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
1099 LIMIT_INITIAL, /* initial state for LIMIT node */
1100 LIMIT_EMPTY, /* there are no returnable rows */
1101 LIMIT_INWINDOW, /* have returned a row in the window */
1102 LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */
1103 LIMIT_WINDOWEND, /* stepped off end of window */
1104 LIMIT_WINDOWSTART /* stepped off beginning of window */
1107 typedef struct LimitState
1109 PlanState ps; /* its first field is NodeTag */
1110 ExprState *limitOffset; /* OFFSET parameter, or NULL if none */
1111 ExprState *limitCount; /* COUNT parameter, or NULL if none */
1112 long offset; /* current OFFSET value */
1113 long count; /* current COUNT, if any */
1114 bool noCount; /* if true, ignore count */
1115 LimitStateCond lstate; /* state machine status, as above */
1116 long position; /* 1-based index of last tuple returned */
1117 TupleTableSlot *subSlot; /* tuple last obtained from subplan */
1120 #endif /* EXECNODES_H */