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.122 2004-12-31 22:03:34 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 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.
179
* In theory, when a node wants to perform a projection
180
* it should just update this information as necessary and then
181
* call ExecProject(). -cim 6/3/91
183
* ExecProject() evaluates the tlist, forms a tuple, and stores it
184
* in the given slot. As a side-effect, the actual datum values and
185
* null indicators are placed in the work arrays tupValues/tupNulls.
187
* targetlist target list for projection
188
* exprContext expression context in which to evaluate targetlist
189
* slot slot to place projection result in
190
* tupValues array of computed values
191
* tupNull array of null indicators
192
* itemIsDone workspace for ExecProject
195
typedef struct ProjectionInfo
199
ExprContext *pi_exprContext;
200
TupleTableSlot *pi_slot;
203
ExprDoneCond *pi_itemIsDone;
209
* This class is used to store information regarding junk attributes.
210
* A junk attribute is an attribute in a tuple that is needed only for
211
* storing intermediate information in the executor, and does not belong
212
* in emitted tuples. For example, when we do an UPDATE query,
213
* the planner adds a "junk" entry to the targetlist so that the tuples
214
* returned to ExecutePlan() contain an extra attribute: the ctid of
215
* the tuple to be updated. This is needed to do the update, but we
216
* don't want the ctid to be part of the stored new tuple! So, we
217
* apply a "junk filter" to remove the junk attributes and form the
220
* targetList: the original target list (including junk attributes).
221
* cleanTupType: the tuple descriptor for the "clean" tuple (with
222
* junk attributes removed).
223
* cleanMap: A map with the correspondence between the non-junk
224
* attribute numbers of the "original" tuple and the
225
* attribute numbers of the "clean" tuple.
226
* resultSlot: tuple slot that can be used to hold cleaned tuple.
229
typedef struct JunkFilter
233
TupleDesc jf_cleanTupType;
234
AttrNumber *jf_cleanMap;
235
TupleTableSlot *jf_resultSlot;
239
* ResultRelInfo information
241
* Whenever we update an existing relation, we have to
242
* update indices on the relation, and perhaps also fire triggers.
243
* The ResultRelInfo class is used to hold all the information needed
244
* about a result relation, including indices.. -cim 10/15/89
246
* RangeTableIndex result relation's range table index
247
* RelationDesc relation descriptor for result relation
248
* NumIndices # of indices existing on result relation
249
* IndexRelationDescs array of relation descriptors for indices
250
* IndexRelationInfo array of key/attr info for indices
251
* TrigDesc triggers to be fired, if any
252
* TrigFunctions cached lookup info for trigger functions
253
* ConstraintExprs array of constraint-checking expr states
254
* junkFilter for removing junk attributes from tuples
257
typedef struct ResultRelInfo
260
Index ri_RangeTableIndex;
261
Relation ri_RelationDesc;
263
RelationPtr ri_IndexRelationDescs;
264
IndexInfo **ri_IndexRelationInfo;
265
TriggerDesc *ri_TrigDesc;
266
FmgrInfo *ri_TrigFunctions;
267
List **ri_ConstraintExprs;
268
JunkFilter *ri_junkFilter;
274
* Master working state for an Executor invocation
277
typedef struct EState
281
/* Basic state for all query types: */
282
ScanDirection es_direction; /* current scan direction */
283
Snapshot es_snapshot; /* time qual to use */
284
Snapshot es_crosscheck_snapshot; /* crosscheck time qual for RI */
285
List *es_range_table; /* List of RangeTableEntrys */
287
/* Info about target table for insert/update/delete queries: */
288
ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
289
int es_num_result_relations; /* length of array */
290
ResultRelInfo *es_result_relation_info; /* currently active array
292
JunkFilter *es_junkFilter; /* currently active junk filter */
293
Relation es_into_relation_descriptor; /* for SELECT INTO */
295
/* Parameter info: */
296
ParamListInfo es_param_list_info; /* values of external params */
297
ParamExecData *es_param_exec_vals; /* values of internal params */
299
/* Other working state: */
300
MemoryContext es_query_cxt; /* per-query context in which EState lives */
302
TupleTable es_tupleTable; /* Array of TupleTableSlots */
304
uint32 es_processed; /* # of tuples processed */
305
Oid es_lastoid; /* last oid processed (by INSERT) */
306
List *es_rowMark; /* not good place, but there is no other */
308
bool es_instrument; /* true requests runtime instrumentation */
309
bool es_select_into; /* true if doing SELECT INTO */
310
bool es_into_oids; /* true to generate OIDs in SELECT INTO */
312
List *es_exprcontexts; /* List of ExprContexts within EState */
315
* this ExprContext is for per-output-tuple operations, such as
316
* constraint checks and index-value computations. It will be reset
317
* for each output tuple. Note that it will be created only if
320
ExprContext *es_per_tuple_exprcontext;
322
/* Below is to re-evaluate plan qual in READ COMMITTED mode */
323
Plan *es_topPlan; /* link to top of plan tree */
324
struct evalPlanQual *es_evalPlanQual; /* chain of PlanQual
326
bool *es_evTupleNull; /* local array of EPQ status */
327
HeapTuple *es_evTuple; /* shared array of EPQ substitute tuples */
328
bool es_useEvalPlan; /* evaluating EPQ tuples? */
332
/* ----------------------------------------------------------------
335
* All-in-memory tuple hash tables are used for a number of purposes.
336
* ----------------------------------------------------------------
338
typedef struct TupleHashEntryData *TupleHashEntry;
339
typedef struct TupleHashTableData *TupleHashTable;
341
typedef struct TupleHashEntryData
343
/* firstTuple must be the first field in this struct! */
344
HeapTuple firstTuple; /* copy of first tuple in this group */
345
/* there may be additional data beyond the end of this struct */
346
} TupleHashEntryData; /* VARIABLE LENGTH STRUCT */
348
typedef struct TupleHashTableData
350
HTAB *hashtab; /* underlying dynahash table */
351
int numCols; /* number of columns in lookup key */
352
AttrNumber *keyColIdx; /* attr numbers of key columns */
353
FmgrInfo *eqfunctions; /* lookup data for comparison functions */
354
FmgrInfo *hashfunctions; /* lookup data for hash functions */
355
MemoryContext tablecxt; /* memory context containing table */
356
MemoryContext tempcxt; /* context for function evaluations */
357
Size entrysize; /* actual size to make each hash entry */
358
TupleDesc tupdesc; /* tuple descriptor */
359
} TupleHashTableData;
361
typedef HASH_SEQ_STATUS TupleHashIterator;
363
#define ResetTupleHashIterator(htable, iter) \
364
hash_seq_init(iter, (htable)->hashtab)
365
#define ScanTupleHashTable(iter) \
366
((TupleHashEntry) hash_seq_search(iter))
369
/* ----------------------------------------------------------------
370
* Expression State Trees
372
* Each executable expression tree has a parallel ExprState tree.
374
* Unlike PlanState, there is not an exact one-for-one correspondence between
375
* ExprState node types and Expr node types. Many Expr node types have no
376
* need for node-type-specific run-time state, and so they can use plain
377
* ExprState or GenericExprState as their associated ExprState node type.
378
* ----------------------------------------------------------------
384
* ExprState is the common superclass for all ExprState-type nodes.
386
* It can also be instantiated directly for leaf Expr nodes that need no
387
* local run-time state (such as Var, Const, or Param).
389
* To save on dispatch overhead, each ExprState node contains a function
390
* pointer to the routine to execute to evaluate the node.
394
typedef struct ExprState ExprState;
396
typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
397
ExprContext *econtext,
399
ExprDoneCond *isDone);
404
Expr *expr; /* associated Expr node */
405
ExprStateEvalFunc evalfunc; /* routine to run to execute node */
409
* GenericExprState node
411
* This is used for Expr node types that need no local run-time state,
412
* but have one child Expr node.
415
typedef struct GenericExprState
418
ExprState *arg; /* state of my child node */
422
* AggrefExprState node
425
typedef struct AggrefExprState
428
ExprState *target; /* state of my child node */
429
int aggno; /* ID number for agg within its plan node */
433
* ArrayRefExprState node
435
* Note: array types can be fixed-length (typlen > 0), but only when the
436
* element type is itself fixed-length. Otherwise they are varlena structures
437
* and have typlen = -1. In any case, an array type is never pass-by-value.
440
typedef struct ArrayRefExprState
443
List *refupperindexpr; /* states for child nodes */
444
List *reflowerindexpr;
446
ExprState *refassgnexpr;
447
int16 refattrlength; /* typlen of array type */
448
int16 refelemlength; /* typlen of the array element type */
449
bool refelembyval; /* is the element type pass-by-value? */
450
char refelemalign; /* typalign of the element type */
456
* Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
457
* and NullIf nodes; be careful to check what xprstate.expr is actually
461
typedef struct FuncExprState
464
List *args; /* states of argument expressions */
467
* Function manager's lookup info for the target function. If
468
* func.fn_oid is InvalidOid, we haven't initialized it yet.
473
* We also need to store argument values across calls when evaluating
474
* a function-returning-set.
476
* setArgsValid is true when we are evaluating a set-valued function and
477
* we are in the middle of a call series; we want to pass the same
478
* argument values to the function again (and again, until it returns
484
* Flag to remember whether we found a set-valued argument to the
485
* function. This causes the function result to be a set as well.
486
* Valid only when setArgsValid is true.
488
bool setHasSetArg; /* some argument returns a set */
491
* Flag to remember whether we have registered a shutdown callback for
492
* this FuncExprState. We do so only if setArgsValid has been true at
493
* least once (since all the callback is for is to clear
496
bool shutdown_reg; /* a shutdown callback is registered */
499
* Current argument data for a set-valued function; contains valid
500
* data only if setArgsValid is true.
502
FunctionCallInfoData setArgs;
506
* ScalarArrayOpExprState node
508
* This is a FuncExprState plus some additional data.
511
typedef struct ScalarArrayOpExprState
513
FuncExprState fxprstate;
514
/* Cached info about array element type */
519
} ScalarArrayOpExprState;
525
typedef struct BoolExprState
528
List *args; /* states of argument expression(s) */
535
typedef struct SubPlanState
538
EState *sub_estate; /* subselect plan has its own EState */
539
struct PlanState *planstate; /* subselect plan's state tree */
540
List *exprs; /* states of combining expression(s) */
541
List *args; /* states of argument expression(s) */
542
bool needShutdown; /* TRUE = need to shutdown subplan */
543
HeapTuple curTuple; /* copy of most recent tuple from subplan */
544
/* these are used when hashing the subselect's output: */
545
ProjectionInfo *projLeft; /* for projecting lefthand exprs */
546
ProjectionInfo *projRight; /* for projecting subselect output */
547
TupleHashTable hashtable; /* hash table for no-nulls subselect rows */
548
TupleHashTable hashnulls; /* hash table for rows with null(s) */
549
bool havehashrows; /* TRUE if hashtable is not empty */
550
bool havenullrows; /* TRUE if hashnulls is not empty */
551
MemoryContext tablecxt; /* memory context containing tables */
552
ExprContext *innerecontext; /* working context for comparisons */
553
AttrNumber *keyColIdx; /* control data for hash tables */
554
FmgrInfo *eqfunctions; /* comparison functions for hash tables */
555
FmgrInfo *hashfunctions; /* lookup data for hash functions */
559
* FieldSelectState node
562
typedef struct FieldSelectState
565
ExprState *arg; /* input expression */
566
TupleDesc argdesc; /* tupdesc for most recent input */
570
* FieldStoreState node
573
typedef struct FieldStoreState
576
ExprState *arg; /* input tuple value */
577
List *newvals; /* new value(s) for field(s) */
578
TupleDesc argdesc; /* tupdesc for most recent input */
582
* ConvertRowtypeExprState node
585
typedef struct ConvertRowtypeExprState
588
ExprState *arg; /* input tuple value */
589
TupleDesc indesc; /* tupdesc for source rowtype */
590
TupleDesc outdesc; /* tupdesc for result rowtype */
591
AttrNumber *attrMap; /* indexes of input fields, or 0 for null */
592
Datum *invalues; /* workspace for deconstructing source */
594
Datum *outvalues; /* workspace for constructing result */
596
} ConvertRowtypeExprState;
602
typedef struct CaseExprState
605
ExprState *arg; /* implicit equality comparison argument */
606
List *args; /* the arguments (list of WHEN clauses) */
607
ExprState *defresult; /* the default result (ELSE clause) */
614
typedef struct CaseWhenState
617
ExprState *expr; /* condition expression */
618
ExprState *result; /* substitution result */
622
* ArrayExprState node
624
* Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
628
typedef struct ArrayExprState
631
List *elements; /* states for child nodes */
632
int16 elemlength; /* typlen of the array element type */
633
bool elembyval; /* is the element type pass-by-value? */
634
char elemalign; /* typalign of the element type */
641
typedef struct RowExprState
644
List *args; /* the arguments */
645
TupleDesc tupdesc; /* descriptor for result tuples */
649
* CoalesceExprState node
652
typedef struct CoalesceExprState
655
List *args; /* the arguments */
659
* CoerceToDomainState node
662
typedef struct CoerceToDomainState
665
ExprState *arg; /* input expression */
666
/* Cached list of constraints that need to be checked */
667
List *constraints; /* list of DomainConstraintState nodes */
668
} CoerceToDomainState;
671
* DomainConstraintState - one item to check during CoerceToDomain
673
* Note: this is just a Node, and not an ExprState, because it has no
674
* corresponding Expr to link to. Nonetheless it is part of an ExprState
675
* tree, so we give it a name following the xxxState convention.
677
typedef enum DomainConstraintType
679
DOM_CONSTRAINT_NOTNULL,
681
} DomainConstraintType;
683
typedef struct DomainConstraintState
686
DomainConstraintType constrainttype; /* constraint type */
687
char *name; /* name of constraint (for error msgs) */
688
ExprState *check_expr; /* for CHECK, a boolean expression */
689
} DomainConstraintState;
692
/* ----------------------------------------------------------------
693
* Executor State Trees
695
* An executing query has a PlanState tree paralleling the Plan tree
696
* that describes the plan.
697
* ----------------------------------------------------------------
703
* We never actually instantiate any PlanState nodes; this is just the common
704
* abstract superclass for all PlanState-type nodes.
707
typedef struct PlanState
711
Plan *plan; /* associated Plan node */
713
EState *state; /* at execution time, state's of
714
* individual nodes point to one EState
715
* for the whole top-level plan */
717
struct Instrumentation *instrument; /* Optional runtime stats for this
721
* Common structural data for all Plan types. These links to
722
* subsidiary state trees parallel links in the associated plan tree
723
* (except for the subPlan list, which does not exist in the plan
726
List *targetlist; /* target list to be computed at this node */
727
List *qual; /* implicitly-ANDed qual conditions */
728
struct PlanState *lefttree; /* input plan tree(s) */
729
struct PlanState *righttree;
730
List *initPlan; /* Init SubPlanState nodes (un-correlated
731
* expr subselects) */
732
List *subPlan; /* SubPlanState nodes in my expressions */
735
* State for management of parameter-change-driven rescanning
737
Bitmapset *chgParam; /* set of IDs of changed Params */
740
* Other run-time state needed by most if not all node types.
742
TupleTableSlot *ps_OuterTupleSlot; /* slot for current "outer" tuple */
743
TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
744
ExprContext *ps_ExprContext; /* node's expression-evaluation context */
745
ProjectionInfo *ps_ProjInfo; /* info for doing tuple projection */
746
bool ps_TupFromTlist;/* state flag for processing set-valued
747
* functions in targetlist */
751
* these are are defined to avoid confusion problems with "left"
752
* and "right" and "inner" and "outer". The convention is that
753
* the "left" plan is the "outer" plan and the "right" plan is
754
* the inner plan, but these make the code more readable.
757
#define innerPlanState(node) (((PlanState *)(node))->righttree)
758
#define outerPlanState(node) (((PlanState *)(node))->lefttree)
762
* ResultState information
765
typedef struct ResultState
767
PlanState ps; /* its first field is NodeTag */
768
ExprState *resconstantqual;
769
bool rs_done; /* are we done? */
770
bool rs_checkqual; /* do we need to check the qual? */
774
* AppendState information
776
* nplans how many plans are in the list
777
* whichplan which plan is being executed (0 .. n-1)
778
* firstplan first plan to execute (usually 0)
779
* lastplan last plan to execute (usually n-1)
782
typedef struct AppendState
784
PlanState ps; /* its first field is NodeTag */
785
PlanState **appendplans; /* array of PlanStates for my inputs */
792
/* ----------------------------------------------------------------
793
* Scan State Information
794
* ----------------------------------------------------------------
798
* ScanState information
800
* ScanState extends PlanState for node types that represent
801
* scans of an underlying relation. It can also be used for nodes
802
* that scan the output of an underlying plan node --- in that case,
803
* only ScanTupleSlot is actually useful, and it refers to the tuple
804
* retrieved from the subplan.
806
* currentRelation relation being scanned (NULL if none)
807
* currentScanDesc current scan descriptor for scan (NULL if none)
808
* ScanTupleSlot pointer to slot in tuple table holding scan tuple
811
typedef struct ScanState
813
PlanState ps; /* its first field is NodeTag */
814
Relation ss_currentRelation;
815
HeapScanDesc ss_currentScanDesc;
816
TupleTableSlot *ss_ScanTupleSlot;
820
* SeqScan uses a bare ScanState as its state node, since it needs
821
* no additional fields.
823
typedef ScanState SeqScanState;
826
* IndexScanState information
828
* indxqualorig execution state for indxqualorig expressions
829
* NumIndices number of indices in this scan
830
* IndexPtr current index in use
831
* MarkIndexPtr IndexPtr for marked scan point
832
* ScanKeys Skey structures to scan index rels
833
* NumScanKeys array of no of keys in each Skey struct
834
* RuntimeKeyInfo array of array of exprstates for Skeys
835
* that will be evaluated at runtime
836
* RuntimeContext expr context for evaling runtime Skeys
837
* RuntimeKeysReady true if runtime Skeys have been computed
838
* RelationDescs ptr to array of relation descriptors
839
* ScanDescs ptr to array of scan descriptors
840
* LossyQuals ptr to array of qual lists for lossy operators
841
* DupHash hashtable for recognizing dups in multiple scan
842
* MaxHash max # entries we will allow in hashtable
845
typedef struct IndexScanState
847
ScanState ss; /* its first field is NodeTag */
851
int iss_MarkIndexPtr;
852
ScanKey *iss_ScanKeys;
853
int *iss_NumScanKeys;
854
ExprState ***iss_RuntimeKeyInfo;
855
ExprContext *iss_RuntimeContext;
856
bool iss_RuntimeKeysReady;
857
RelationPtr iss_RelationDescs;
858
IndexScanDescPtr iss_ScanDescs;
859
List **iss_LossyQuals;
865
* TidScanState information
867
* NumTids number of tids in this scan
868
* TidPtr current tid in use
869
* TidList evaluated item pointers
872
typedef struct TidScanState
874
ScanState ss; /* its first field is NodeTag */
875
List *tss_tideval; /* list of ExprState nodes */
879
ItemPointerData *tss_TidList;
880
HeapTupleData tss_htup;
884
* SubqueryScanState information
886
* SubqueryScanState is used for scanning a sub-query in the range table.
887
* The sub-query will have its own EState, which we save here.
888
* ScanTupleSlot references the current output tuple of the sub-query.
890
* SubEState exec state for sub-query
893
typedef struct SubqueryScanState
895
ScanState ss; /* its first field is NodeTag */
897
EState *sss_SubEState;
901
* FunctionScanState information
903
* Function nodes are used to scan the results of a
904
* function appearing in FROM (typically a function returning set).
906
* tupdesc expected return tuple description
907
* tuplestorestate private state of tuplestore.c
908
* funcexpr state for function expression being evaluated
911
typedef struct FunctionScanState
913
ScanState ss; /* its first field is NodeTag */
915
Tuplestorestate *tuplestorestate;
919
/* ----------------------------------------------------------------
920
* Join State Information
921
* ----------------------------------------------------------------
925
* JoinState information
927
* Superclass for state nodes of join plans.
930
typedef struct JoinState
934
List *joinqual; /* JOIN quals (in addition to ps.qual) */
938
* NestLoopState information
940
* NeedNewOuter true if need new outer tuple on next call
941
* MatchedOuter true if found a join match for current outer tuple
942
* NullInnerTupleSlot prepared null tuple for left outer joins
945
typedef struct NestLoopState
947
JoinState js; /* its first field is NodeTag */
948
bool nl_NeedNewOuter;
949
bool nl_MatchedOuter;
950
TupleTableSlot *nl_NullInnerTupleSlot;
954
* MergeJoinState information
956
* OuterSkipQual outerKey1 < innerKey1 ...
957
* InnerSkipQual outerKey1 > innerKey1 ...
958
* JoinState current "state" of join. see executor.h
959
* MatchedOuter true if found a join match for current outer tuple
960
* MatchedInner true if found a join match for current inner tuple
961
* OuterTupleSlot pointer to slot in tuple table for cur outer tuple
962
* InnerTupleSlot pointer to slot in tuple table for cur inner tuple
963
* MarkedTupleSlot pointer to slot in tuple table for marked tuple
964
* NullOuterTupleSlot prepared null tuple for right outer joins
965
* NullInnerTupleSlot prepared null tuple for left outer joins
968
typedef struct MergeJoinState
970
JoinState js; /* its first field is NodeTag */
971
List *mergeclauses; /* list of ExprState nodes */
972
List *mj_OuterSkipQual; /* list of ExprState nodes */
973
List *mj_InnerSkipQual; /* list of ExprState nodes */
975
bool mj_MatchedOuter;
976
bool mj_MatchedInner;
977
TupleTableSlot *mj_OuterTupleSlot;
978
TupleTableSlot *mj_InnerTupleSlot;
979
TupleTableSlot *mj_MarkedTupleSlot;
980
TupleTableSlot *mj_NullOuterTupleSlot;
981
TupleTableSlot *mj_NullInnerTupleSlot;
985
* HashJoinState information
987
* hj_HashTable hash table for the hashjoin
988
* hj_CurBucketNo bucket# for current outer tuple
989
* hj_CurTuple last inner tuple matched to current outer
990
* tuple, or NULL if starting search
991
* (CurBucketNo and CurTuple are meaningless
992
* unless OuterTupleSlot is nonempty!)
993
* hj_OuterHashKeys the outer hash keys in the hashjoin condition
994
* hj_InnerHashKeys the inner hash keys in the hashjoin condition
995
* hj_HashOperators the join operators in the hashjoin condition
996
* hj_OuterTupleSlot tuple slot for outer tuples
997
* hj_HashTupleSlot tuple slot for hashed tuples
998
* hj_NullInnerTupleSlot prepared null tuple for left outer joins
999
* hj_NeedNewOuter true if need new outer tuple on next call
1000
* hj_MatchedOuter true if found a join match for current outer
1001
* hj_hashdone true if hash-table-build phase is done
1004
typedef struct HashJoinState
1006
JoinState js; /* its first field is NodeTag */
1007
List *hashclauses; /* list of ExprState nodes */
1008
HashJoinTable hj_HashTable;
1010
HashJoinTuple hj_CurTuple;
1011
List *hj_OuterHashKeys; /* list of ExprState nodes */
1012
List *hj_InnerHashKeys; /* list of ExprState nodes */
1013
List *hj_HashOperators; /* list of operator OIDs */
1014
TupleTableSlot *hj_OuterTupleSlot;
1015
TupleTableSlot *hj_HashTupleSlot;
1016
TupleTableSlot *hj_NullInnerTupleSlot;
1017
bool hj_NeedNewOuter;
1018
bool hj_MatchedOuter;
1023
/* ----------------------------------------------------------------
1024
* Materialization State Information
1025
* ----------------------------------------------------------------
1029
* MaterialState information
1031
* materialize nodes are used to materialize the results
1032
* of a subplan into a temporary file.
1034
* ss.ss_ScanTupleSlot refers to output of underlying plan.
1037
typedef struct MaterialState
1039
ScanState ss; /* its first field is NodeTag */
1040
void *tuplestorestate; /* private state of tuplestore.c */
1041
bool eof_underlying; /* reached end of underlying plan? */
1045
* SortState information
1048
typedef struct SortState
1050
ScanState ss; /* its first field is NodeTag */
1051
bool sort_Done; /* sort completed yet? */
1052
void *tuplesortstate; /* private state of tuplesort.c */
1055
/* ---------------------
1056
* GroupState information
1057
* -------------------------
1059
typedef struct GroupState
1061
ScanState ss; /* its first field is NodeTag */
1062
FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1063
HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1064
bool grp_done; /* indicates completion of Group scan */
1067
/* ---------------------
1068
* AggState information
1070
* ss.ss_ScanTupleSlot refers to output of underlying plan.
1072
* Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
1073
* ecxt_aggnulls arrays, which hold the computed agg values for the current
1074
* input group during evaluation of an Agg node's output tuple(s). We
1075
* create a second ExprContext, tmpcontext, in which to evaluate input
1076
* expressions and run the aggregate transition functions.
1077
* -------------------------
1079
/* these structs are private in nodeAgg.c: */
1080
typedef struct AggStatePerAggData *AggStatePerAgg;
1081
typedef struct AggStatePerGroupData *AggStatePerGroup;
1083
typedef struct AggState
1085
ScanState ss; /* its first field is NodeTag */
1086
List *aggs; /* all Aggref nodes in targetlist & quals */
1087
int numaggs; /* length of list (could be zero!) */
1088
FmgrInfo *eqfunctions; /* per-grouping-field equality fns */
1089
FmgrInfo *hashfunctions; /* per-grouping-field hash fns */
1090
AggStatePerAgg peragg; /* per-Aggref information */
1091
MemoryContext aggcontext; /* memory context for long-lived data */
1092
ExprContext *tmpcontext; /* econtext for input expressions */
1093
bool agg_done; /* indicates completion of Agg scan */
1094
/* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
1095
AggStatePerGroup pergroup; /* per-Aggref-per-group working state */
1096
HeapTuple grp_firstTuple; /* copy of first tuple of current group */
1097
/* these fields are used in AGG_HASHED mode: */
1098
TupleHashTable hashtable; /* hash table with one entry per group */
1099
bool table_filled; /* hash table filled yet? */
1100
TupleHashIterator hashiter; /* for iterating through hash table */
1104
* UniqueState information
1106
* Unique nodes are used "on top of" sort nodes to discard
1107
* duplicate tuples returned from the sort phase. Basically
1108
* all it does is compare the current tuple from the subplan
1109
* with the previously fetched tuple stored in priorTuple.
1110
* If the two are identical in all interesting fields, then
1111
* we just fetch another tuple from the sort and try again.
1114
typedef struct UniqueState
1116
PlanState ps; /* its first field is NodeTag */
1117
FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1118
HeapTuple priorTuple; /* most recently returned tuple, or NULL */
1119
MemoryContext tempContext; /* short-term context for comparisons */
1123
* HashState information
1126
typedef struct HashState
1128
PlanState ps; /* its first field is NodeTag */
1129
HashJoinTable hashtable; /* hash table for the hashjoin */
1130
List *hashkeys; /* list of ExprState nodes */
1131
/* hashkeys is same as parent's hj_InnerHashKeys */
1135
* SetOpState information
1137
* SetOp nodes are used "on top of" sort nodes to discard
1138
* duplicate tuples returned from the sort phase. These are
1139
* more complex than a simple Unique since we have to count
1140
* how many duplicates to return.
1143
typedef struct SetOpState
1145
PlanState ps; /* its first field is NodeTag */
1146
FmgrInfo *eqfunctions; /* per-field lookup data for equality fns */
1147
bool subplan_done; /* has subplan returned EOF? */
1148
long numLeft; /* number of left-input dups of cur group */
1149
long numRight; /* number of right-input dups of cur group */
1150
long numOutput; /* number of dups left to output */
1151
MemoryContext tempContext; /* short-term context for comparisons */
1155
* LimitState information
1157
* Limit nodes are used to enforce LIMIT/OFFSET clauses.
1158
* They just select the desired subrange of their subplan's output.
1160
* offset is the number of initial tuples to skip (0 does nothing).
1161
* count is the number of tuples to return after skipping the offset tuples.
1162
* If no limit count was specified, count is undefined and noCount is true.
1163
* When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
1168
LIMIT_INITIAL, /* initial state for LIMIT node */
1169
LIMIT_EMPTY, /* there are no returnable rows */
1170
LIMIT_INWINDOW, /* have returned a row in the window */
1171
LIMIT_SUBPLANEOF, /* at EOF of subplan (within window) */
1172
LIMIT_WINDOWEND, /* stepped off end of window */
1173
LIMIT_WINDOWSTART /* stepped off beginning of window */
1176
typedef struct LimitState
1178
PlanState ps; /* its first field is NodeTag */
1179
ExprState *limitOffset; /* OFFSET parameter, or NULL if none */
1180
ExprState *limitCount; /* COUNT parameter, or NULL if none */
1181
long offset; /* current OFFSET value */
1182
long count; /* current COUNT, if any */
1183
bool noCount; /* if true, ignore count */
1184
LimitStateCond lstate; /* state machine status, as above */
1185
long position; /* 1-based index of last tuple returned */
1186
TupleTableSlot *subSlot; /* tuple last obtained from subplan */
1189
#endif /* EXECNODES_H */