]> granicus.if.org Git - postgresql/blob - src/include/nodes/execnodes.h
Implement an API to let foreign-data wrappers actually be functional.
[postgresql] / src / include / nodes / execnodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * execnodes.h
4  *        definitions for executor state nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/nodes/execnodes.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef EXECNODES_H
15 #define EXECNODES_H
16
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "access/skey.h"
20 #include "nodes/params.h"
21 #include "nodes/plannodes.h"
22 #include "nodes/tidbitmap.h"
23 #include "utils/hsearch.h"
24 #include "utils/rel.h"
25 #include "utils/snapshot.h"
26 #include "utils/tuplestore.h"
27
28
29 /* ----------------
30  *        IndexInfo information
31  *
32  *              this struct holds the information needed to construct new index
33  *              entries for a particular index.  Used for both index_build and
34  *              retail creation of index entries.
35  *
36  *              NumIndexAttrs           number of columns in this index
37  *              KeyAttrNumbers          underlying-rel attribute numbers used as keys
38  *                                                      (zeroes indicate expressions)
39  *              Expressions                     expr trees for expression entries, or NIL if none
40  *              ExpressionsState        exec state for expressions, or NIL if none
41  *              Predicate                       partial-index predicate, or NIL if none
42  *              PredicateState          exec state for predicate, or NIL if none
43  *              ExclusionOps            Per-column exclusion operators, or NULL if none
44  *              ExclusionProcs          Underlying function OIDs for ExclusionOps
45  *              ExclusionStrats         Opclass strategy numbers for ExclusionOps
46  *              Unique                          is it a unique index?
47  *              ReadyForInserts         is it valid for inserts?
48  *              Concurrent                      are we doing a concurrent index build?
49  *              BrokenHotChain          did we detect any broken HOT chains?
50  *
51  * ii_Concurrent and ii_BrokenHotChain are used only during index build;
52  * they're conventionally set to false otherwise.
53  * ----------------
54  */
55 typedef struct IndexInfo
56 {
57         NodeTag         type;
58         int                     ii_NumIndexAttrs;
59         AttrNumber      ii_KeyAttrNumbers[INDEX_MAX_KEYS];
60         List       *ii_Expressions; /* list of Expr */
61         List       *ii_ExpressionsState;        /* list of ExprState */
62         List       *ii_Predicate;       /* list of Expr */
63         List       *ii_PredicateState;          /* list of ExprState */
64         Oid                *ii_ExclusionOps;    /* array with one entry per column */
65         Oid                *ii_ExclusionProcs;          /* array with one entry per column */
66         uint16     *ii_ExclusionStrats;         /* array with one entry per column */
67         bool            ii_Unique;
68         bool            ii_ReadyForInserts;
69         bool            ii_Concurrent;
70         bool            ii_BrokenHotChain;
71 } IndexInfo;
72
73 /* ----------------
74  *        ExprContext_CB
75  *
76  *              List of callbacks to be called at ExprContext shutdown.
77  * ----------------
78  */
79 typedef void (*ExprContextCallbackFunction) (Datum arg);
80
81 typedef struct ExprContext_CB
82 {
83         struct ExprContext_CB *next;
84         ExprContextCallbackFunction function;
85         Datum           arg;
86 } ExprContext_CB;
87
88 /* ----------------
89  *        ExprContext
90  *
91  *              This class holds the "current context" information
92  *              needed to evaluate expressions for doing tuple qualifications
93  *              and tuple projections.  For example, if an expression refers
94  *              to an attribute in the current inner tuple then we need to know
95  *              what the current inner tuple is and so we look at the expression
96  *              context.
97  *
98  *      There are two memory contexts associated with an ExprContext:
99  *      * ecxt_per_query_memory is a query-lifespan context, typically the same
100  *        context the ExprContext node itself is allocated in.  This context
101  *        can be used for purposes such as storing function call cache info.
102  *      * ecxt_per_tuple_memory is a short-term context for expression results.
103  *        As the name suggests, it will typically be reset once per tuple,
104  *        before we begin to evaluate expressions for that tuple.  Each
105  *        ExprContext normally has its very own per-tuple memory context.
106  *
107  *      CurrentMemoryContext should be set to ecxt_per_tuple_memory before
108  *      calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
109  * ----------------
110  */
111 typedef struct ExprContext
112 {
113         NodeTag         type;
114
115         /* Tuples that Var nodes in expression may refer to */
116         TupleTableSlot *ecxt_scantuple;
117         TupleTableSlot *ecxt_innertuple;
118         TupleTableSlot *ecxt_outertuple;
119
120         /* Memory contexts for expression evaluation --- see notes above */
121         MemoryContext ecxt_per_query_memory;
122         MemoryContext ecxt_per_tuple_memory;
123
124         /* Values to substitute for Param nodes in expression */
125         ParamExecData *ecxt_param_exec_vals;            /* for PARAM_EXEC params */
126         ParamListInfo ecxt_param_list_info; /* for other param types */
127
128         /*
129          * Values to substitute for Aggref nodes in the expressions of an Agg
130          * node, or for WindowFunc nodes within a WindowAgg node.
131          */
132         Datum      *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */
133         bool       *ecxt_aggnulls;      /* null flags for aggs/windowfuncs */
134
135         /* Value to substitute for CaseTestExpr nodes in expression */
136         Datum           caseValue_datum;
137         bool            caseValue_isNull;
138
139         /* Value to substitute for CoerceToDomainValue nodes in expression */
140         Datum           domainValue_datum;
141         bool            domainValue_isNull;
142
143         /* Link to containing EState (NULL if a standalone ExprContext) */
144         struct EState *ecxt_estate;
145
146         /* Functions to call back when ExprContext is shut down */
147         ExprContext_CB *ecxt_callbacks;
148 } ExprContext;
149
150 /*
151  * Set-result status returned by ExecEvalExpr()
152  */
153 typedef enum
154 {
155         ExprSingleResult,                       /* expression does not return a set */
156         ExprMultipleResult,                     /* this result is an element of a set */
157         ExprEndResult                           /* there are no more elements in the set */
158 } ExprDoneCond;
159
160 /*
161  * Return modes for functions returning sets.  Note values must be chosen
162  * as separate bits so that a bitmask can be formed to indicate supported
163  * modes.  SFRM_Materialize_Random and SFRM_Materialize_Preferred are
164  * auxiliary flags about SFRM_Materialize mode, rather than separate modes.
165  */
166 typedef enum
167 {
168         SFRM_ValuePerCall = 0x01,       /* one value returned per call */
169         SFRM_Materialize = 0x02,        /* result set instantiated in Tuplestore */
170         SFRM_Materialize_Random = 0x04,         /* Tuplestore needs randomAccess */
171         SFRM_Materialize_Preferred = 0x08       /* caller prefers Tuplestore */
172 } SetFunctionReturnMode;
173
174 /*
175  * When calling a function that might return a set (multiple rows),
176  * a node of this type is passed as fcinfo->resultinfo to allow
177  * return status to be passed back.  A function returning set should
178  * raise an error if no such resultinfo is provided.
179  */
180 typedef struct ReturnSetInfo
181 {
182         NodeTag         type;
183         /* values set by caller: */
184         ExprContext *econtext;          /* context function is being called in */
185         TupleDesc       expectedDesc;   /* tuple descriptor expected by caller */
186         int                     allowedModes;   /* bitmask: return modes caller can handle */
187         /* result status from function (but pre-initialized by caller): */
188         SetFunctionReturnMode returnMode;       /* actual return mode */
189         ExprDoneCond isDone;            /* status for ValuePerCall mode */
190         /* fields filled by function in Materialize return mode: */
191         Tuplestorestate *setResult; /* holds the complete returned tuple set */
192         TupleDesc       setDesc;                /* actual descriptor for returned tuples */
193 } ReturnSetInfo;
194
195 /* ----------------
196  *              ProjectionInfo node information
197  *
198  *              This is all the information needed to perform projections ---
199  *              that is, form new tuples by evaluation of targetlist expressions.
200  *              Nodes which need to do projections create one of these.
201  *
202  *              ExecProject() evaluates the tlist, forms a tuple, and stores it
203  *              in the given slot.      Note that the result will be a "virtual" tuple
204  *              unless ExecMaterializeSlot() is then called to force it to be
205  *              converted to a physical tuple.  The slot must have a tupledesc
206  *              that matches the output of the tlist!
207  *
208  *              The planner very often produces tlists that consist entirely of
209  *              simple Var references (lower levels of a plan tree almost always
210  *              look like that).  And top-level tlists are often mostly Vars too.
211  *              We therefore optimize execution of simple-Var tlist entries.
212  *              The pi_targetlist list actually contains only the tlist entries that
213  *              aren't simple Vars, while those that are Vars are processed using the
214  *              varSlotOffsets/varNumbers/varOutputCols arrays.
215  *
216  *              The lastXXXVar fields are used to optimize fetching of fields from
217  *              input tuples: they let us do a slot_getsomeattrs() call to ensure
218  *              that all needed attributes are extracted in one pass.
219  *
220  *              targetlist              target list for projection (non-Var expressions only)
221  *              exprContext             expression context in which to evaluate targetlist
222  *              slot                    slot to place projection result in
223  *              itemIsDone              workspace array for ExecProject
224  *              directMap               true if varOutputCols[] is an identity map
225  *              numSimpleVars   number of simple Vars found in original tlist
226  *              varSlotOffsets  array indicating which slot each simple Var is from
227  *              varNumbers              array containing input attr numbers of simple Vars
228  *              varOutputCols   array containing output attr numbers of simple Vars
229  *              lastInnerVar    highest attnum from inner tuple slot (0 if none)
230  *              lastOuterVar    highest attnum from outer tuple slot (0 if none)
231  *              lastScanVar             highest attnum from scan tuple slot (0 if none)
232  * ----------------
233  */
234 typedef struct ProjectionInfo
235 {
236         NodeTag         type;
237         List       *pi_targetlist;
238         ExprContext *pi_exprContext;
239         TupleTableSlot *pi_slot;
240         ExprDoneCond *pi_itemIsDone;
241         bool            pi_directMap;
242         int                     pi_numSimpleVars;
243         int                *pi_varSlotOffsets;
244         int                *pi_varNumbers;
245         int                *pi_varOutputCols;
246         int                     pi_lastInnerVar;
247         int                     pi_lastOuterVar;
248         int                     pi_lastScanVar;
249 } ProjectionInfo;
250
251 /* ----------------
252  *        JunkFilter
253  *
254  *        This class is used to store information regarding junk attributes.
255  *        A junk attribute is an attribute in a tuple that is needed only for
256  *        storing intermediate information in the executor, and does not belong
257  *        in emitted tuples.  For example, when we do an UPDATE query,
258  *        the planner adds a "junk" entry to the targetlist so that the tuples
259  *        returned to ExecutePlan() contain an extra attribute: the ctid of
260  *        the tuple to be updated.      This is needed to do the update, but we
261  *        don't want the ctid to be part of the stored new tuple!  So, we
262  *        apply a "junk filter" to remove the junk attributes and form the
263  *        real output tuple.  The junkfilter code also provides routines to
264  *        extract the values of the junk attribute(s) from the input tuple.
265  *
266  *        targetList:           the original target list (including junk attributes).
267  *        cleanTupType:         the tuple descriptor for the "clean" tuple (with
268  *                                              junk attributes removed).
269  *        cleanMap:                     A map with the correspondence between the non-junk
270  *                                              attribute numbers of the "original" tuple and the
271  *                                              attribute numbers of the "clean" tuple.
272  *        resultSlot:           tuple slot used to hold cleaned tuple.
273  *        junkAttNo:            not used by junkfilter code.  Can be used by caller
274  *                                              to remember the attno of a specific junk attribute
275  *                                              (execMain.c stores the "ctid" attno here).
276  * ----------------
277  */
278 typedef struct JunkFilter
279 {
280         NodeTag         type;
281         List       *jf_targetList;
282         TupleDesc       jf_cleanTupType;
283         AttrNumber *jf_cleanMap;
284         TupleTableSlot *jf_resultSlot;
285         AttrNumber      jf_junkAttNo;
286 } JunkFilter;
287
288 /* ----------------
289  *        ResultRelInfo information
290  *
291  *              Whenever we update an existing relation, we have to
292  *              update indices on the relation, and perhaps also fire triggers.
293  *              The ResultRelInfo class is used to hold all the information needed
294  *              about a result relation, including indices.. -cim 10/15/89
295  *
296  *              RangeTableIndex                 result relation's range table index
297  *              RelationDesc                    relation descriptor for result relation
298  *              NumIndices                              # of indices existing on result relation
299  *              IndexRelationDescs              array of relation descriptors for indices
300  *              IndexRelationInfo               array of key/attr info for indices
301  *              TrigDesc                                triggers to be fired, if any
302  *              TrigFunctions                   cached lookup info for trigger functions
303  *              TrigWhenExprs                   array of trigger WHEN expr states
304  *              TrigInstrument                  optional runtime measurements for triggers
305  *              ConstraintExprs                 array of constraint-checking expr states
306  *              junkFilter                              for removing junk attributes from tuples
307  *              projectReturning                for computing a RETURNING list
308  * ----------------
309  */
310 typedef struct ResultRelInfo
311 {
312         NodeTag         type;
313         Index           ri_RangeTableIndex;
314         Relation        ri_RelationDesc;
315         int                     ri_NumIndices;
316         RelationPtr ri_IndexRelationDescs;
317         IndexInfo **ri_IndexRelationInfo;
318         TriggerDesc *ri_TrigDesc;
319         FmgrInfo   *ri_TrigFunctions;
320         List      **ri_TrigWhenExprs;
321         struct Instrumentation *ri_TrigInstrument;
322         List      **ri_ConstraintExprs;
323         JunkFilter *ri_junkFilter;
324         ProjectionInfo *ri_projectReturning;
325 } ResultRelInfo;
326
327 /* ----------------
328  *        EState information
329  *
330  * Master working state for an Executor invocation
331  * ----------------
332  */
333 typedef struct EState
334 {
335         NodeTag         type;
336
337         /* Basic state for all query types: */
338         ScanDirection es_direction; /* current scan direction */
339         Snapshot        es_snapshot;    /* time qual to use */
340         Snapshot        es_crosscheck_snapshot; /* crosscheck time qual for RI */
341         List       *es_range_table; /* List of RangeTblEntry */
342         PlannedStmt *es_plannedstmt;    /* link to top of plan tree */
343
344         JunkFilter *es_junkFilter;      /* top-level junk filter, if any */
345
346         /* If query can insert/delete tuples, the command ID to mark them with */
347         CommandId       es_output_cid;
348
349         /* Info about target table for insert/update/delete queries: */
350         ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
351         int                     es_num_result_relations;                /* length of array */
352         ResultRelInfo *es_result_relation_info;         /* currently active array elt */
353
354         /* Stuff used for firing triggers: */
355         List       *es_trig_target_relations;           /* trigger-only ResultRelInfos */
356         TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
357         TupleTableSlot *es_trig_oldtup_slot;            /* for trigger old tuples */
358
359         /* Parameter info: */
360         ParamListInfo es_param_list_info;       /* values of external params */
361         ParamExecData *es_param_exec_vals;      /* values of internal params */
362
363         /* Other working state: */
364         MemoryContext es_query_cxt; /* per-query context in which EState lives */
365
366         List       *es_tupleTable;      /* List of TupleTableSlots */
367
368         List       *es_rowMarks;        /* List of ExecRowMarks */
369
370         uint32          es_processed;   /* # of tuples processed */
371         Oid                     es_lastoid;             /* last oid processed (by INSERT) */
372
373         int                     es_instrument;  /* OR of InstrumentOption flags */
374         bool            es_select_into; /* true if doing SELECT INTO */
375         bool            es_into_oids;   /* true to generate OIDs in SELECT INTO */
376
377         List       *es_exprcontexts;    /* List of ExprContexts within EState */
378
379         List       *es_subplanstates;           /* List of PlanState for SubPlans */
380
381         /*
382          * this ExprContext is for per-output-tuple operations, such as constraint
383          * checks and index-value computations.  It will be reset for each output
384          * tuple.  Note that it will be created only if needed.
385          */
386         ExprContext *es_per_tuple_exprcontext;
387
388         /*
389          * These fields are for re-evaluating plan quals when an updated tuple is
390          * substituted in READ COMMITTED mode.  es_epqTuple[] contains tuples that
391          * scan plan nodes should return instead of whatever they'd normally
392          * return, or NULL if nothing to return; es_epqTupleSet[] is true if a
393          * particular array entry is valid; and es_epqScanDone[] is state to
394          * remember if the tuple has been returned already.  Arrays are of size
395          * list_length(es_range_table) and are indexed by scan node scanrelid - 1.
396          */
397         HeapTuple  *es_epqTuple;        /* array of EPQ substitute tuples */
398         bool       *es_epqTupleSet; /* true if EPQ tuple is provided */
399         bool       *es_epqScanDone; /* true if EPQ tuple has been fetched */
400 } EState;
401
402
403 /*
404  * ExecRowMark -
405  *         runtime representation of FOR UPDATE/SHARE clauses
406  *
407  * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we should have an
408  * ExecRowMark for each non-target relation in the query (except inheritance
409  * parent RTEs, which can be ignored at runtime).  See PlanRowMark for details
410  * about most of the fields.  In addition to fields directly derived from
411  * PlanRowMark, we store curCtid, which is used by the WHERE CURRENT OF code.
412  *
413  * EState->es_rowMarks is a list of these structs.
414  */
415 typedef struct ExecRowMark
416 {
417         Relation        relation;               /* opened and suitably locked relation */
418         Index           rti;                    /* its range table index */
419         Index           prti;                   /* parent range table index, if child */
420         Index           rowmarkId;              /* unique identifier for resjunk columns */
421         RowMarkType markType;           /* see enum in nodes/plannodes.h */
422         bool            noWait;                 /* NOWAIT option */
423         ItemPointerData curCtid;        /* ctid of currently locked tuple, if any */
424 } ExecRowMark;
425
426 /*
427  * ExecAuxRowMark -
428  *         additional runtime representation of FOR UPDATE/SHARE clauses
429  *
430  * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to
431  * deal with.  In addition to a pointer to the related entry in es_rowMarks,
432  * this struct carries the column number(s) of the resjunk columns associated
433  * with the rowmark (see comments for PlanRowMark for more detail).  In the
434  * case of ModifyTable, there has to be a separate ExecAuxRowMark list for
435  * each child plan, because the resjunk columns could be at different physical
436  * column positions in different subplans.
437  */
438 typedef struct ExecAuxRowMark
439 {
440         ExecRowMark *rowmark;           /* related entry in es_rowMarks */
441         AttrNumber      ctidAttNo;              /* resno of ctid junk attribute, if any */
442         AttrNumber      toidAttNo;              /* resno of tableoid junk attribute, if any */
443         AttrNumber      wholeAttNo;             /* resno of whole-row junk attribute, if any */
444 } ExecAuxRowMark;
445
446
447 /* ----------------------------------------------------------------
448  *                               Tuple Hash Tables
449  *
450  * All-in-memory tuple hash tables are used for a number of purposes.
451  *
452  * Note: tab_hash_funcs are for the key datatype(s) stored in the table,
453  * and tab_eq_funcs are non-cross-type equality operators for those types.
454  * Normally these are the only functions used, but FindTupleHashEntry()
455  * supports searching a hashtable using cross-data-type hashing.  For that,
456  * the caller must supply hash functions for the LHS datatype as well as
457  * the cross-type equality operators to use.  in_hash_funcs and cur_eq_funcs
458  * are set to point to the caller's function arrays while doing such a search.
459  * During LookupTupleHashEntry(), they point to tab_hash_funcs and
460  * tab_eq_funcs respectively.
461  * ----------------------------------------------------------------
462  */
463 typedef struct TupleHashEntryData *TupleHashEntry;
464 typedef struct TupleHashTableData *TupleHashTable;
465
466 typedef struct TupleHashEntryData
467 {
468         /* firstTuple must be the first field in this struct! */
469         MinimalTuple firstTuple;        /* copy of first tuple in this group */
470         /* there may be additional data beyond the end of this struct */
471 } TupleHashEntryData;                   /* VARIABLE LENGTH STRUCT */
472
473 typedef struct TupleHashTableData
474 {
475         HTAB       *hashtab;            /* underlying dynahash table */
476         int                     numCols;                /* number of columns in lookup key */
477         AttrNumber *keyColIdx;          /* attr numbers of key columns */
478         FmgrInfo   *tab_hash_funcs; /* hash functions for table datatype(s) */
479         FmgrInfo   *tab_eq_funcs;       /* equality functions for table datatype(s) */
480         MemoryContext tablecxt;         /* memory context containing table */
481         MemoryContext tempcxt;          /* context for function evaluations */
482         Size            entrysize;              /* actual size to make each hash entry */
483         TupleTableSlot *tableslot;      /* slot for referencing table entries */
484         /* The following fields are set transiently for each table search: */
485         TupleTableSlot *inputslot;      /* current input tuple's slot */
486         FmgrInfo   *in_hash_funcs;      /* hash functions for input datatype(s) */
487         FmgrInfo   *cur_eq_funcs;       /* equality functions for input vs. table */
488 } TupleHashTableData;
489
490 typedef HASH_SEQ_STATUS TupleHashIterator;
491
492 /*
493  * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan.
494  * Use ResetTupleHashIterator if the table can be frozen (in this case no
495  * explicit scan termination is needed).
496  */
497 #define InitTupleHashIterator(htable, iter) \
498         hash_seq_init(iter, (htable)->hashtab)
499 #define TermTupleHashIterator(iter) \
500         hash_seq_term(iter)
501 #define ResetTupleHashIterator(htable, iter) \
502         do { \
503                 hash_freeze((htable)->hashtab); \
504                 hash_seq_init(iter, (htable)->hashtab); \
505         } while (0)
506 #define ScanTupleHashTable(iter) \
507         ((TupleHashEntry) hash_seq_search(iter))
508
509
510 /* ----------------------------------------------------------------
511  *                               Expression State Trees
512  *
513  * Each executable expression tree has a parallel ExprState tree.
514  *
515  * Unlike PlanState, there is not an exact one-for-one correspondence between
516  * ExprState node types and Expr node types.  Many Expr node types have no
517  * need for node-type-specific run-time state, and so they can use plain
518  * ExprState or GenericExprState as their associated ExprState node type.
519  * ----------------------------------------------------------------
520  */
521
522 /* ----------------
523  *              ExprState node
524  *
525  * ExprState is the common superclass for all ExprState-type nodes.
526  *
527  * It can also be instantiated directly for leaf Expr nodes that need no
528  * local run-time state (such as Var, Const, or Param).
529  *
530  * To save on dispatch overhead, each ExprState node contains a function
531  * pointer to the routine to execute to evaluate the node.
532  * ----------------
533  */
534
535 typedef struct ExprState ExprState;
536
537 typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
538                                                                                                 ExprContext *econtext,
539                                                                                                 bool *isNull,
540                                                                                                 ExprDoneCond *isDone);
541
542 struct ExprState
543 {
544         NodeTag         type;
545         Expr       *expr;                       /* associated Expr node */
546         ExprStateEvalFunc evalfunc; /* routine to run to execute node */
547 };
548
549 /* ----------------
550  *              GenericExprState node
551  *
552  * This is used for Expr node types that need no local run-time state,
553  * but have one child Expr node.
554  * ----------------
555  */
556 typedef struct GenericExprState
557 {
558         ExprState       xprstate;
559         ExprState  *arg;                        /* state of my child node */
560 } GenericExprState;
561
562 /* ----------------
563  *              AggrefExprState node
564  * ----------------
565  */
566 typedef struct AggrefExprState
567 {
568         ExprState       xprstate;
569         List       *args;                       /* states of argument expressions */
570         int                     aggno;                  /* ID number for agg within its plan node */
571 } AggrefExprState;
572
573 /* ----------------
574  *              WindowFuncExprState node
575  * ----------------
576  */
577 typedef struct WindowFuncExprState
578 {
579         ExprState       xprstate;
580         List       *args;                       /* states of argument expressions */
581         int                     wfuncno;                /* ID number for wfunc within its plan node */
582 } WindowFuncExprState;
583
584 /* ----------------
585  *              ArrayRefExprState node
586  *
587  * Note: array types can be fixed-length (typlen > 0), but only when the
588  * element type is itself fixed-length.  Otherwise they are varlena structures
589  * and have typlen = -1.  In any case, an array type is never pass-by-value.
590  * ----------------
591  */
592 typedef struct ArrayRefExprState
593 {
594         ExprState       xprstate;
595         List       *refupperindexpr;    /* states for child nodes */
596         List       *reflowerindexpr;
597         ExprState  *refexpr;
598         ExprState  *refassgnexpr;
599         int16           refattrlength;  /* typlen of array type */
600         int16           refelemlength;  /* typlen of the array element type */
601         bool            refelembyval;   /* is the element type pass-by-value? */
602         char            refelemalign;   /* typalign of the element type */
603 } ArrayRefExprState;
604
605 /* ----------------
606  *              FuncExprState node
607  *
608  * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
609  * and NullIf nodes; be careful to check what xprstate.expr is actually
610  * pointing at!
611  * ----------------
612  */
613 typedef struct FuncExprState
614 {
615         ExprState       xprstate;
616         List       *args;                       /* states of argument expressions */
617
618         /*
619          * Function manager's lookup info for the target function.  If func.fn_oid
620          * is InvalidOid, we haven't initialized it yet (nor any of the following
621          * fields).
622          */
623         FmgrInfo        func;
624
625         /*
626          * For a set-returning function (SRF) that returns a tuplestore, we keep
627          * the tuplestore here and dole out the result rows one at a time. The
628          * slot holds the row currently being returned.
629          */
630         Tuplestorestate *funcResultStore;
631         TupleTableSlot *funcResultSlot;
632
633         /*
634          * In some cases we need to compute a tuple descriptor for the function's
635          * output.      If so, it's stored here.
636          */
637         TupleDesc       funcResultDesc;
638         bool            funcReturnsTuple;               /* valid when funcResultDesc isn't
639                                                                                  * NULL */
640
641         /*
642          * setArgsValid is true when we are evaluating a set-returning function
643          * that uses value-per-call mode and we are in the middle of a call
644          * series; we want to pass the same argument values to the function again
645          * (and again, until it returns ExprEndResult).  This indicates that
646          * fcinfo_data already contains valid argument data.
647          */
648         bool            setArgsValid;
649
650         /*
651          * Flag to remember whether we found a set-valued argument to the
652          * function. This causes the function result to be a set as well. Valid
653          * only when setArgsValid is true or funcResultStore isn't NULL.
654          */
655         bool            setHasSetArg;   /* some argument returns a set */
656
657         /*
658          * Flag to remember whether we have registered a shutdown callback for
659          * this FuncExprState.  We do so only if funcResultStore or setArgsValid
660          * has been set at least once (since all the callback is for is to release
661          * the tuplestore or clear setArgsValid).
662          */
663         bool            shutdown_reg;   /* a shutdown callback is registered */
664
665         /*
666          * Call parameter structure for the function.  This has been initialized
667          * (by InitFunctionCallInfoData) if func.fn_oid is valid.  It also saves
668          * argument values between calls, when setArgsValid is true.
669          */
670         FunctionCallInfoData fcinfo_data;
671 } FuncExprState;
672
673 /* ----------------
674  *              ScalarArrayOpExprState node
675  *
676  * This is a FuncExprState plus some additional data.
677  * ----------------
678  */
679 typedef struct ScalarArrayOpExprState
680 {
681         FuncExprState fxprstate;
682         /* Cached info about array element type */
683         Oid                     element_type;
684         int16           typlen;
685         bool            typbyval;
686         char            typalign;
687 } ScalarArrayOpExprState;
688
689 /* ----------------
690  *              BoolExprState node
691  * ----------------
692  */
693 typedef struct BoolExprState
694 {
695         ExprState       xprstate;
696         List       *args;                       /* states of argument expression(s) */
697 } BoolExprState;
698
699 /* ----------------
700  *              SubPlanState node
701  * ----------------
702  */
703 typedef struct SubPlanState
704 {
705         ExprState       xprstate;
706         struct PlanState *planstate;    /* subselect plan's state tree */
707         ExprState  *testexpr;           /* state of combining expression */
708         List       *args;                       /* states of argument expression(s) */
709         HeapTuple       curTuple;               /* copy of most recent tuple from subplan */
710         /* these are used when hashing the subselect's output: */
711         ProjectionInfo *projLeft;       /* for projecting lefthand exprs */
712         ProjectionInfo *projRight;      /* for projecting subselect output */
713         TupleHashTable hashtable;       /* hash table for no-nulls subselect rows */
714         TupleHashTable hashnulls;       /* hash table for rows with null(s) */
715         bool            havehashrows;   /* TRUE if hashtable is not empty */
716         bool            havenullrows;   /* TRUE if hashnulls is not empty */
717         MemoryContext hashtablecxt;     /* memory context containing hash tables */
718         MemoryContext hashtempcxt;      /* temp memory context for hash tables */
719         ExprContext *innerecontext; /* econtext for computing inner tuples */
720         AttrNumber *keyColIdx;          /* control data for hash tables */
721         FmgrInfo   *tab_hash_funcs; /* hash functions for table datatype(s) */
722         FmgrInfo   *tab_eq_funcs;       /* equality functions for table datatype(s) */
723         FmgrInfo   *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */
724         FmgrInfo   *cur_eq_funcs;       /* equality functions for LHS vs. table */
725 } SubPlanState;
726
727 /* ----------------
728  *              AlternativeSubPlanState node
729  * ----------------
730  */
731 typedef struct AlternativeSubPlanState
732 {
733         ExprState       xprstate;
734         List       *subplans;           /* states of alternative subplans */
735         int                     active;                 /* list index of the one we're using */
736 } AlternativeSubPlanState;
737
738 /* ----------------
739  *              FieldSelectState node
740  * ----------------
741  */
742 typedef struct FieldSelectState
743 {
744         ExprState       xprstate;
745         ExprState  *arg;                        /* input expression */
746         TupleDesc       argdesc;                /* tupdesc for most recent input */
747 } FieldSelectState;
748
749 /* ----------------
750  *              FieldStoreState node
751  * ----------------
752  */
753 typedef struct FieldStoreState
754 {
755         ExprState       xprstate;
756         ExprState  *arg;                        /* input tuple value */
757         List       *newvals;            /* new value(s) for field(s) */
758         TupleDesc       argdesc;                /* tupdesc for most recent input */
759 } FieldStoreState;
760
761 /* ----------------
762  *              CoerceViaIOState node
763  * ----------------
764  */
765 typedef struct CoerceViaIOState
766 {
767         ExprState       xprstate;
768         ExprState  *arg;                        /* input expression */
769         FmgrInfo        outfunc;                /* lookup info for source output function */
770         FmgrInfo        infunc;                 /* lookup info for result input function */
771         Oid                     intypioparam;   /* argument needed for input function */
772 } CoerceViaIOState;
773
774 /* ----------------
775  *              ArrayCoerceExprState node
776  * ----------------
777  */
778 typedef struct ArrayCoerceExprState
779 {
780         ExprState       xprstate;
781         ExprState  *arg;                        /* input array value */
782         Oid                     resultelemtype; /* element type of result array */
783         FmgrInfo        elemfunc;               /* lookup info for element coercion function */
784         /* use struct pointer to avoid including array.h here */
785         struct ArrayMapState *amstate;          /* workspace for array_map */
786 } ArrayCoerceExprState;
787
788 /* ----------------
789  *              ConvertRowtypeExprState node
790  * ----------------
791  */
792 typedef struct ConvertRowtypeExprState
793 {
794         ExprState       xprstate;
795         ExprState  *arg;                        /* input tuple value */
796         TupleDesc       indesc;                 /* tupdesc for source rowtype */
797         TupleDesc       outdesc;                /* tupdesc for result rowtype */
798         /* use "struct" so we needn't include tupconvert.h here */
799         struct TupleConversionMap *map;
800         bool            initialized;
801 } ConvertRowtypeExprState;
802
803 /* ----------------
804  *              CaseExprState node
805  * ----------------
806  */
807 typedef struct CaseExprState
808 {
809         ExprState       xprstate;
810         ExprState  *arg;                        /* implicit equality comparison argument */
811         List       *args;                       /* the arguments (list of WHEN clauses) */
812         ExprState  *defresult;          /* the default result (ELSE clause) */
813 } CaseExprState;
814
815 /* ----------------
816  *              CaseWhenState node
817  * ----------------
818  */
819 typedef struct CaseWhenState
820 {
821         ExprState       xprstate;
822         ExprState  *expr;                       /* condition expression */
823         ExprState  *result;                     /* substitution result */
824 } CaseWhenState;
825
826 /* ----------------
827  *              ArrayExprState node
828  *
829  * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
830  * arrays.
831  * ----------------
832  */
833 typedef struct ArrayExprState
834 {
835         ExprState       xprstate;
836         List       *elements;           /* states for child nodes */
837         int16           elemlength;             /* typlen of the array element type */
838         bool            elembyval;              /* is the element type pass-by-value? */
839         char            elemalign;              /* typalign of the element type */
840 } ArrayExprState;
841
842 /* ----------------
843  *              RowExprState node
844  * ----------------
845  */
846 typedef struct RowExprState
847 {
848         ExprState       xprstate;
849         List       *args;                       /* the arguments */
850         TupleDesc       tupdesc;                /* descriptor for result tuples */
851 } RowExprState;
852
853 /* ----------------
854  *              RowCompareExprState node
855  * ----------------
856  */
857 typedef struct RowCompareExprState
858 {
859         ExprState       xprstate;
860         List       *largs;                      /* the left-hand input arguments */
861         List       *rargs;                      /* the right-hand input arguments */
862         FmgrInfo   *funcs;                      /* array of comparison function info */
863 } RowCompareExprState;
864
865 /* ----------------
866  *              CoalesceExprState node
867  * ----------------
868  */
869 typedef struct CoalesceExprState
870 {
871         ExprState       xprstate;
872         List       *args;                       /* the arguments */
873 } CoalesceExprState;
874
875 /* ----------------
876  *              MinMaxExprState node
877  * ----------------
878  */
879 typedef struct MinMaxExprState
880 {
881         ExprState       xprstate;
882         List       *args;                       /* the arguments */
883         FmgrInfo        cfunc;                  /* lookup info for comparison func */
884 } MinMaxExprState;
885
886 /* ----------------
887  *              XmlExprState node
888  * ----------------
889  */
890 typedef struct XmlExprState
891 {
892         ExprState       xprstate;
893         List       *named_args;         /* ExprStates for named arguments */
894         List       *args;                       /* ExprStates for other arguments */
895 } XmlExprState;
896
897 /* ----------------
898  *              NullTestState node
899  * ----------------
900  */
901 typedef struct NullTestState
902 {
903         ExprState       xprstate;
904         ExprState  *arg;                        /* input expression */
905         /* used only if input is of composite type: */
906         TupleDesc       argdesc;                /* tupdesc for most recent input */
907 } NullTestState;
908
909 /* ----------------
910  *              CoerceToDomainState node
911  * ----------------
912  */
913 typedef struct CoerceToDomainState
914 {
915         ExprState       xprstate;
916         ExprState  *arg;                        /* input expression */
917         /* Cached list of constraints that need to be checked */
918         List       *constraints;        /* list of DomainConstraintState nodes */
919 } CoerceToDomainState;
920
921 /*
922  * DomainConstraintState - one item to check during CoerceToDomain
923  *
924  * Note: this is just a Node, and not an ExprState, because it has no
925  * corresponding Expr to link to.  Nonetheless it is part of an ExprState
926  * tree, so we give it a name following the xxxState convention.
927  */
928 typedef enum DomainConstraintType
929 {
930         DOM_CONSTRAINT_NOTNULL,
931         DOM_CONSTRAINT_CHECK
932 } DomainConstraintType;
933
934 typedef struct DomainConstraintState
935 {
936         NodeTag         type;
937         DomainConstraintType constrainttype;            /* constraint type */
938         char       *name;                       /* name of constraint (for error msgs) */
939         ExprState  *check_expr;         /* for CHECK, a boolean expression */
940 } DomainConstraintState;
941
942
943 /* ----------------------------------------------------------------
944  *                               Executor State Trees
945  *
946  * An executing query has a PlanState tree paralleling the Plan tree
947  * that describes the plan.
948  * ----------------------------------------------------------------
949  */
950
951 /* ----------------
952  *              PlanState node
953  *
954  * We never actually instantiate any PlanState nodes; this is just the common
955  * abstract superclass for all PlanState-type nodes.
956  * ----------------
957  */
958 typedef struct PlanState
959 {
960         NodeTag         type;
961
962         Plan       *plan;                       /* associated Plan node */
963
964         EState     *state;                      /* at execution time, states of individual
965                                                                  * nodes point to one EState for the whole
966                                                                  * top-level plan */
967
968         struct Instrumentation *instrument; /* Optional runtime stats for this
969                                                                                  * plan node */
970
971         /*
972          * Common structural data for all Plan types.  These links to subsidiary
973          * state trees parallel links in the associated plan tree (except for the
974          * subPlan list, which does not exist in the plan tree).
975          */
976         List       *targetlist;         /* target list to be computed at this node */
977         List       *qual;                       /* implicitly-ANDed qual conditions */
978         struct PlanState *lefttree; /* input plan tree(s) */
979         struct PlanState *righttree;
980         List       *initPlan;           /* Init SubPlanState nodes (un-correlated expr
981                                                                  * subselects) */
982         List       *subPlan;            /* SubPlanState nodes in my expressions */
983
984         /*
985          * State for management of parameter-change-driven rescanning
986          */
987         Bitmapset  *chgParam;           /* set of IDs of changed Params */
988
989         /*
990          * Other run-time state needed by most if not all node types.
991          */
992         TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
993         ExprContext *ps_ExprContext;    /* node's expression-evaluation context */
994         ProjectionInfo *ps_ProjInfo;    /* info for doing tuple projection */
995         bool            ps_TupFromTlist;/* state flag for processing set-valued
996                                                                  * functions in targetlist */
997 } PlanState;
998
999 /* ----------------
1000  *      these are defined to avoid confusion problems with "left"
1001  *      and "right" and "inner" and "outer".  The convention is that
1002  *      the "left" plan is the "outer" plan and the "right" plan is
1003  *      the inner plan, but these make the code more readable.
1004  * ----------------
1005  */
1006 #define innerPlanState(node)            (((PlanState *)(node))->righttree)
1007 #define outerPlanState(node)            (((PlanState *)(node))->lefttree)
1008
1009 /*
1010  * EPQState is state for executing an EvalPlanQual recheck on a candidate
1011  * tuple in ModifyTable or LockRows.  The estate and planstate fields are
1012  * NULL if inactive.
1013  */
1014 typedef struct EPQState
1015 {
1016         EState     *estate;                     /* subsidiary EState */
1017         PlanState  *planstate;          /* plan state tree ready to be executed */
1018         TupleTableSlot *origslot;       /* original output tuple to be rechecked */
1019         Plan       *plan;                       /* plan tree to be executed */
1020         List       *arowMarks;          /* ExecAuxRowMarks (non-locking only) */
1021         int                     epqParam;               /* ID of Param to force scan node re-eval */
1022 } EPQState;
1023
1024
1025 /* ----------------
1026  *       ResultState information
1027  * ----------------
1028  */
1029 typedef struct ResultState
1030 {
1031         PlanState       ps;                             /* its first field is NodeTag */
1032         ExprState  *resconstantqual;
1033         bool            rs_done;                /* are we done? */
1034         bool            rs_checkqual;   /* do we need to check the qual? */
1035 } ResultState;
1036
1037 /* ----------------
1038  *       ModifyTableState information
1039  * ----------------
1040  */
1041 typedef struct ModifyTableState
1042 {
1043         PlanState       ps;                             /* its first field is NodeTag */
1044         CmdType         operation;
1045         PlanState **mt_plans;           /* subplans (one per target rel) */
1046         int                     mt_nplans;              /* number of plans in the array */
1047         int                     mt_whichplan;   /* which one is being executed (0..n-1) */
1048         List      **mt_arowmarks;       /* per-subplan ExecAuxRowMark lists */
1049         EPQState        mt_epqstate;    /* for evaluating EvalPlanQual rechecks */
1050         bool            fireBSTriggers; /* do we need to fire stmt triggers? */
1051 } ModifyTableState;
1052
1053 /* ----------------
1054  *       AppendState information
1055  *
1056  *              nplans                  how many plans are in the array
1057  *              whichplan               which plan is being executed (0 .. n-1)
1058  * ----------------
1059  */
1060 typedef struct AppendState
1061 {
1062         PlanState       ps;                             /* its first field is NodeTag */
1063         PlanState **appendplans;        /* array of PlanStates for my inputs */
1064         int                     as_nplans;
1065         int                     as_whichplan;
1066 } AppendState;
1067
1068 /* ----------------
1069  *       MergeAppendState information
1070  *
1071  *              nplans                  how many plans are in the array
1072  *              nkeys                   number of sort key columns
1073  *              scankeys                sort keys in ScanKey representation
1074  *              slots                   current output tuple of each subplan
1075  *              heap                    heap of active tuples (represented as array indexes)
1076  *              heap_size               number of active heap entries
1077  *              initialized             true if we have fetched first tuple from each subplan
1078  *              last_slot               last subplan fetched from (which must be re-called)
1079  * ----------------
1080  */
1081 typedef struct MergeAppendState
1082 {
1083         PlanState       ps;                             /* its first field is NodeTag */
1084         PlanState **mergeplans;         /* array of PlanStates for my inputs */
1085         int                     ms_nplans;
1086         int                     ms_nkeys;
1087         ScanKey         ms_scankeys;    /* array of length ms_nkeys */
1088         TupleTableSlot **ms_slots;      /* array of length ms_nplans */
1089         int                     *ms_heap;               /* array of length ms_nplans */
1090         int                     ms_heap_size;   /* current active length of ms_heap[] */
1091         bool            ms_initialized; /* are subplans started? */
1092         int                     ms_last_slot;   /* last subplan slot we returned from */
1093 } MergeAppendState;
1094
1095 /* ----------------
1096  *       RecursiveUnionState information
1097  *
1098  *              RecursiveUnionState is used for performing a recursive union.
1099  *
1100  *              recursing                       T when we're done scanning the non-recursive term
1101  *              intermediate_empty      T if intermediate_table is currently empty
1102  *              working_table           working table (to be scanned by recursive term)
1103  *              intermediate_table      current recursive output (next generation of WT)
1104  * ----------------
1105  */
1106 typedef struct RecursiveUnionState
1107 {
1108         PlanState       ps;                             /* its first field is NodeTag */
1109         bool            recursing;
1110         bool            intermediate_empty;
1111         Tuplestorestate *working_table;
1112         Tuplestorestate *intermediate_table;
1113         /* Remaining fields are unused in UNION ALL case */
1114         FmgrInfo   *eqfunctions;        /* per-grouping-field equality fns */
1115         FmgrInfo   *hashfunctions;      /* per-grouping-field hash fns */
1116         MemoryContext tempContext;      /* short-term context for comparisons */
1117         TupleHashTable hashtable;       /* hash table for tuples already seen */
1118         MemoryContext tableContext; /* memory context containing hash table */
1119 } RecursiveUnionState;
1120
1121 /* ----------------
1122  *       BitmapAndState information
1123  * ----------------
1124  */
1125 typedef struct BitmapAndState
1126 {
1127         PlanState       ps;                             /* its first field is NodeTag */
1128         PlanState **bitmapplans;        /* array of PlanStates for my inputs */
1129         int                     nplans;                 /* number of input plans */
1130 } BitmapAndState;
1131
1132 /* ----------------
1133  *       BitmapOrState information
1134  * ----------------
1135  */
1136 typedef struct BitmapOrState
1137 {
1138         PlanState       ps;                             /* its first field is NodeTag */
1139         PlanState **bitmapplans;        /* array of PlanStates for my inputs */
1140         int                     nplans;                 /* number of input plans */
1141 } BitmapOrState;
1142
1143 /* ----------------------------------------------------------------
1144  *                               Scan State Information
1145  * ----------------------------------------------------------------
1146  */
1147
1148 /* ----------------
1149  *       ScanState information
1150  *
1151  *              ScanState extends PlanState for node types that represent
1152  *              scans of an underlying relation.  It can also be used for nodes
1153  *              that scan the output of an underlying plan node --- in that case,
1154  *              only ScanTupleSlot is actually useful, and it refers to the tuple
1155  *              retrieved from the subplan.
1156  *
1157  *              currentRelation    relation being scanned (NULL if none)
1158  *              currentScanDesc    current scan descriptor for scan (NULL if none)
1159  *              ScanTupleSlot      pointer to slot in tuple table holding scan tuple
1160  * ----------------
1161  */
1162 typedef struct ScanState
1163 {
1164         PlanState       ps;                             /* its first field is NodeTag */
1165         Relation        ss_currentRelation;
1166         HeapScanDesc ss_currentScanDesc;
1167         TupleTableSlot *ss_ScanTupleSlot;
1168 } ScanState;
1169
1170 /*
1171  * SeqScan uses a bare ScanState as its state node, since it needs
1172  * no additional fields.
1173  */
1174 typedef ScanState SeqScanState;
1175
1176 /*
1177  * These structs store information about index quals that don't have simple
1178  * constant right-hand sides.  See comments for ExecIndexBuildScanKeys()
1179  * for discussion.
1180  */
1181 typedef struct
1182 {
1183         ScanKey         scan_key;               /* scankey to put value into */
1184         ExprState  *key_expr;           /* expr to evaluate to get value */
1185         bool            key_toastable;  /* is expr's result a toastable datatype? */
1186 } IndexRuntimeKeyInfo;
1187
1188 typedef struct
1189 {
1190         ScanKey         scan_key;               /* scankey to put value into */
1191         ExprState  *array_expr;         /* expr to evaluate to get array value */
1192         int                     next_elem;              /* next array element to use */
1193         int                     num_elems;              /* number of elems in current array value */
1194         Datum      *elem_values;        /* array of num_elems Datums */
1195         bool       *elem_nulls;         /* array of num_elems is-null flags */
1196 } IndexArrayKeyInfo;
1197
1198 /* ----------------
1199  *       IndexScanState information
1200  *
1201  *              indexqualorig      execution state for indexqualorig expressions
1202  *              ScanKeys                   Skey structures for index quals
1203  *              NumScanKeys                number of ScanKeys
1204  *              OrderByKeys                Skey structures for index ordering operators
1205  *              NumOrderByKeys     number of OrderByKeys
1206  *              RuntimeKeys                info about Skeys that must be evaluated at runtime
1207  *              NumRuntimeKeys     number of RuntimeKeys
1208  *              RuntimeKeysReady   true if runtime Skeys have been computed
1209  *              RuntimeContext     expr context for evaling runtime Skeys
1210  *              RelationDesc       index relation descriptor
1211  *              ScanDesc                   index scan descriptor
1212  * ----------------
1213  */
1214 typedef struct IndexScanState
1215 {
1216         ScanState       ss;                             /* its first field is NodeTag */
1217         List       *indexqualorig;
1218         ScanKey         iss_ScanKeys;
1219         int                     iss_NumScanKeys;
1220         ScanKey         iss_OrderByKeys;
1221         int                     iss_NumOrderByKeys;
1222         IndexRuntimeKeyInfo *iss_RuntimeKeys;
1223         int                     iss_NumRuntimeKeys;
1224         bool            iss_RuntimeKeysReady;
1225         ExprContext *iss_RuntimeContext;
1226         Relation        iss_RelationDesc;
1227         IndexScanDesc iss_ScanDesc;
1228 } IndexScanState;
1229
1230 /* ----------------
1231  *       BitmapIndexScanState information
1232  *
1233  *              result                     bitmap to return output into, or NULL
1234  *              ScanKeys                   Skey structures for index quals
1235  *              NumScanKeys                number of ScanKeys
1236  *              RuntimeKeys                info about Skeys that must be evaluated at runtime
1237  *              NumRuntimeKeys     number of RuntimeKeys
1238  *              ArrayKeys                  info about Skeys that come from ScalarArrayOpExprs
1239  *              NumArrayKeys       number of ArrayKeys
1240  *              RuntimeKeysReady   true if runtime Skeys have been computed
1241  *              RuntimeContext     expr context for evaling runtime Skeys
1242  *              RelationDesc       index relation descriptor
1243  *              ScanDesc                   index scan descriptor
1244  * ----------------
1245  */
1246 typedef struct BitmapIndexScanState
1247 {
1248         ScanState       ss;                             /* its first field is NodeTag */
1249         TIDBitmap  *biss_result;
1250         ScanKey         biss_ScanKeys;
1251         int                     biss_NumScanKeys;
1252         IndexRuntimeKeyInfo *biss_RuntimeKeys;
1253         int                     biss_NumRuntimeKeys;
1254         IndexArrayKeyInfo *biss_ArrayKeys;
1255         int                     biss_NumArrayKeys;
1256         bool            biss_RuntimeKeysReady;
1257         ExprContext *biss_RuntimeContext;
1258         Relation        biss_RelationDesc;
1259         IndexScanDesc biss_ScanDesc;
1260 } BitmapIndexScanState;
1261
1262 /* ----------------
1263  *       BitmapHeapScanState information
1264  *
1265  *              bitmapqualorig     execution state for bitmapqualorig expressions
1266  *              tbm                                bitmap obtained from child index scan(s)
1267  *              tbmiterator                iterator for scanning current pages
1268  *              tbmres                     current-page data
1269  *              prefetch_iterator  iterator for prefetching ahead of current page
1270  *              prefetch_pages     # pages prefetch iterator is ahead of current
1271  *              prefetch_target    target prefetch distance
1272  * ----------------
1273  */
1274 typedef struct BitmapHeapScanState
1275 {
1276         ScanState       ss;                             /* its first field is NodeTag */
1277         List       *bitmapqualorig;
1278         TIDBitmap  *tbm;
1279         TBMIterator *tbmiterator;
1280         TBMIterateResult *tbmres;
1281         TBMIterator *prefetch_iterator;
1282         int                     prefetch_pages;
1283         int                     prefetch_target;
1284 } BitmapHeapScanState;
1285
1286 /* ----------------
1287  *       TidScanState information
1288  *
1289  *              isCurrentOf    scan has a CurrentOfExpr qual
1290  *              NumTids            number of tids in this scan
1291  *              TidPtr             index of currently fetched tid
1292  *              TidList            evaluated item pointers (array of size NumTids)
1293  * ----------------
1294  */
1295 typedef struct TidScanState
1296 {
1297         ScanState       ss;                             /* its first field is NodeTag */
1298         List       *tss_tidquals;       /* list of ExprState nodes */
1299         bool            tss_isCurrentOf;
1300         int                     tss_NumTids;
1301         int                     tss_TidPtr;
1302         int                     tss_MarkTidPtr;
1303         ItemPointerData *tss_TidList;
1304         HeapTupleData tss_htup;
1305 } TidScanState;
1306
1307 /* ----------------
1308  *       SubqueryScanState information
1309  *
1310  *              SubqueryScanState is used for scanning a sub-query in the range table.
1311  *              ScanTupleSlot references the current output tuple of the sub-query.
1312  * ----------------
1313  */
1314 typedef struct SubqueryScanState
1315 {
1316         ScanState       ss;                             /* its first field is NodeTag */
1317         PlanState  *subplan;
1318 } SubqueryScanState;
1319
1320 /* ----------------
1321  *       FunctionScanState information
1322  *
1323  *              Function nodes are used to scan the results of a
1324  *              function appearing in FROM (typically a function returning set).
1325  *
1326  *              eflags                          node's capability flags
1327  *              tupdesc                         expected return tuple description
1328  *              tuplestorestate         private state of tuplestore.c
1329  *              funcexpr                        state for function expression being evaluated
1330  * ----------------
1331  */
1332 typedef struct FunctionScanState
1333 {
1334         ScanState       ss;                             /* its first field is NodeTag */
1335         int                     eflags;
1336         TupleDesc       tupdesc;
1337         Tuplestorestate *tuplestorestate;
1338         ExprState  *funcexpr;
1339 } FunctionScanState;
1340
1341 /* ----------------
1342  *       ValuesScanState information
1343  *
1344  *              ValuesScan nodes are used to scan the results of a VALUES list
1345  *
1346  *              rowcontext                      per-expression-list context
1347  *              exprlists                       array of expression lists being evaluated
1348  *              array_len                       size of array
1349  *              curr_idx                        current array index (0-based)
1350  *              marked_idx                      marked position (for mark/restore)
1351  *
1352  *      Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection
1353  *      expressions attached to the node.  We create a second ExprContext,
1354  *      rowcontext, in which to build the executor expression state for each
1355  *      Values sublist.  Resetting this context lets us get rid of expression
1356  *      state for each row, avoiding major memory leakage over a long values list.
1357  * ----------------
1358  */
1359 typedef struct ValuesScanState
1360 {
1361         ScanState       ss;                             /* its first field is NodeTag */
1362         ExprContext *rowcontext;
1363         List      **exprlists;
1364         int                     array_len;
1365         int                     curr_idx;
1366         int                     marked_idx;
1367 } ValuesScanState;
1368
1369 /* ----------------
1370  *       CteScanState information
1371  *
1372  *              CteScan nodes are used to scan a CommonTableExpr query.
1373  *
1374  * Multiple CteScan nodes can read out from the same CTE query.  We use
1375  * a tuplestore to hold rows that have been read from the CTE query but
1376  * not yet consumed by all readers.
1377  * ----------------
1378  */
1379 typedef struct CteScanState
1380 {
1381         ScanState       ss;                             /* its first field is NodeTag */
1382         int                     eflags;                 /* capability flags to pass to tuplestore */
1383         int                     readptr;                /* index of my tuplestore read pointer */
1384         PlanState  *cteplanstate;       /* PlanState for the CTE query itself */
1385         /* Link to the "leader" CteScanState (possibly this same node) */
1386         struct CteScanState *leader;
1387         /* The remaining fields are only valid in the "leader" CteScanState */
1388         Tuplestorestate *cte_table; /* rows already read from the CTE query */
1389         bool            eof_cte;                /* reached end of CTE query? */
1390 } CteScanState;
1391
1392 /* ----------------
1393  *       WorkTableScanState information
1394  *
1395  *              WorkTableScan nodes are used to scan the work table created by
1396  *              a RecursiveUnion node.  We locate the RecursiveUnion node
1397  *              during executor startup.
1398  * ----------------
1399  */
1400 typedef struct WorkTableScanState
1401 {
1402         ScanState       ss;                             /* its first field is NodeTag */
1403         RecursiveUnionState *rustate;
1404 } WorkTableScanState;
1405
1406 /* ----------------
1407  *       ForeignScanState information
1408  *
1409  *              ForeignScan nodes are used to scan foreign-data tables.
1410  * ----------------
1411  */
1412 typedef struct ForeignScanState
1413 {
1414         ScanState       ss;                             /* its first field is NodeTag */
1415         /* use struct pointer to avoid including fdwapi.h here */
1416         struct FdwRoutine *fdwroutine;
1417         void       *fdw_state;          /* foreign-data wrapper can keep state here */
1418 } ForeignScanState;
1419
1420 /* ----------------------------------------------------------------
1421  *                               Join State Information
1422  * ----------------------------------------------------------------
1423  */
1424
1425 /* ----------------
1426  *       JoinState information
1427  *
1428  *              Superclass for state nodes of join plans.
1429  * ----------------
1430  */
1431 typedef struct JoinState
1432 {
1433         PlanState       ps;
1434         JoinType        jointype;
1435         List       *joinqual;           /* JOIN quals (in addition to ps.qual) */
1436 } JoinState;
1437
1438 /* ----------------
1439  *       NestLoopState information
1440  *
1441  *              NeedNewOuter       true if need new outer tuple on next call
1442  *              MatchedOuter       true if found a join match for current outer tuple
1443  *              NullInnerTupleSlot prepared null tuple for left outer joins
1444  * ----------------
1445  */
1446 typedef struct NestLoopState
1447 {
1448         JoinState       js;                             /* its first field is NodeTag */
1449         bool            nl_NeedNewOuter;
1450         bool            nl_MatchedOuter;
1451         TupleTableSlot *nl_NullInnerTupleSlot;
1452 } NestLoopState;
1453
1454 /* ----------------
1455  *       MergeJoinState information
1456  *
1457  *              NumClauses                 number of mergejoinable join clauses
1458  *              Clauses                    info for each mergejoinable clause
1459  *              JoinState                  current state of ExecMergeJoin state machine
1460  *              ExtraMarks                 true to issue extra Mark operations on inner scan
1461  *              ConstFalseJoin     true if we have a constant-false joinqual
1462  *              FillOuter                  true if should emit unjoined outer tuples anyway
1463  *              FillInner                  true if should emit unjoined inner tuples anyway
1464  *              MatchedOuter       true if found a join match for current outer tuple
1465  *              MatchedInner       true if found a join match for current inner tuple
1466  *              OuterTupleSlot     slot in tuple table for cur outer tuple
1467  *              InnerTupleSlot     slot in tuple table for cur inner tuple
1468  *              MarkedTupleSlot    slot in tuple table for marked tuple
1469  *              NullOuterTupleSlot prepared null tuple for right outer joins
1470  *              NullInnerTupleSlot prepared null tuple for left outer joins
1471  *              OuterEContext      workspace for computing outer tuple's join values
1472  *              InnerEContext      workspace for computing inner tuple's join values
1473  * ----------------
1474  */
1475 /* private in nodeMergejoin.c: */
1476 typedef struct MergeJoinClauseData *MergeJoinClause;
1477
1478 typedef struct MergeJoinState
1479 {
1480         JoinState       js;                             /* its first field is NodeTag */
1481         int                     mj_NumClauses;
1482         MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
1483         int                     mj_JoinState;
1484         bool            mj_ExtraMarks;
1485         bool            mj_ConstFalseJoin;
1486         bool            mj_FillOuter;
1487         bool            mj_FillInner;
1488         bool            mj_MatchedOuter;
1489         bool            mj_MatchedInner;
1490         TupleTableSlot *mj_OuterTupleSlot;
1491         TupleTableSlot *mj_InnerTupleSlot;
1492         TupleTableSlot *mj_MarkedTupleSlot;
1493         TupleTableSlot *mj_NullOuterTupleSlot;
1494         TupleTableSlot *mj_NullInnerTupleSlot;
1495         ExprContext *mj_OuterEContext;
1496         ExprContext *mj_InnerEContext;
1497 } MergeJoinState;
1498
1499 /* ----------------
1500  *       HashJoinState information
1501  *
1502  *              hashclauses                             original form of the hashjoin condition
1503  *              hj_OuterHashKeys                the outer hash keys in the hashjoin condition
1504  *              hj_InnerHashKeys                the inner hash keys in the hashjoin condition
1505  *              hj_HashOperators                the join operators in the hashjoin condition
1506  *              hj_HashTable                    hash table for the hashjoin
1507  *                                                              (NULL if table not built yet)
1508  *              hj_CurHashValue                 hash value for current outer tuple
1509  *              hj_CurBucketNo                  regular bucket# for current outer tuple
1510  *              hj_CurSkewBucketNo              skew bucket# for current outer tuple
1511  *              hj_CurTuple                             last inner tuple matched to current outer
1512  *                                                              tuple, or NULL if starting search
1513  *                                                              (hj_CurXXX variables are undefined if
1514  *                                                              OuterTupleSlot is empty!)
1515  *              hj_OuterTupleSlot               tuple slot for outer tuples
1516  *              hj_HashTupleSlot                tuple slot for inner (hashed) tuples
1517  *              hj_NullOuterTupleSlot   prepared null tuple for right/full outer joins
1518  *              hj_NullInnerTupleSlot   prepared null tuple for left/full outer joins
1519  *              hj_FirstOuterTupleSlot  first tuple retrieved from outer plan
1520  *              hj_JoinState                    current state of ExecHashJoin state machine
1521  *              hj_MatchedOuter                 true if found a join match for current outer
1522  *              hj_OuterNotEmpty                true if outer relation known not empty
1523  * ----------------
1524  */
1525
1526 /* these structs are defined in executor/hashjoin.h: */
1527 typedef struct HashJoinTupleData *HashJoinTuple;
1528 typedef struct HashJoinTableData *HashJoinTable;
1529
1530 typedef struct HashJoinState
1531 {
1532         JoinState       js;                             /* its first field is NodeTag */
1533         List       *hashclauses;        /* list of ExprState nodes */
1534         List       *hj_OuterHashKeys;           /* list of ExprState nodes */
1535         List       *hj_InnerHashKeys;           /* list of ExprState nodes */
1536         List       *hj_HashOperators;           /* list of operator OIDs */
1537         HashJoinTable hj_HashTable;
1538         uint32          hj_CurHashValue;
1539         int                     hj_CurBucketNo;
1540         int                     hj_CurSkewBucketNo;
1541         HashJoinTuple hj_CurTuple;
1542         TupleTableSlot *hj_OuterTupleSlot;
1543         TupleTableSlot *hj_HashTupleSlot;
1544         TupleTableSlot *hj_NullOuterTupleSlot;
1545         TupleTableSlot *hj_NullInnerTupleSlot;
1546         TupleTableSlot *hj_FirstOuterTupleSlot;
1547         int                     hj_JoinState;
1548         bool            hj_MatchedOuter;
1549         bool            hj_OuterNotEmpty;
1550 } HashJoinState;
1551
1552
1553 /* ----------------------------------------------------------------
1554  *                               Materialization State Information
1555  * ----------------------------------------------------------------
1556  */
1557
1558 /* ----------------
1559  *       MaterialState information
1560  *
1561  *              materialize nodes are used to materialize the results
1562  *              of a subplan into a temporary file.
1563  *
1564  *              ss.ss_ScanTupleSlot refers to output of underlying plan.
1565  * ----------------
1566  */
1567 typedef struct MaterialState
1568 {
1569         ScanState       ss;                             /* its first field is NodeTag */
1570         int                     eflags;                 /* capability flags to pass to tuplestore */
1571         bool            eof_underlying; /* reached end of underlying plan? */
1572         Tuplestorestate *tuplestorestate;
1573 } MaterialState;
1574
1575 /* ----------------
1576  *       SortState information
1577  * ----------------
1578  */
1579 typedef struct SortState
1580 {
1581         ScanState       ss;                             /* its first field is NodeTag */
1582         bool            randomAccess;   /* need random access to sort output? */
1583         bool            bounded;                /* is the result set bounded? */
1584         int64           bound;                  /* if bounded, how many tuples are needed */
1585         bool            sort_Done;              /* sort completed yet? */
1586         bool            bounded_Done;   /* value of bounded we did the sort with */
1587         int64           bound_Done;             /* value of bound we did the sort with */
1588         void       *tuplesortstate; /* private state of tuplesort.c */
1589 } SortState;
1590
1591 /* ---------------------
1592  *      GroupState information
1593  * -------------------------
1594  */
1595 typedef struct GroupState
1596 {
1597         ScanState       ss;                             /* its first field is NodeTag */
1598         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
1599         bool            grp_done;               /* indicates completion of Group scan */
1600 } GroupState;
1601
1602 /* ---------------------
1603  *      AggState information
1604  *
1605  *      ss.ss_ScanTupleSlot refers to output of underlying plan.
1606  *
1607  *      Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
1608  *      ecxt_aggnulls arrays, which hold the computed agg values for the current
1609  *      input group during evaluation of an Agg node's output tuple(s).  We
1610  *      create a second ExprContext, tmpcontext, in which to evaluate input
1611  *      expressions and run the aggregate transition functions.
1612  * -------------------------
1613  */
1614 /* these structs are private in nodeAgg.c: */
1615 typedef struct AggStatePerAggData *AggStatePerAgg;
1616 typedef struct AggStatePerGroupData *AggStatePerGroup;
1617
1618 typedef struct AggState
1619 {
1620         ScanState       ss;                             /* its first field is NodeTag */
1621         List       *aggs;                       /* all Aggref nodes in targetlist & quals */
1622         int                     numaggs;                /* length of list (could be zero!) */
1623         FmgrInfo   *eqfunctions;        /* per-grouping-field equality fns */
1624         FmgrInfo   *hashfunctions;      /* per-grouping-field hash fns */
1625         AggStatePerAgg peragg;          /* per-Aggref information */
1626         MemoryContext aggcontext;       /* memory context for long-lived data */
1627         ExprContext *tmpcontext;        /* econtext for input expressions */
1628         bool            agg_done;               /* indicates completion of Agg scan */
1629         /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
1630         AggStatePerGroup pergroup;      /* per-Aggref-per-group working state */
1631         HeapTuple       grp_firstTuple; /* copy of first tuple of current group */
1632         /* these fields are used in AGG_HASHED mode: */
1633         TupleHashTable hashtable;       /* hash table with one entry per group */
1634         TupleTableSlot *hashslot;       /* slot for loading hash table */
1635         List       *hash_needed;        /* list of columns needed in hash table */
1636         bool            table_filled;   /* hash table filled yet? */
1637         TupleHashIterator hashiter; /* for iterating through hash table */
1638 } AggState;
1639
1640 /* ----------------
1641  *      WindowAggState information
1642  * ----------------
1643  */
1644 /* these structs are private in nodeWindowAgg.c: */
1645 typedef struct WindowStatePerFuncData *WindowStatePerFunc;
1646 typedef struct WindowStatePerAggData *WindowStatePerAgg;
1647
1648 typedef struct WindowAggState
1649 {
1650         ScanState       ss;                             /* its first field is NodeTag */
1651
1652         /* these fields are filled in by ExecInitExpr: */
1653         List       *funcs;                      /* all WindowFunc nodes in targetlist */
1654         int                     numfuncs;               /* total number of window functions */
1655         int                     numaggs;                /* number that are plain aggregates */
1656
1657         WindowStatePerFunc perfunc; /* per-window-function information */
1658         WindowStatePerAgg peragg;       /* per-plain-aggregate information */
1659         FmgrInfo   *partEqfunctions;    /* equality funcs for partition columns */
1660         FmgrInfo   *ordEqfunctions; /* equality funcs for ordering columns */
1661         Tuplestorestate *buffer;        /* stores rows of current partition */
1662         int                     current_ptr;    /* read pointer # for current */
1663         int64           spooled_rows;   /* total # of rows in buffer */
1664         int64           currentpos;             /* position of current row in partition */
1665         int64           frameheadpos;   /* current frame head position */
1666         int64           frametailpos;   /* current frame tail position */
1667         /* use struct pointer to avoid including windowapi.h here */
1668         struct WindowObjectData *agg_winobj;            /* winobj for aggregate
1669                                                                                                  * fetches */
1670         int64           aggregatedbase; /* start row for current aggregates */
1671         int64           aggregatedupto; /* rows before this one are aggregated */
1672
1673         int                     frameOptions;   /* frame_clause options, see WindowDef */
1674         ExprState  *startOffset;        /* expression for starting bound offset */
1675         ExprState  *endOffset;          /* expression for ending bound offset */
1676         Datum           startOffsetValue;               /* result of startOffset evaluation */
1677         Datum           endOffsetValue; /* result of endOffset evaluation */
1678
1679         MemoryContext partcontext;      /* context for partition-lifespan data */
1680         MemoryContext aggcontext;       /* context for each aggregate data */
1681         ExprContext *tmpcontext;        /* short-term evaluation context */
1682
1683         bool            all_first;              /* true if the scan is starting */
1684         bool            all_done;               /* true if the scan is finished */
1685         bool            partition_spooled;              /* true if all tuples in current
1686                                                                                  * partition have been spooled into
1687                                                                                  * tuplestore */
1688         bool            more_partitions;/* true if there's more partitions after this
1689                                                                  * one */
1690         bool            framehead_valid;/* true if frameheadpos is known up to date
1691                                                                  * for current row */
1692         bool            frametail_valid;/* true if frametailpos is known up to date
1693                                                                  * for current row */
1694
1695         TupleTableSlot *first_part_slot;        /* first tuple of current or next
1696                                                                                  * partition */
1697
1698         /* temporary slots for tuples fetched back from tuplestore */
1699         TupleTableSlot *agg_row_slot;
1700         TupleTableSlot *temp_slot_1;
1701         TupleTableSlot *temp_slot_2;
1702 } WindowAggState;
1703
1704 /* ----------------
1705  *       UniqueState information
1706  *
1707  *              Unique nodes are used "on top of" sort nodes to discard
1708  *              duplicate tuples returned from the sort phase.  Basically
1709  *              all it does is compare the current tuple from the subplan
1710  *              with the previously fetched tuple (stored in its result slot).
1711  *              If the two are identical in all interesting fields, then
1712  *              we just fetch another tuple from the sort and try again.
1713  * ----------------
1714  */
1715 typedef struct UniqueState
1716 {
1717         PlanState       ps;                             /* its first field is NodeTag */
1718         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
1719         MemoryContext tempContext;      /* short-term context for comparisons */
1720 } UniqueState;
1721
1722 /* ----------------
1723  *       HashState information
1724  * ----------------
1725  */
1726 typedef struct HashState
1727 {
1728         PlanState       ps;                             /* its first field is NodeTag */
1729         HashJoinTable hashtable;        /* hash table for the hashjoin */
1730         List       *hashkeys;           /* list of ExprState nodes */
1731         /* hashkeys is same as parent's hj_InnerHashKeys */
1732 } HashState;
1733
1734 /* ----------------
1735  *       SetOpState information
1736  *
1737  *              Even in "sorted" mode, SetOp nodes are more complex than a simple
1738  *              Unique, since we have to count how many duplicates to return.  But
1739  *              we also support hashing, so this is really more like a cut-down
1740  *              form of Agg.
1741  * ----------------
1742  */
1743 /* this struct is private in nodeSetOp.c: */
1744 typedef struct SetOpStatePerGroupData *SetOpStatePerGroup;
1745
1746 typedef struct SetOpState
1747 {
1748         PlanState       ps;                             /* its first field is NodeTag */
1749         FmgrInfo   *eqfunctions;        /* per-grouping-field equality fns */
1750         FmgrInfo   *hashfunctions;      /* per-grouping-field hash fns */
1751         bool            setop_done;             /* indicates completion of output scan */
1752         long            numOutput;              /* number of dups left to output */
1753         MemoryContext tempContext;      /* short-term context for comparisons */
1754         /* these fields are used in SETOP_SORTED mode: */
1755         SetOpStatePerGroup pergroup;    /* per-group working state */
1756         HeapTuple       grp_firstTuple; /* copy of first tuple of current group */
1757         /* these fields are used in SETOP_HASHED mode: */
1758         TupleHashTable hashtable;       /* hash table with one entry per group */
1759         MemoryContext tableContext; /* memory context containing hash table */
1760         bool            table_filled;   /* hash table filled yet? */
1761         TupleHashIterator hashiter; /* for iterating through hash table */
1762 } SetOpState;
1763
1764 /* ----------------
1765  *       LockRowsState information
1766  *
1767  *              LockRows nodes are used to enforce FOR UPDATE/FOR SHARE locking.
1768  * ----------------
1769  */
1770 typedef struct LockRowsState
1771 {
1772         PlanState       ps;                             /* its first field is NodeTag */
1773         List       *lr_arowMarks;       /* List of ExecAuxRowMarks */
1774         EPQState        lr_epqstate;    /* for evaluating EvalPlanQual rechecks */
1775 } LockRowsState;
1776
1777 /* ----------------
1778  *       LimitState information
1779  *
1780  *              Limit nodes are used to enforce LIMIT/OFFSET clauses.
1781  *              They just select the desired subrange of their subplan's output.
1782  *
1783  * offset is the number of initial tuples to skip (0 does nothing).
1784  * count is the number of tuples to return after skipping the offset tuples.
1785  * If no limit count was specified, count is undefined and noCount is true.
1786  * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
1787  * ----------------
1788  */
1789 typedef enum
1790 {
1791         LIMIT_INITIAL,                          /* initial state for LIMIT node */
1792         LIMIT_RESCAN,                           /* rescan after recomputing parameters */
1793         LIMIT_EMPTY,                            /* there are no returnable rows */
1794         LIMIT_INWINDOW,                         /* have returned a row in the window */
1795         LIMIT_SUBPLANEOF,                       /* at EOF of subplan (within window) */
1796         LIMIT_WINDOWEND,                        /* stepped off end of window */
1797         LIMIT_WINDOWSTART                       /* stepped off beginning of window */
1798 } LimitStateCond;
1799
1800 typedef struct LimitState
1801 {
1802         PlanState       ps;                             /* its first field is NodeTag */
1803         ExprState  *limitOffset;        /* OFFSET parameter, or NULL if none */
1804         ExprState  *limitCount;         /* COUNT parameter, or NULL if none */
1805         int64           offset;                 /* current OFFSET value */
1806         int64           count;                  /* current COUNT, if any */
1807         bool            noCount;                /* if true, ignore count */
1808         LimitStateCond lstate;          /* state machine status, as above */
1809         int64           position;               /* 1-based index of last tuple returned */
1810         TupleTableSlot *subSlot;        /* tuple last obtained from subplan */
1811 } LimitState;
1812
1813 #endif   /* EXECNODES_H */