1 /*-------------------------------------------------------------------------
4 * definitions for executor state nodes
7 * Portions Copyright (c) 1996-2005, 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.134 2005/06/15 07:27:44 neilc Exp $
12 *-------------------------------------------------------------------------
17 #include "access/relscan.h"
18 #include "executor/tuptable.h"
20 #include "nodes/bitmapset.h"
21 #include "nodes/params.h"
22 #include "nodes/plannodes.h"
23 #include "nodes/tidbitmap.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 CaseTestExpr nodes in expression */
117 Datum caseValue_datum;
118 bool caseValue_isNull;
120 /* Value to substitute for CoerceToDomainValue nodes in expression */
121 Datum domainValue_datum;
122 bool domainValue_isNull;
124 /* Link to containing EState */
125 struct EState *ecxt_estate;
127 /* Functions to call back when ExprContext is shut down */
128 ExprContext_CB *ecxt_callbacks;
132 * Set-result status returned by ExecEvalExpr()
136 ExprSingleResult, /* expression does not return a set */
137 ExprMultipleResult, /* this result is an element of a set */
138 ExprEndResult /* there are no more elements in the set */
142 * Return modes for functions returning sets. Note values must be chosen
143 * as separate bits so that a bitmask can be formed to indicate supported
148 SFRM_ValuePerCall = 0x01, /* one value returned per call */
149 SFRM_Materialize = 0x02 /* result set instantiated in Tuplestore */
150 } SetFunctionReturnMode;
153 * When calling a function that might return a set (multiple rows),
154 * a node of this type is passed as fcinfo->resultinfo to allow
155 * return status to be passed back. A function returning set should
156 * raise an error if no such resultinfo is provided.
158 typedef struct ReturnSetInfo
161 /* values set by caller: */
162 ExprContext *econtext; /* context function is being called in */
163 TupleDesc expectedDesc; /* tuple descriptor expected by caller */
164 int allowedModes; /* bitmask: return modes caller can handle */
165 /* result status from function (but pre-initialized by caller): */
166 SetFunctionReturnMode returnMode; /* actual return mode */
167 ExprDoneCond isDone; /* status for ValuePerCall mode */
168 /* fields filled by function in Materialize return mode: */
169 Tuplestorestate *setResult; /* holds the complete returned tuple set */
170 TupleDesc setDesc; /* actual descriptor for returned tuples */
174 * ProjectionInfo node information
176 * This is all the information needed to perform projections ---
177 * that is, form new tuples by evaluation of targetlist expressions.
178 * Nodes which need to do projections create one of these.
180 * ExecProject() evaluates the tlist, forms a tuple, and stores it
181 * in the given slot. Note that the result will be a "virtual" tuple
182 * unless ExecMaterializeSlot() is then called to force it to be
183 * converted to a physical tuple. The slot must have a tupledesc
184 * that matches the output of the tlist!
186 * The planner very often produces tlists that consist entirely of
187 * simple Var references (lower levels of a plan tree almost always
188 * look like that). So we have an optimization to handle that case
189 * with minimum overhead.
191 * targetlist target list for projection
192 * exprContext expression context in which to evaluate targetlist
193 * slot slot to place projection result in
194 * itemIsDone workspace for ExecProject
195 * isVarList TRUE if simple-Var-list optimization applies
196 * varSlotOffsets array indicating which slot each simple Var is from
197 * varNumbers array indicating attr numbers of simple Vars
198 * lastInnerVar highest attnum from inner tuple slot (0 if none)
199 * lastOuterVar highest attnum from outer tuple slot (0 if none)
200 * lastScanVar highest attnum from scan tuple slot (0 if none)
203 typedef struct ProjectionInfo
207 ExprContext *pi_exprContext;
208 TupleTableSlot *pi_slot;
209 ExprDoneCond *pi_itemIsDone;
211 int *pi_varSlotOffsets;
221 * This class is used to store information regarding junk attributes.
222 * A junk attribute is an attribute in a tuple that is needed only for
223 * storing intermediate information in the executor, and does not belong
224 * in emitted tuples. For example, when we do an UPDATE query,
225 * the planner adds a "junk" entry to the targetlist so that the tuples
226 * returned to ExecutePlan() contain an extra attribute: the ctid of
227 * the tuple to be updated. This is needed to do the update, but we
228 * don't want the ctid to be part of the stored new tuple! So, we
229 * apply a "junk filter" to remove the junk attributes and form the
232 * targetList: the original target list (including junk attributes).
233 * cleanTupType: the tuple descriptor for the "clean" tuple (with
234 * junk attributes removed).
235 * cleanMap: A map with the correspondence between the non-junk
236 * attribute numbers of the "original" tuple and the
237 * attribute numbers of the "clean" tuple.
238 * resultSlot: tuple slot used to hold cleaned tuple.
241 typedef struct JunkFilter
245 TupleDesc jf_cleanTupType;
246 AttrNumber *jf_cleanMap;
247 TupleTableSlot *jf_resultSlot;
251 * ResultRelInfo information
253 * Whenever we update an existing relation, we have to
254 * update indices on the relation, and perhaps also fire triggers.
255 * The ResultRelInfo class is used to hold all the information needed
256 * about a result relation, including indices.. -cim 10/15/89
258 * RangeTableIndex result relation's range table index
259 * RelationDesc relation descriptor for result relation
260 * NumIndices # of indices existing on result relation
261 * IndexRelationDescs array of relation descriptors for indices
262 * IndexRelationInfo array of key/attr info for indices
263 * TrigDesc triggers to be fired, if any
264 * TrigFunctions cached lookup info for trigger functions
265 * TrigInstrument optional runtime measurements for triggers
266 * ConstraintExprs array of constraint-checking expr states
267 * junkFilter for removing junk attributes from tuples
270 typedef struct ResultRelInfo
273 Index ri_RangeTableIndex;
274 Relation ri_RelationDesc;
276 RelationPtr ri_IndexRelationDescs;
277 IndexInfo **ri_IndexRelationInfo;
278 TriggerDesc *ri_TrigDesc;
279 FmgrInfo *ri_TrigFunctions;
280 struct Instrumentation *ri_TrigInstrument;
281 List **ri_ConstraintExprs;
282 JunkFilter *ri_junkFilter;
288 * Master working state for an Executor invocation
291 typedef struct EState
295 /* Basic state for all query types: */
296 ScanDirection es_direction; /* current scan direction */
297 Snapshot es_snapshot; /* time qual to use */
298 Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
299 List *es_range_table; /* List of RangeTableEntrys */
301 /* Info about target table for insert/update/delete queries: */
302 ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
303 int es_num_result_relations; /* length of array */
304 ResultRelInfo *es_result_relation_info; /* currently active array
306 JunkFilter *es_junkFilter; /* currently active junk filter */
307 Relation es_into_relation_descriptor; /* for SELECT INTO */
309 /* Parameter info: */
310 ParamListInfo es_param_list_info; /* values of external params */
311 ParamExecData *es_param_exec_vals; /* values of internal params */
313 /* Other working state: */
314 MemoryContext es_query_cxt; /* per-query context in which EState lives */
316 TupleTable es_tupleTable; /* Array of TupleTableSlots */
318 uint32 es_processed; /* # of tuples processed */
319 Oid es_lastoid; /* last oid processed (by INSERT) */
320 List *es_rowMark; /* not good place, but there is no other */
321 bool es_forUpdate; /* was it FOR UPDATE or FOR SHARE */
323 bool es_instrument; /* true requests runtime instrumentation */
324 bool es_select_into; /* true if doing SELECT INTO */
325 bool es_into_oids; /* true to generate OIDs in SELECT INTO */
327 List *es_exprcontexts; /* List of ExprContexts within EState */
330 * this ExprContext is for per-output-tuple operations, such as
331 * constraint checks and index-value computations. It will be reset
332 * for each output tuple. Note that it will be created only if
335 ExprContext *es_per_tuple_exprcontext;
337 /* Below is to re-evaluate plan qual in READ COMMITTED mode */
338 Plan *es_topPlan; /* link to top of plan tree */
339 struct evalPlanQual *es_evalPlanQual; /* chain of PlanQual
341 bool *es_evTupleNull; /* local array of EPQ status */
342 HeapTuple *es_evTuple; /* shared array of EPQ substitute tuples */
343 bool es_useEvalPlan; /* evaluating EPQ tuples? */
347 /* ----------------------------------------------------------------
350 * All-in-memory tuple hash tables are used for a number of purposes.
351 * ----------------------------------------------------------------
353 typedef struct TupleHashEntryData *TupleHashEntry;
354 typedef struct TupleHashTableData *TupleHashTable;
356 typedef struct TupleHashEntryData
358 /* firstTuple must be the first field in this struct! */
359 HeapTuple firstTuple; /* copy of first tuple in this group */
360 /* there may be additional data beyond the end of this struct */
361 } TupleHashEntryData; /* VARIABLE LENGTH STRUCT */
363 typedef struct TupleHashTableData
365 HTAB *hashtab; /* underlying dynahash table */
366 int numCols; /* number of columns in lookup key */
367 AttrNumber *keyColIdx; /* attr numbers of key columns */
368 FmgrInfo *eqfunctions; /* lookup data for comparison functions */
369 FmgrInfo *hashfunctions; /* lookup data for hash functions */
370 MemoryContext tablecxt; /* memory context containing table */
371 MemoryContext tempcxt; /* context for function evaluations */
372 Size entrysize; /* actual size to make each hash entry */
373 TupleTableSlot *tableslot; /* slot for referencing table entries */
374 TupleTableSlot *inputslot; /* current input tuple's slot */
375 } TupleHashTableData;
377 typedef HASH_SEQ_STATUS TupleHashIterator;
379 #define ResetTupleHashIterator(htable, iter) \
380 hash_seq_init(iter, (htable)->hashtab)
381 #define ScanTupleHashTable(iter) \
382 ((TupleHashEntry) hash_seq_search(iter))
385 /* ----------------------------------------------------------------
386 * Expression State Trees
388 * Each executable expression tree has a parallel ExprState tree.
390 * Unlike PlanState, there is not an exact one-for-one correspondence between
391 * ExprState node types and Expr node types. Many Expr node types have no
392 * need for node-type-specific run-time state, and so they can use plain
393 * ExprState or GenericExprState as their associated ExprState node type.
394 * ----------------------------------------------------------------
400 * ExprState is the common superclass for all ExprState-type nodes.
402 * It can also be instantiated directly for leaf Expr nodes that need no
403 * local run-time state (such as Var, Const, or Param).
405 * To save on dispatch overhead, each ExprState node contains a function
406 * pointer to the routine to execute to evaluate the node.
410 typedef struct ExprState ExprState;
412 typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
413 ExprContext *econtext,
415 ExprDoneCond *isDone);
420 Expr *expr; /* associated Expr node */
421 ExprStateEvalFunc evalfunc; /* routine to run to execute node */
425 * GenericExprState node
427 * This is used for Expr node types that need no local run-time state,
428 * but have one child Expr node.
431 typedef struct GenericExprState
434 ExprState *arg; /* state of my child node */
438 * AggrefExprState node
441 typedef struct AggrefExprState
444 ExprState *target; /* state of my child node */
445 int aggno; /* ID number for agg within its plan node */
449 * ArrayRefExprState node
451 * Note: array types can be fixed-length (typlen > 0), but only when the
452 * element type is itself fixed-length. Otherwise they are varlena structures
453 * and have typlen = -1. In any case, an array type is never pass-by-value.
456 typedef struct ArrayRefExprState
459 List *refupperindexpr; /* states for child nodes */
460 List *reflowerindexpr;
462 ExprState *refassgnexpr;
463 int16 refattrlength; /* typlen of array type */
464 int16 refelemlength; /* typlen of the array element type */
465 bool refelembyval; /* is the element type pass-by-value? */
466 char refelemalign; /* typalign of the element type */
472 * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
473 * and NullIf nodes; be careful to check what xprstate.expr is actually
477 typedef struct FuncExprState
480 List *args; /* states of argument expressions */
483 * Function manager's lookup info for the target function. If
484 * func.fn_oid is InvalidOid, we haven't initialized it yet.
489 * We also need to store argument values across calls when evaluating
490 * a function-returning-set.
492 * setArgsValid is true when we are evaluating a set-valued function and
493 * we are in the middle of a call series; we want to pass the same
494 * argument values to the function again (and again, until it returns
500 * Flag to remember whether we found a set-valued argument to the
501 * function. This causes the function result to be a set as well.
502 * Valid only when setArgsValid is true.
504 bool setHasSetArg; /* some argument returns a set */
507 * Flag to remember whether we have registered a shutdown callback for
508 * this FuncExprState. We do so only if setArgsValid has been true at
509 * least once (since all the callback is for is to clear
512 bool shutdown_reg; /* a shutdown callback is registered */
515 * Current argument data for a set-valued function; contains valid
516 * data only if setArgsValid is true.
518 FunctionCallInfoData setArgs;
522 * ScalarArrayOpExprState node
524 * This is a FuncExprState plus some additional data.
527 typedef struct ScalarArrayOpExprState
529 FuncExprState fxprstate;
530 /* Cached info about array element type */
535 } ScalarArrayOpExprState;
541 typedef struct BoolExprState
544 List *args; /* states of argument expression(s) */
551 typedef struct SubPlanState
554 EState *sub_estate; /* subselect plan has its own EState */
555 struct PlanState *planstate; /* subselect plan's state tree */
556 List *exprs; /* states of combining expression(s) */
557 List *args; /* states of argument expression(s) */
558 bool needShutdown; /* TRUE = need to shutdown subplan */
559 HeapTuple curTuple; /* copy of most recent tuple from subplan */
560 /* these are used when hashing the subselect's output: */
561 ProjectionInfo *projLeft; /* for projecting lefthand exprs */
562 ProjectionInfo *projRight; /* for projecting subselect output */
563 TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
564 TupleHashTable hashnulls; /* hash table for rows with null(s) */
565 bool havehashrows; /* TRUE if hashtable is not empty */
566 bool havenullrows; /* TRUE if hashnulls is not empty */
567 MemoryContext tablecxt; /* memory context containing tables */
568 ExprContext *innerecontext; /* working context for comparisons */
569 AttrNumber *keyColIdx; /* control data for hash tables */
570 FmgrInfo *eqfunctions; /* comparison functions for hash tables */
571 FmgrInfo *hashfunctions; /* lookup data for hash functions */
575 * FieldSelectState node
578 typedef struct FieldSelectState
581 ExprState *arg; /* input expression */
582 TupleDesc argdesc; /* tupdesc for most recent input */
586 * FieldStoreState node
589 typedef struct FieldStoreState
592 ExprState *arg; /* input tuple value */
593 List *newvals; /* new value(s) for field(s) */
594 TupleDesc argdesc; /* tupdesc for most recent input */
598 * ConvertRowtypeExprState node
601 typedef struct ConvertRowtypeExprState
604 ExprState *arg; /* input tuple value */
605 TupleDesc indesc; /* tupdesc for source rowtype */
606 TupleDesc outdesc; /* tupdesc for result rowtype */
607 AttrNumber *attrMap; /* indexes of input fields, or 0 for null */
608 Datum *invalues; /* workspace for deconstructing source */
610 Datum *outvalues; /* workspace for constructing result */
612 } ConvertRowtypeExprState;
618 typedef struct CaseExprState
621 ExprState *arg; /* implicit equality comparison argument */
622 List *args; /* the arguments (list of WHEN clauses) */
623 ExprState *defresult; /* the default result (ELSE clause) */
630 typedef struct CaseWhenState
633 ExprState *expr; /* condition expression */
634 ExprState *result; /* substitution result */
638 * ArrayExprState node
640 * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
644 typedef struct ArrayExprState
647 List *elements; /* states for child nodes */
648 int16 elemlength; /* typlen of the array element type */
649 bool elembyval; /* is the element type pass-by-value? */
650 char elemalign; /* typalign of the element type */
657 typedef struct RowExprState
660 List *args; /* the arguments */
661 TupleDesc tupdesc; /* descriptor for result tuples */
665 * CoalesceExprState node
668 typedef struct CoalesceExprState
671 List *args; /* the arguments */
675 * CoerceToDomainState node
678 typedef struct CoerceToDomainState
681 ExprState *arg; /* input expression */
682 /* Cached list of constraints that need to be checked */
683 List *constraints; /* list of DomainConstraintState nodes */
684 } CoerceToDomainState;
687 * DomainConstraintState - one item to check during CoerceToDomain
689 * Note: this is just a Node, and not an ExprState, because it has no
690 * corresponding Expr to link to. Nonetheless it is part of an ExprState
691 * tree, so we give it a name following the xxxState convention.
693 typedef enum DomainConstraintType
695 DOM_CONSTRAINT_NOTNULL,
697 } DomainConstraintType;
699 typedef struct DomainConstraintState
702 DomainConstraintType constrainttype; /* constraint type */
703 char *name; /* name of constraint (for error msgs) */
704 ExprState *check_expr; /* for CHECK, a boolean expression */
705 } DomainConstraintState;
708 /* ----------------------------------------------------------------
709 * Executor State Trees
711 * An executing query has a PlanState tree paralleling the Plan tree
712 * that describes the plan.
713 * ----------------------------------------------------------------
719 * We never actually instantiate any PlanState nodes; this is just the common
720 * abstract superclass for all PlanState-type nodes.
723 typedef struct PlanState
727 Plan *plan; /* associated Plan node */
729 EState *state; /* at execution time, state's of
730 * individual nodes point to one EState
731 * for the whole top-level plan */
733 struct Instrumentation *instrument; /* Optional runtime stats for this
737 * Common structural data for all Plan types. These links to
738 * subsidiary state trees parallel links in the associated plan tree
739 * (except for the subPlan list, which does not exist in the plan
742 List *targetlist; /* target list to be computed at this node */
743 List *qual; /* implicitly-ANDed qual conditions */
744 struct PlanState *lefttree; /* input plan tree(s) */
745 struct PlanState *righttree;
746 List *initPlan; /* Init SubPlanState nodes (un-correlated
747 * expr subselects) */
748 List *subPlan; /* SubPlanState nodes in my expressions */
751 * State for management of parameter-change-driven rescanning
753 Bitmapset *chgParam; /* set of IDs of changed Params */
756 * Other run-time state needed by most if not all node types.
758 TupleTableSlot *ps_OuterTupleSlot; /* slot for current "outer" tuple */
759 TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
760 ExprContext *ps_ExprContext; /* node's expression-evaluation context */
761 ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */
762 bool ps_TupFromTlist;/* state flag for processing set-valued
763 * functions in targetlist */
767 * these are are defined to avoid confusion problems with "left"
768 * and "right" and "inner" and "outer". The convention is that
769 * the "left" plan is the "outer" plan and the "right" plan is
770 * the inner plan, but these make the code more readable.
773 #define innerPlanState(node) (((PlanState *)(node))->righttree)
774 #define outerPlanState(node) (((PlanState *)(node))->lefttree)
778 * ResultState information
781 typedef struct ResultState
783 PlanState ps; /* its first field is NodeTag */
784 ExprState *resconstantqual;
785 bool rs_done; /* are we done? */
786 bool rs_checkqual; /* do we need to check the qual? */
790 * AppendState information
792 * nplans how many plans are in the list
793 * whichplan which plan is being executed (0 .. n-1)
794 * firstplan first plan to execute (usually 0)
795 * lastplan last plan to execute (usually n-1)
798 typedef struct AppendState
800 PlanState ps; /* its first field is NodeTag */
801 PlanState **appendplans; /* array of PlanStates for my inputs */
809 * BitmapAndState information
812 typedef struct BitmapAndState
814 PlanState ps; /* its first field is NodeTag */
815 PlanState **bitmapplans; /* array of PlanStates for my inputs */
816 int nplans; /* number of input plans */
820 * BitmapOrState information
823 typedef struct BitmapOrState
825 PlanState ps; /* its first field is NodeTag */
826 PlanState **bitmapplans; /* array of PlanStates for my inputs */
827 int nplans; /* number of input plans */
830 /* ----------------------------------------------------------------
831 * Scan State Information
832 * ----------------------------------------------------------------
836 * ScanState information
838 * ScanState extends PlanState for node types that represent
839 * scans of an underlying relation. It can also be used for nodes
840 * that scan the output of an underlying plan node --- in that case,
841 * only ScanTupleSlot is actually useful, and it refers to the tuple
842 * retrieved from the subplan.
844 * currentRelation relation being scanned (NULL if none)
845 * currentScanDesc current scan descriptor for scan (NULL if none)
846 * ScanTupleSlot pointer to slot in tuple table holding scan tuple
849 typedef struct ScanState
851 PlanState ps; /* its first field is NodeTag */
852 Relation ss_currentRelation;
853 HeapScanDesc ss_currentScanDesc;
854 TupleTableSlot *ss_ScanTupleSlot;
858 * SeqScan uses a bare ScanState as its state node, since it needs
859 * no additional fields.
861 typedef ScanState SeqScanState;
864 * IndexScanState information
866 * indexqualorig execution state for indexqualorig expressions
867 * ScanKeys Skey structures to scan index rel
868 * NumScanKeys number of Skey structs
869 * RuntimeKeyInfo array of exprstates for Skeys
870 * that will be evaluated at runtime
871 * RuntimeContext expr context for evaling runtime Skeys
872 * RuntimeKeysReady true if runtime Skeys have been computed
873 * RelationDesc index relation descriptor
874 * ScanDesc index scan descriptor
877 typedef struct IndexScanState
879 ScanState ss; /* its first field is NodeTag */
881 ScanKey iss_ScanKeys;
883 ExprState **iss_RuntimeKeyInfo;
884 ExprContext *iss_RuntimeContext;
885 bool iss_RuntimeKeysReady;
886 Relation iss_RelationDesc;
887 IndexScanDesc iss_ScanDesc;
891 * BitmapIndexScanState information
893 * result bitmap to return output into, or NULL
894 * ScanKeys Skey structures to scan index rel
895 * NumScanKeys number of Skey structs
896 * RuntimeKeyInfo array of exprstates for Skeys
897 * that will be evaluated at runtime
898 * RuntimeContext expr context for evaling runtime Skeys
899 * RuntimeKeysReady true if runtime Skeys have been computed
900 * RelationDesc index relation descriptor
901 * ScanDesc index scan descriptor
904 typedef struct BitmapIndexScanState
906 ScanState ss; /* its first field is NodeTag */
907 TIDBitmap *biss_result;
908 ScanKey biss_ScanKeys;
909 int biss_NumScanKeys;
910 ExprState **biss_RuntimeKeyInfo;
911 ExprContext *biss_RuntimeContext;
912 bool biss_RuntimeKeysReady;
913 Relation biss_RelationDesc;
914 IndexScanDesc biss_ScanDesc;
915 } BitmapIndexScanState;
918 * BitmapHeapScanState information
920 * bitmapqualorig execution state for bitmapqualorig expressions
921 * tbm bitmap obtained from child index scan(s)
922 * tbmres current-page data
923 * curslot current tbmres index or tuple offset on page
924 * minslot lowest tbmres index or tuple offset to try
925 * maxslot highest tbmres index or tuple offset to try
928 typedef struct BitmapHeapScanState
930 ScanState ss; /* its first field is NodeTag */
931 List *bitmapqualorig;
933 TBMIterateResult *tbmres;
937 } BitmapHeapScanState;
940 * TidScanState information
942 * NumTids number of tids in this scan
943 * TidPtr current tid in use
944 * TidList evaluated item pointers
947 typedef struct TidScanState
949 ScanState ss; /* its first field is NodeTag */
950 List *tss_tideval; /* list of ExprState nodes */
954 ItemPointerData *tss_TidList;
955 HeapTupleData tss_htup;
959 * SubqueryScanState information
961 * SubqueryScanState is used for scanning a sub-query in the range table.
962 * The sub-query will have its own EState, which we save here.
963 * ScanTupleSlot references the current output tuple of the sub-query.
965 * SubEState exec state for sub-query
968 typedef struct SubqueryScanState
970 ScanState ss; /* its first field is NodeTag */
972 EState *sss_SubEState;
976 * FunctionScanState information
978 * Function nodes are used to scan the results of a
979 * function appearing in FROM (typically a function returning set).
981 * tupdesc expected return tuple description
982 * tuplestorestate private state of tuplestore.c
983 * funcexpr state for function expression being evaluated
986 typedef struct FunctionScanState
988 ScanState ss; /* its first field is NodeTag */
990 Tuplestorestate *tuplestorestate;
994 /* ----------------------------------------------------------------
995 * Join State Information
996 * ----------------------------------------------------------------
1000 * JoinState information
1002 * Superclass for state nodes of join plans.
1005 typedef struct JoinState
1009 List *joinqual; /* JOIN quals (in addition to ps.qual) */
1013 * NestLoopState information
1015 * NeedNewOuter true if need new outer tuple on next call
1016 * MatchedOuter true if found a join match for current outer tuple
1017 * NullInnerTupleSlot prepared null tuple for left outer joins
1020 typedef struct NestLoopState
1022 JoinState js; /* its first field is NodeTag */
1023 bool nl_NeedNewOuter;
1024 bool nl_MatchedOuter;
1025 TupleTableSlot *nl_NullInnerTupleSlot;
1029 * MergeJoinState information
1031 * NumClauses number of mergejoinable join clauses
1032 * Clauses info for each mergejoinable clause
1033 * JoinState current "state" of join. see execdefs.h
1034 * FillOuter true if should emit unjoined outer tuples anyway
1035 * FillInner true if should emit unjoined inner tuples anyway
1036 * MatchedOuter true if found a join match for current outer tuple
1037 * MatchedInner true if found a join match for current inner tuple
1038 * OuterTupleSlot slot in tuple table for cur outer tuple
1039 * InnerTupleSlot slot in tuple table for cur inner tuple
1040 * MarkedTupleSlot slot in tuple table for marked tuple
1041 * NullOuterTupleSlot prepared null tuple for right outer joins
1042 * NullInnerTupleSlot prepared null tuple for left outer joins
1043 * OuterEContext workspace for computing outer tuple's join values
1044 * InnerEContext workspace for computing inner tuple's join values
1047 /* private in nodeMergejoin.c: */
1048 typedef struct MergeJoinClauseData *MergeJoinClause;
1050 typedef struct MergeJoinState
1052 JoinState js; /* its first field is NodeTag */
1054 MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
1058 bool mj_MatchedOuter;
1059 bool mj_MatchedInner;
1060 TupleTableSlot *mj_OuterTupleSlot;
1061 TupleTableSlot *mj_InnerTupleSlot;
1062 TupleTableSlot *mj_MarkedTupleSlot;
1063 TupleTableSlot *mj_NullOuterTupleSlot;
1064 TupleTableSlot *mj_NullInnerTupleSlot;
1065 ExprContext *mj_OuterEContext;
1066 ExprContext *mj_InnerEContext;
1070 * HashJoinState information
1072 * hj_HashTable hash table for the hashjoin
1073 * (NULL if table not built yet)
1074 * hj_CurHashValue hash value for current outer tuple
1075 * hj_CurBucketNo bucket# for current outer tuple
1076 * hj_CurTuple last inner tuple matched to current outer
1077 * tuple, or NULL if starting search
1078 * (CurHashValue, CurBucketNo and CurTuple are
1079 * undefined if OuterTupleSlot is empty!)
1080 * hj_OuterHashKeys the outer hash keys in the hashjoin condition
1081 * hj_InnerHashKeys the inner hash keys in the hashjoin condition
1082 * hj_HashOperators the join operators in the hashjoin condition
1083 * hj_OuterTupleSlot tuple slot for outer tuples
1084 * hj_HashTupleSlot tuple slot for hashed tuples
1085 * hj_NullInnerTupleSlot prepared null tuple for left outer joins
1086 * hj_NeedNewOuter true if need new outer tuple on next call
1087 * hj_MatchedOuter true if found a join match for current outer
1091 /* these structs are defined in executor/hashjoin.h: */
1092 typedef struct HashJoinTupleData *HashJoinTuple;
1093 typedef struct HashJoinTableData *HashJoinTable;
1095 typedef struct HashJoinState
1097 JoinState js; /* its first field is NodeTag */
1098 List *hashclauses; /* list of ExprState nodes */
1099 HashJoinTable hj_HashTable;
1100 uint32 hj_CurHashValue;
1102 HashJoinTuple hj_CurTuple;
1103 List *hj_OuterHashKeys; /* list of ExprState nodes */
1104 List *hj_InnerHashKeys; /* list of ExprState nodes */
1105 List *hj_HashOperators; /* list of operator OIDs */
1106 TupleTableSlot *hj_OuterTupleSlot;
1107 TupleTableSlot *hj_HashTupleSlot;
1108 TupleTableSlot *hj_NullInnerTupleSlot;
1109 bool hj_NeedNewOuter;
1110 bool hj_MatchedOuter;
1114 /* ----------------------------------------------------------------
1115 * Materialization State Information
1116 * ----------------------------------------------------------------
1120 * MaterialState information
1122 * materialize nodes are used to materialize the results
1123 * of a subplan into a temporary file.
1125 * ss.ss_ScanTupleSlot refers to output of underlying plan.
1128 typedef struct MaterialState
1130 ScanState ss; /* its first field is NodeTag */
1131 void *tuplestorestate; /* private state of tuplestore.c */
1132 bool eof_underlying; /* reached end of underlying plan? */
1136 * SortState information
1139 typedef struct SortState
1141 ScanState ss; /* its first field is NodeTag */
1142 bool sort_Done; /* sort completed yet? */
1143 void *tuplesortstate; /* private state of tuplesort.c */
1146 /* ---------------------
1147 * GroupState information
1148 * -------------------------
1150 typedef struct GroupState
1152 ScanState ss; /* its first field is NodeTag */
1153 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1154 bool grp_done; /* indicates completion of Group scan */
1157 /* ---------------------
1158 * AggState information
1160 * ss.ss_ScanTupleSlot refers to output of underlying plan.
1162 * Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
1163 * ecxt_aggnulls arrays, which hold the computed agg values for the current
1164 * input group during evaluation of an Agg node's output tuple(s). We
1165 * create a second ExprContext, tmpcontext, in which to evaluate input
1166 * expressions and run the aggregate transition functions.
1167 * -------------------------
1169 /* these structs are private in nodeAgg.c: */
1170 typedef struct AggStatePerAggData *AggStatePerAgg;
1171 typedef struct AggStatePerGroupData *AggStatePerGroup;
1173 typedef struct AggState
1175 ScanState ss; /* its first field is NodeTag */
1176 List *aggs; /* all Aggref nodes in targetlist & quals */
1177 int numaggs; /* length of list (could be zero!) */
1178 FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
1179 FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1180 AggStatePerAgg peragg; /* per-Aggref information */
1181 MemoryContext aggcontext; /* memory context for long-lived data */
1182 ExprContext *tmpcontext; /* econtext for input expressions */
1183 bool agg_done; /* indicates completion of Agg scan */
1184 /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
1185 AggStatePerGroup pergroup; /* per-Aggref-per-group working state */
1186 HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1187 /* these fields are used in AGG_HASHED mode: */
1188 TupleHashTable hashtable; /* hash table with one entry per group */
1189 bool table_filled; /* hash table filled yet? */
1190 TupleHashIterator hashiter; /* for iterating through hash table */
1194 * UniqueState information
1196 * Unique nodes are used "on top of" sort nodes to discard
1197 * duplicate tuples returned from the sort phase. Basically
1198 * all it does is compare the current tuple from the subplan
1199 * with the previously fetched tuple (stored in its result slot).
1200 * If the two are identical in all interesting fields, then
1201 * we just fetch another tuple from the sort and try again.
1204 typedef struct UniqueState
1206 PlanState ps; /* its first field is NodeTag */
1207 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1208 MemoryContext tempContext; /* short-term context for comparisons */
1212 * HashState information
1215 typedef struct HashState
1217 PlanState ps; /* its first field is NodeTag */
1218 HashJoinTable hashtable; /* hash table for the hashjoin */
1219 List *hashkeys; /* list of ExprState nodes */
1220 /* hashkeys is same as parent's hj_InnerHashKeys */
1221 TupleTableSlot *firstTuple; /* tuple produced by ExecHash() */
1225 * SetOpState information
1227 * SetOp nodes are used "on top of" sort nodes to discard
1228 * duplicate tuples returned from the sort phase. These are
1229 * more complex than a simple Unique since we have to count
1230 * how many duplicates to return.
1233 typedef struct SetOpState
1235 PlanState ps; /* its first field is NodeTag */
1236 FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1237 bool subplan_done; /* has subplan returned EOF? */
1238 long numLeft; /* number of left-input dups of cur group */
1239 long numRight; /* number of right-input dups of cur group */
1240 long numOutput; /* number of dups left to output */
1241 MemoryContext tempContext; /* short-term context for comparisons */
1245 * LimitState information
1247 * Limit nodes are used to enforce LIMIT/OFFSET clauses.
1248 * They just select the desired subrange of their subplan's output.
1250 * offset is the number of initial tuples to skip (0 does nothing).
1251 * count is the number of tuples to return after skipping the offset tuples.
1252 * If no limit count was specified, count is undefined and noCount is true.
1253 * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
1258 LIMIT_INITIAL, /* initial state for LIMIT node */
1259 LIMIT_EMPTY, /* there are no returnable rows */
1260 LIMIT_INWINDOW, /* have returned a row in the window */
1261 LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */
1262 LIMIT_WINDOWEND, /* stepped off end of window */
1263 LIMIT_WINDOWSTART /* stepped off beginning of window */
1266 typedef struct LimitState
1268 PlanState ps; /* its first field is NodeTag */
1269 ExprState *limitOffset; /* OFFSET parameter, or NULL if none */
1270 ExprState *limitCount; /* COUNT parameter, or NULL if none */
1271 long offset; /* current OFFSET value */
1272 long count; /* current COUNT, if any */
1273 bool noCount; /* if true, ignore count */
1274 LimitStateCond lstate; /* state machine status, as above */
1275 long position; /* 1-based index of last tuple returned */
1276 TupleTableSlot *subSlot; /* tuple last obtained from subplan */
1279 #endif /* EXECNODES_H */