]> granicus.if.org Git - postgresql/blob - src/include/nodes/execnodes.h
Spell 'precedes', 'preceding' correctly in various places.
[postgresql] / src / include / nodes / execnodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * execnodes.h
4  *        definitions for executor state nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: execnodes.h,v 1.67 2001/11/21 22:57:01 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef EXECNODES_H
15 #define EXECNODES_H
16
17 #include "access/relscan.h"
18 #include "access/sdir.h"
19 #include "executor/hashjoin.h"
20 #include "executor/tuptable.h"
21 #include "fmgr.h"
22 #include "nodes/params.h"
23 #include "nodes/primnodes.h"
24
25 /* ----------------
26  *        IndexInfo information
27  *
28  *              this class holds the information needed to construct new index
29  *              entries for a particular index.  Used for both index_build and
30  *              retail creation of index entries.
31  *
32  *              NumIndexAttrs           number of columns in this index
33  *                                                      (1 if a func. index, else same as NumKeyAttrs)
34  *              NumKeyAttrs                     number of key attributes for this index
35  *                                                      (ie, number of attrs from underlying relation)
36  *              KeyAttrNumbers          underlying-rel attribute numbers used as keys
37  *              Predicate                       partial-index predicate, or NIL if none
38  *              FuncOid                         OID of function, or InvalidOid if not f. index
39  *              FuncInfo                        fmgr lookup data for function, if FuncOid valid
40  *              Unique                          is it a unique index?
41  * ----------------
42  */
43 typedef struct IndexInfo
44 {
45         NodeTag         type;
46         int                     ii_NumIndexAttrs;
47         int                     ii_NumKeyAttrs;
48         AttrNumber      ii_KeyAttrNumbers[INDEX_MAX_KEYS];
49         List       *ii_Predicate;
50         Oid                     ii_FuncOid;
51         FmgrInfo        ii_FuncInfo;
52         bool            ii_Unique;
53 } IndexInfo;
54
55 /* ----------------
56  *        ExprContext
57  *
58  *              This class holds the "current context" information
59  *              needed to evaluate expressions for doing tuple qualifications
60  *              and tuple projections.  For example, if an expression refers
61  *              to an attribute in the current inner tuple then we need to know
62  *              what the current inner tuple is and so we look at the expression
63  *              context.
64  *
65  *      There are two memory contexts associated with an ExprContext:
66  *      * ecxt_per_query_memory is a relatively long-lived context (such as
67  *        TransactionCommandContext); typically it's the same context the
68  *        ExprContext node itself is allocated in.      This context can be
69  *        used for purposes such as storing operator/function fcache nodes.
70  *      * ecxt_per_tuple_memory is a short-term context for expression results.
71  *        As the name suggests, it will typically be reset once per tuple,
72  *        before we begin to evaluate expressions for that tuple.  Each
73  *        ExprContext normally has its very own per-tuple memory context.
74  *      CurrentMemoryContext should be set to ecxt_per_tuple_memory before
75  *      calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
76  * ----------------
77  */
78 typedef struct ExprContext
79 {
80         NodeTag         type;
81         /* Tuples that Var nodes in expression may refer to */
82         TupleTableSlot *ecxt_scantuple;
83         TupleTableSlot *ecxt_innertuple;
84         TupleTableSlot *ecxt_outertuple;
85         /* Memory contexts for expression evaluation --- see notes above */
86         MemoryContext ecxt_per_query_memory;
87         MemoryContext ecxt_per_tuple_memory;
88         /* Values to substitute for Param nodes in expression */
89         ParamExecData *ecxt_param_exec_vals;            /* for PARAM_EXEC params */
90         ParamListInfo ecxt_param_list_info; /* for other param types */
91         /* Values to substitute for Aggref nodes in expression */
92         Datum      *ecxt_aggvalues; /* precomputed values for Aggref nodes */
93         bool       *ecxt_aggnulls;      /* null flags for Aggref nodes */
94 } ExprContext;
95
96 /*
97  * Set-result status returned by ExecEvalExpr()
98  */
99 typedef enum
100 {
101         ExprSingleResult,                       /* expression does not return a set */
102         ExprMultipleResult,                     /* this result is an element of a set */
103         ExprEndResult                           /* there are no more elements in the set */
104 } ExprDoneCond;
105
106 /*
107  * When calling a function that might return a set (multiple rows),
108  * a node of this type is passed as fcinfo->resultinfo to allow
109  * return status to be passed back.  A function returning set should
110  * raise an error if no such resultinfo is provided.
111  *
112  * XXX this mechanism is a quick hack and probably needs to be redesigned.
113  */
114 typedef struct ReturnSetInfo
115 {
116         NodeTag         type;
117         ExprDoneCond isDone;
118 } ReturnSetInfo;
119
120
121 /* ----------------
122  *              ProjectionInfo node information
123  *
124  *              This is all the information needed to perform projections
125  *              on a tuple.  Nodes which need to do projections create one
126  *              of these.  In theory, when a node wants to perform a projection
127  *              it should just update this information as necessary and then
128  *              call ExecProject().  -cim 6/3/91
129  *
130  *              targetlist              target list for projection
131  *              len                             length of target list
132  *              tupValue                array of pointers to projection results
133  *              exprContext             expression context for ExecTargetList
134  *              slot                    slot to place projection result in
135  * ----------------
136  */
137 typedef struct ProjectionInfo
138 {
139         NodeTag         type;
140         List       *pi_targetlist;
141         int                     pi_len;
142         Datum      *pi_tupValue;
143         ExprContext *pi_exprContext;
144         TupleTableSlot *pi_slot;
145 } ProjectionInfo;
146
147 /* ----------------
148  *        JunkFilter
149  *
150  *        This class is used to store information regarding junk attributes.
151  *        A junk attribute is an attribute in a tuple that is needed only for
152  *        storing intermediate information in the executor, and does not belong
153  *        in emitted tuples.    For example, when we do an UPDATE query,
154  *        the planner adds a "junk" entry to the targetlist so that the tuples
155  *        returned to ExecutePlan() contain an extra attribute: the ctid of
156  *        the tuple to be updated.      This is needed to do the update, but we
157  *        don't want the ctid to be part of the stored new tuple!  So, we
158  *        apply a "junk filter" to remove the junk attributes and form the
159  *        real output tuple.
160  *
161  *        targetList:           the original target list (including junk attributes).
162  *        length:                       the length of 'targetList'.
163  *        tupType:                      the tuple descriptor for the "original" tuple
164  *                                              (including the junk attributes).
165  *        cleanTargetList:      the "clean" target list (junk attributes removed).
166  *        cleanLength:          the length of 'cleanTargetList'
167  *        cleanTupType:         the tuple descriptor of the "clean" tuple (with
168  *                                              junk attributes removed).
169  *        cleanMap:                     A map with the correspondence between the non-junk
170  *                                              attribute numbers of the "original" tuple and the
171  *                                              attribute numbers of the "clean" tuple.
172  *        junkContext:          memory context holding the JunkFilter node and all
173  *                                              its subsidiary data structures.
174  *        resultSlot:           tuple slot that can be used to hold cleaned tuple.
175  *
176  * NOTE: the original targetList and tupType are passed to ExecInitJunkFilter,
177  * as is the resultSlot.  These items do not belong to the JunkFilter.  All
178  * the other subsidiary structures are created during ExecInitJunkFilter,
179  * and all of them can be freed by deleting the memory context junkContext.
180  * This would not be needed if we had a cleaner approach to managing
181  * query-lifetime data structures...
182  * ----------------
183  */
184 typedef struct JunkFilter
185 {
186         NodeTag         type;
187         List       *jf_targetList;
188         int                     jf_length;
189         TupleDesc       jf_tupType;
190         List       *jf_cleanTargetList;
191         int                     jf_cleanLength;
192         TupleDesc       jf_cleanTupType;
193         AttrNumber *jf_cleanMap;
194         MemoryContext jf_junkContext;
195         TupleTableSlot *jf_resultSlot;
196 } JunkFilter;
197
198 /* ----------------
199  *        ResultRelInfo information
200  *
201  *              Whenever we update an existing relation, we have to
202  *              update indices on the relation, and perhaps also fire triggers.
203  *              The ResultRelInfo class is used to hold all the information needed
204  *              about a result relation, including indices.. -cim 10/15/89
205  *
206  *              RangeTableIndex                 result relation's range table index
207  *              RelationDesc                    relation descriptor for result relation
208  *              NumIndices                              # of indices existing on result relation
209  *              IndexRelationDescs              array of relation descriptors for indices
210  *              IndexRelationInfo               array of key/attr info for indices
211  *              TrigDesc                                triggers to be fired, if any
212  *              TrigFunctions                   cached lookup info for trigger functions
213  *              ConstraintExprs                 array of constraint-checking expressions
214  *              junkFilter                              for removing junk attributes from tuples
215  * ----------------
216  */
217 typedef struct ResultRelInfo
218 {
219         NodeTag         type;
220         Index           ri_RangeTableIndex;
221         Relation        ri_RelationDesc;
222         int                     ri_NumIndices;
223         RelationPtr ri_IndexRelationDescs;
224         IndexInfo **ri_IndexRelationInfo;
225         TriggerDesc *ri_TrigDesc;
226         FmgrInfo   *ri_TrigFunctions;
227         List      **ri_ConstraintExprs;
228         JunkFilter *ri_junkFilter;
229 } ResultRelInfo;
230
231 /* ----------------
232  *        EState information
233  *
234  *              direction                                               direction of the scan
235  *
236  *              range_table                                             array of scan relation information
237  *
238  *              result_relation information             for insert/update/delete queries
239  *
240  *              into_relation_descriptor                relation being retrieved "into"
241  *
242  *              param_list_info                                 information needed to transform
243  *                                                                              Param nodes into Const nodes
244  *
245  *              tupleTable                                              this is a pointer to an array
246  *                                                                              of pointers to tuples used by
247  *                                                                              the executor at any given moment.
248  * ----------------
249  */
250 typedef struct EState
251 {
252         NodeTag         type;
253         ScanDirection es_direction;
254         Snapshot        es_snapshot;
255         List       *es_range_table;
256         ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
257         int                     es_num_result_relations;                /* length of array */
258         ResultRelInfo *es_result_relation_info;         /* currently active array
259                                                                                                  * elt */
260         JunkFilter *es_junkFilter;      /* currently active junk filter */
261         Relation        es_into_relation_descriptor;
262         ParamListInfo es_param_list_info;
263         ParamExecData *es_param_exec_vals;      /* this is for subselects */
264         TupleTable      es_tupleTable;
265         uint32          es_processed;   /* # of tuples processed */
266         Oid                     es_lastoid;             /* last oid processed (by INSERT) */
267         List       *es_rowMark;         /* not good place, but there is no other */
268         MemoryContext es_query_cxt; /* per-query context in which EState lives */
269
270         /*
271          * this ExprContext is for per-output-tuple operations, such as
272          * constraint checks and index-value computations.      It will be reset
273          * for each output tuple.  Note that it will be created only if
274          * needed.
275          */
276         ExprContext *es_per_tuple_exprcontext;
277         /* Below is to re-evaluate plan qual in READ COMMITTED mode */
278         struct Plan *es_origPlan;
279         Pointer         es_evalPlanQual;
280         bool       *es_evTupleNull;
281         HeapTuple  *es_evTuple;
282         bool            es_useEvalPlan;
283 } EState;
284
285 /* ----------------
286  *              Executor Type information needed by plannodes.h
287  *
288  *|             Note: the bogus classes CommonState and CommonScanState exist only
289  *|                       because our inheritance system only allows single inheritance
290  *|                       and we have to have unique slot names.  Hence two or more
291  *|                       classes which want to have a common slot must ALL inherit
292  *|                       the slot from some other class.  (This is a big hack to
293  *|                       allow our classes to share slot names..)
294  *|
295  *|             Example:
296  *|                       the class Result and the class NestLoop nodes both want
297  *|                       a slot called "OuterTuple" so they both have to inherit
298  *|                       it from some other class.  In this case they inherit
299  *|                       it from CommonState.  "CommonState" and "CommonScanState" are
300  *|                       the best names I could come up with for this sort of
301  *|                       stuff.
302  *|
303  *|                       As a result, many classes have extra slots which they
304  *|                       don't use.  These slots are denoted (unused) in the
305  *|                       comment preceding the class definition.       If you
306  *|                       comes up with a better idea of a way of doing things
307  *|                       along these lines, then feel free to make your idea
308  *|                       known to me.. -cim 10/15/89
309  * ----------------
310  */
311
312 /* ----------------------------------------------------------------
313  *                               Common Executor State Information
314  * ----------------------------------------------------------------
315  */
316
317 /* ----------------
318  *       CommonState information
319  *
320  *              Superclass for all executor node-state object types.
321  *
322  *              OuterTupleSlot     pointer to slot containing current "outer" tuple
323  *              ResultTupleSlot    pointer to slot in tuple table for projected tuple
324  *              ExprContext                node's expression-evaluation context
325  *              ProjInfo                   info this node uses to form tuple projections
326  *              TupFromTlist       state flag used by some node types (why kept here?)
327  * ----------------
328  */
329 typedef struct CommonState
330 {
331         NodeTag         type;                   /* its first field is NodeTag */
332         TupleTableSlot *cs_OuterTupleSlot;
333         TupleTableSlot *cs_ResultTupleSlot;
334         ExprContext *cs_ExprContext;
335         ProjectionInfo *cs_ProjInfo;
336         bool            cs_TupFromTlist;
337 } CommonState;
338
339
340 /* ----------------------------------------------------------------
341  *                               Control Node State Information
342  * ----------------------------------------------------------------
343  */
344
345 /* ----------------
346  *       ResultState information
347  *
348  *              done                       flag which tells us to quit when we
349  *                                                 have already returned a constant tuple.
350  * ----------------
351  */
352 typedef struct ResultState
353 {
354         CommonState cstate;                     /* its first field is NodeTag */
355         bool            rs_done;
356         bool            rs_checkqual;
357 } ResultState;
358
359 /* ----------------
360  *       AppendState information
361  *
362  *              whichplan               which plan is being executed (0 .. n-1)
363  *              firstplan               first plan to execute (usually 0)
364  *              lastplan                last plan to execute (usually n-1)
365  *              nplans                  how many plans are in the list
366  *              initialized             array of ExecInitNode() results
367  * ----------------
368  */
369 typedef struct AppendState
370 {
371         CommonState cstate;                     /* its first field is NodeTag */
372         int                     as_whichplan;
373         int                     as_firstplan;
374         int                     as_lastplan;
375         int                     as_nplans;
376         bool       *as_initialized;
377 } AppendState;
378
379 /* ----------------------------------------------------------------
380  *                               Scan State Information
381  * ----------------------------------------------------------------
382  */
383
384 /* ----------------
385  *       CommonScanState information
386  *
387  *              CommonScanState extends CommonState for node types that represent
388  *              scans of an underlying relation.  It can also be used for nodes
389  *              that scan the output of an underlying plan node --- in that case,
390  *              only ScanTupleSlot is actually useful, and it refers to the tuple
391  *              retrieved from the subplan.
392  *
393  *              currentRelation    relation being scanned (NULL if none)
394  *              currentScanDesc    current scan descriptor for scan (NULL if none)
395  *              ScanTupleSlot      pointer to slot in tuple table holding scan tuple
396  * ----------------
397  */
398 typedef struct CommonScanState
399 {
400         CommonState cstate;                     /* its first field is NodeTag */
401         Relation        css_currentRelation;
402         HeapScanDesc css_currentScanDesc;
403         TupleTableSlot *css_ScanTupleSlot;
404 } CommonScanState;
405
406 /*
407  * SeqScan uses a bare CommonScanState as its state item, since it needs
408  * no additional fields.
409  */
410
411 /* ----------------
412  *       IndexScanState information
413  *
414  *              Note that an IndexScan node *also* has a CommonScanState state item.
415  *              IndexScanState stores the info needed specifically for indexing.
416  *              There's probably no good reason why this is a separate node type
417  *              rather than an extension of CommonScanState.
418  *
419  *              NumIndices                 number of indices in this scan
420  *              IndexPtr                   current index in use
421  *              ScanKeys                   Skey structures to scan index rels
422  *              NumScanKeys                array of no of keys in each Skey struct
423  *              RuntimeKeyInfo     array of array of flags for Skeys evaled at runtime
424  *              RuntimeContext     expr context for evaling runtime Skeys
425  *              RuntimeKeysReady   true if runtime Skeys have been computed
426  *              RelationDescs      ptr to array of relation descriptors
427  *              ScanDescs                  ptr to array of scan descriptors
428  * ----------------
429  */
430 typedef struct IndexScanState
431 {
432         NodeTag         type;
433         int                     iss_NumIndices;
434         int                     iss_IndexPtr;
435         int                     iss_MarkIndexPtr;
436         ScanKey    *iss_ScanKeys;
437         int                *iss_NumScanKeys;
438         int               **iss_RuntimeKeyInfo;
439         ExprContext *iss_RuntimeContext;
440         bool            iss_RuntimeKeysReady;
441         RelationPtr iss_RelationDescs;
442         IndexScanDescPtr iss_ScanDescs;
443         HeapTupleData iss_htup;
444 } IndexScanState;
445
446 /* ----------------
447  *       TidScanState information
448  *
449  *              Note that a TidScan node *also* has a CommonScanState state item.
450  *              There's probably no good reason why this is a separate node type
451  *              rather than an extension of CommonScanState.
452  *
453  *              NumTids            number of tids in this scan
454  *              TidPtr             current tid in use
455  *              TidList            evaluated item pointers
456  * ----------------
457  */
458 typedef struct TidScanState
459 {
460         NodeTag         type;
461         int                     tss_NumTids;
462         int                     tss_TidPtr;
463         int                     tss_MarkTidPtr;
464         ItemPointerData *tss_TidList;
465         HeapTupleData tss_htup;
466 } TidScanState;
467
468 /* ----------------
469  *       SubqueryScanState information
470  *
471  *              SubqueryScanState is used for scanning a sub-query in the range table.
472  *              The sub-query will have its own EState, which we save here.
473  *              ScanTupleSlot references the current output tuple of the sub-query.
474  *
475  *              SubEState                  exec state for sub-query
476  * ----------------
477  */
478 typedef struct SubqueryScanState
479 {
480         CommonScanState csstate;        /* its first field is NodeTag */
481         EState     *sss_SubEState;
482 } SubqueryScanState;
483
484 /* ----------------------------------------------------------------
485  *                               Join State Information
486  * ----------------------------------------------------------------
487  */
488
489 /* ----------------
490  *       JoinState information
491  *
492  *              Superclass for state items of join nodes.
493  *              Currently this is the same as CommonState.
494  * ----------------
495  */
496 typedef CommonState JoinState;
497
498 /* ----------------
499  *       NestLoopState information
500  *
501  *              NeedNewOuter       true if need new outer tuple on next call
502  *              MatchedOuter       true if found a join match for current outer tuple
503  *              NullInnerTupleSlot prepared null tuple for left outer joins
504  * ----------------
505  */
506 typedef struct NestLoopState
507 {
508         JoinState       jstate;                 /* its first field is NodeTag */
509         bool            nl_NeedNewOuter;
510         bool            nl_MatchedOuter;
511         TupleTableSlot *nl_NullInnerTupleSlot;
512 } NestLoopState;
513
514 /* ----------------
515  *       MergeJoinState information
516  *
517  *              OuterSkipQual      outerKey1 < innerKey1 ...
518  *              InnerSkipQual      outerKey1 > innerKey1 ...
519  *              JoinState                  current "state" of join. see executor.h
520  *              MatchedOuter       true if found a join match for current outer tuple
521  *              MatchedInner       true if found a join match for current inner tuple
522  *              OuterTupleSlot     pointer to slot in tuple table for cur outer tuple
523  *              InnerTupleSlot     pointer to slot in tuple table for cur inner tuple
524  *              MarkedTupleSlot    pointer to slot in tuple table for marked tuple
525  *              NullOuterTupleSlot prepared null tuple for right outer joins
526  *              NullInnerTupleSlot prepared null tuple for left outer joins
527  * ----------------
528  */
529 typedef struct MergeJoinState
530 {
531         JoinState       jstate;                 /* its first field is NodeTag */
532         List       *mj_OuterSkipQual;
533         List       *mj_InnerSkipQual;
534         int                     mj_JoinState;
535         bool            mj_MatchedOuter;
536         bool            mj_MatchedInner;
537         TupleTableSlot *mj_OuterTupleSlot;
538         TupleTableSlot *mj_InnerTupleSlot;
539         TupleTableSlot *mj_MarkedTupleSlot;
540         TupleTableSlot *mj_NullOuterTupleSlot;
541         TupleTableSlot *mj_NullInnerTupleSlot;
542 } MergeJoinState;
543
544 /* ----------------
545  *       HashJoinState information
546  *
547  *              hj_HashTable                    hash table for the hashjoin
548  *              hj_CurBucketNo                  bucket# for current outer tuple
549  *              hj_CurTuple                             last inner tuple matched to current outer
550  *                                                              tuple, or NULL if starting search
551  *                                                              (CurBucketNo and CurTuple are meaningless
552  *                                                               unless OuterTupleSlot is nonempty!)
553  *              hj_InnerHashKey                 the inner hash key in the hashjoin condition
554  *              hj_OuterTupleSlot               tuple slot for outer tuples
555  *              hj_HashTupleSlot                tuple slot for hashed tuples
556  *              hj_NullInnerTupleSlot   prepared null tuple for left outer joins
557  *              hj_NeedNewOuter                 true if need new outer tuple on next call
558  *              hj_MatchedOuter                 true if found a join match for current outer
559  *              hj_hashdone                             true if hash-table-build phase is done
560  * ----------------
561  */
562 typedef struct HashJoinState
563 {
564         JoinState       jstate;                 /* its first field is NodeTag */
565         HashJoinTable hj_HashTable;
566         int                     hj_CurBucketNo;
567         HashJoinTuple hj_CurTuple;
568         Node       *hj_InnerHashKey;
569         TupleTableSlot *hj_OuterTupleSlot;
570         TupleTableSlot *hj_HashTupleSlot;
571         TupleTableSlot *hj_NullInnerTupleSlot;
572         bool            hj_NeedNewOuter;
573         bool            hj_MatchedOuter;
574         bool            hj_hashdone;
575 } HashJoinState;
576
577
578 /* ----------------------------------------------------------------
579  *                               Materialization State Information
580  * ----------------------------------------------------------------
581  */
582
583 /* ----------------
584  *       MaterialState information
585  *
586  *              materialize nodes are used to materialize the results
587  *              of a subplan into a temporary file.
588  *
589  *              csstate.css_ScanTupleSlot refers to output of underlying plan.
590  *
591  *              tuplestorestate         private state of tuplestore.c
592  * ----------------
593  */
594 typedef struct MaterialState
595 {
596         CommonScanState csstate;        /* its first field is NodeTag */
597         void       *tuplestorestate;
598 } MaterialState;
599
600 /* ---------------------
601  *      AggregateState information
602  *
603  *      csstate.css_ScanTupleSlot refers to output of underlying plan.
604  *
605  *      Note: the associated ExprContext contains ecxt_aggvalues and ecxt_aggnulls
606  *      arrays, which hold the computed agg values for the current input group
607  *      during evaluation of an Agg node's output tuple(s).
608  * -------------------------
609  */
610 typedef struct AggStatePerAggData *AggStatePerAgg;              /* private in nodeAgg.c */
611
612 typedef struct AggState
613 {
614         CommonScanState csstate;        /* its first field is NodeTag */
615         List       *aggs;                       /* all Aggref nodes in targetlist & quals */
616         int                     numaggs;                /* length of list (could be zero!) */
617         AggStatePerAgg peragg;          /* per-Aggref working state */
618         MemoryContext tup_cxt;          /* context for per-output-tuple
619                                                                  * expressions */
620         MemoryContext agg_cxt[2];       /* pair of expression eval memory contexts */
621         int                     which_cxt;              /* 0 or 1, indicates current agg_cxt */
622         bool            agg_done;               /* indicates completion of Agg scan */
623 } AggState;
624
625 /* ---------------------
626  *      GroupState information
627  * -------------------------
628  */
629 typedef struct GroupState
630 {
631         CommonScanState csstate;        /* its first field is NodeTag */
632         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
633         bool            grp_useFirstTuple;              /* first tuple not processed yet */
634         bool            grp_done;
635         HeapTuple       grp_firstTuple;
636 } GroupState;
637
638 /* ----------------
639  *       SortState information
640  *
641  *              sort_Done               indicates whether sort has been performed yet
642  *              tuplesortstate  private state of tuplesort.c
643  * ----------------
644  */
645 typedef struct SortState
646 {
647         CommonScanState csstate;        /* its first field is NodeTag */
648         bool            sort_Done;
649         void       *tuplesortstate;
650 } SortState;
651
652 /* ----------------
653  *       UniqueState information
654  *
655  *              Unique nodes are used "on top of" sort nodes to discard
656  *              duplicate tuples returned from the sort phase.  Basically
657  *              all it does is compare the current tuple from the subplan
658  *              with the previously fetched tuple stored in priorTuple.
659  *              If the two are identical in all interesting fields, then
660  *              we just fetch another tuple from the sort and try again.
661  * ----------------
662  */
663 typedef struct UniqueState
664 {
665         CommonState cstate;                     /* its first field is NodeTag */
666         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
667         HeapTuple       priorTuple;             /* most recently returned tuple, or NULL */
668         MemoryContext tempContext;      /* short-term context for comparisons */
669 } UniqueState;
670
671 /* ----------------
672  *       SetOpState information
673  *
674  *              SetOp nodes are used "on top of" sort nodes to discard
675  *              duplicate tuples returned from the sort phase.  These are
676  *              more complex than a simple Unique since we have to count
677  *              how many duplicates to return.
678  * ----------------
679  */
680 typedef struct SetOpState
681 {
682         CommonState cstate;                     /* its first field is NodeTag */
683         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
684         bool            subplan_done;   /* has subplan returned EOF? */
685         long            numLeft;                /* number of left-input dups of cur group */
686         long            numRight;               /* number of right-input dups of cur group */
687         long            numOutput;              /* number of dups left to output */
688         MemoryContext tempContext;      /* short-term context for comparisons */
689 } SetOpState;
690
691 /* ----------------
692  *       LimitState information
693  *
694  *              Limit nodes are used to enforce LIMIT/OFFSET clauses.
695  *              They just select the desired subrange of their subplan's output.
696  *
697  * offset is the number of initial tuples to skip (0 does nothing).
698  * count is the number of tuples to return after skipping the offset tuples.
699  * If no limit count was specified, count is undefined and noCount is true.
700  * ----------------
701  */
702 typedef struct LimitState
703 {
704         CommonState cstate;                     /* its first field is NodeTag */
705         long            offset;                 /* current OFFSET value */
706         long            count;                  /* current COUNT, if any */
707         long            position;               /* 1-based index of last tuple fetched */
708         bool            parmsSet;               /* have we calculated offset/limit yet? */
709         bool            noCount;                /* if true, ignore count */
710         bool            atEnd;                  /* if true, we've reached EOF of subplan */
711 } LimitState;
712
713
714 /* ----------------
715  *       HashState information
716  *
717  *              hashtable                       hash table for the hashjoin
718  * ----------------
719  */
720 typedef struct HashState
721 {
722         CommonState cstate;                     /* its first field is NodeTag */
723         HashJoinTable hashtable;
724 } HashState;
725
726 #ifdef NOT_USED
727 /* -----------------------
728  *      TeeState information
729  *        leftPlace  :    next item in the queue unseen by the left parent
730  *        rightPlace :    next item in the queue unseen by the right parent
731  *        lastPlace  :    last item in the queue
732  *        bufferRelname :  name of the relation used as the buffer queue
733  *        bufferRel             :  the relation used as the buffer queue
734  *        mcxt                  :  for now, tee's have their own memory context
735  *                                         may be cleaned up later if portals are cleaned up
736  *
737  * initially, a Tee starts with [left/right]Place variables set to      -1.
738  * on cleanup, queue is free'd when both leftPlace and rightPlace = -1
739  * -------------------------
740 */
741 typedef struct TeeState
742 {
743         CommonState cstate;                     /* its first field is NodeTag */
744         int                     tee_leftPlace,
745                                 tee_rightPlace,
746                                 tee_lastPlace;
747         char       *tee_bufferRelname;
748         Relation        tee_bufferRel;
749         MemoryContext tee_mcxt;
750         HeapScanDesc tee_leftScanDesc,
751                                 tee_rightScanDesc;
752 }       TeeState;
753 #endif
754
755 #endif   /* EXECNODES_H */