~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/include/nodes/execnodes.h

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * execnodes.h
 
4
 *        definitions for executor state nodes
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.122 2004-12-31 22:03:34 pgsql Exp $
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef EXECNODES_H
 
15
#define EXECNODES_H
 
16
 
 
17
#include "access/relscan.h"
 
18
#include "executor/hashjoin.h"
 
19
#include "executor/tuptable.h"
 
20
#include "fmgr.h"
 
21
#include "nodes/bitmapset.h"
 
22
#include "nodes/params.h"
 
23
#include "nodes/plannodes.h"
 
24
#include "utils/hsearch.h"
 
25
#include "utils/tuplestore.h"
 
26
 
 
27
 
 
28
/* ----------------
 
29
 *        IndexInfo information
 
30
 *
 
31
 *              this struct holds the information needed to construct new index
 
32
 *              entries for a particular index.  Used for both index_build and
 
33
 *              retail creation of index entries.
 
34
 *
 
35
 *              NumIndexAttrs           number of columns in this index
 
36
 *              KeyAttrNumbers          underlying-rel attribute numbers used as keys
 
37
 *                                                      (zeroes indicate expressions)
 
38
 *              Expressions                     expr trees for expression entries, or NIL if none
 
39
 *              ExpressionsState        exec state for expressions, or NIL if none
 
40
 *              Predicate                       partial-index predicate, or NIL if none
 
41
 *              PredicateState          exec state for predicate, or NIL if none
 
42
 *              Unique                          is it a unique index?
 
43
 * ----------------
 
44
 */
 
45
typedef struct IndexInfo
 
46
{
 
47
        NodeTag         type;
 
48
        int                     ii_NumIndexAttrs;
 
49
        AttrNumber      ii_KeyAttrNumbers[INDEX_MAX_KEYS];
 
50
        List       *ii_Expressions; /* list of Expr */
 
51
        List       *ii_ExpressionsState;        /* list of ExprState */
 
52
        List       *ii_Predicate;       /* list of Expr */
 
53
        List       *ii_PredicateState;          /* list of ExprState */
 
54
        bool            ii_Unique;
 
55
} IndexInfo;
 
56
 
 
57
/* ----------------
 
58
 *        ExprContext_CB
 
59
 *
 
60
 *              List of callbacks to be called at ExprContext shutdown.
 
61
 * ----------------
 
62
 */
 
63
typedef void (*ExprContextCallbackFunction) (Datum arg);
 
64
 
 
65
typedef struct ExprContext_CB
 
66
{
 
67
        struct ExprContext_CB *next;
 
68
        ExprContextCallbackFunction function;
 
69
        Datum           arg;
 
70
} ExprContext_CB;
 
71
 
 
72
/* ----------------
 
73
 *        ExprContext
 
74
 *
 
75
 *              This class holds the "current context" information
 
76
 *              needed to evaluate expressions for doing tuple qualifications
 
77
 *              and tuple projections.  For example, if an expression refers
 
78
 *              to an attribute in the current inner tuple then we need to know
 
79
 *              what the current inner tuple is and so we look at the expression
 
80
 *              context.
 
81
 *
 
82
 *      There are two memory contexts associated with an ExprContext:
 
83
 *      * ecxt_per_query_memory is a query-lifespan context, typically the same
 
84
 *        context the ExprContext node itself is allocated in.  This context
 
85
 *        can be used for purposes such as storing function call cache info.
 
86
 *      * ecxt_per_tuple_memory is a short-term context for expression results.
 
87
 *        As the name suggests, it will typically be reset once per tuple,
 
88
 *        before we begin to evaluate expressions for that tuple.  Each
 
89
 *        ExprContext normally has its very own per-tuple memory context.
 
90
 *
 
91
 *      CurrentMemoryContext should be set to ecxt_per_tuple_memory before
 
92
 *      calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
 
93
 * ----------------
 
94
 */
 
95
typedef struct ExprContext
 
96
{
 
97
        NodeTag         type;
 
98
 
 
99
        /* Tuples that Var nodes in expression may refer to */
 
100
        TupleTableSlot *ecxt_scantuple;
 
101
        TupleTableSlot *ecxt_innertuple;
 
102
        TupleTableSlot *ecxt_outertuple;
 
103
 
 
104
        /* Memory contexts for expression evaluation --- see notes above */
 
105
        MemoryContext ecxt_per_query_memory;
 
106
        MemoryContext ecxt_per_tuple_memory;
 
107
 
 
108
        /* Values to substitute for Param nodes in expression */
 
109
        ParamExecData *ecxt_param_exec_vals;            /* for PARAM_EXEC params */
 
110
        ParamListInfo ecxt_param_list_info; /* for other param types */
 
111
 
 
112
        /* Values to substitute for Aggref nodes in expression */
 
113
        Datum      *ecxt_aggvalues; /* precomputed values for Aggref nodes */
 
114
        bool       *ecxt_aggnulls;      /* null flags for Aggref nodes */
 
115
 
 
116
        /* Value to substitute for CaseTestExpr nodes in expression */
 
117
        Datum           caseValue_datum;
 
118
        bool            caseValue_isNull;
 
119
 
 
120
        /* Value to substitute for CoerceToDomainValue nodes in expression */
 
121
        Datum           domainValue_datum;
 
122
        bool            domainValue_isNull;
 
123
 
 
124
        /* Link to containing EState */
 
125
        struct EState *ecxt_estate;
 
126
 
 
127
        /* Functions to call back when ExprContext is shut down */
 
128
        ExprContext_CB *ecxt_callbacks;
 
129
} ExprContext;
 
130
 
 
131
/*
 
132
 * Set-result status returned by ExecEvalExpr()
 
133
 */
 
134
typedef enum
 
135
{
 
136
        ExprSingleResult,                       /* expression does not return a set */
 
137
        ExprMultipleResult,                     /* this result is an element of a set */
 
138
        ExprEndResult                           /* there are no more elements in the set */
 
139
} ExprDoneCond;
 
140
 
 
141
/*
 
142
 * Return modes for functions returning sets.  Note values must be chosen
 
143
 * as separate bits so that a bitmask can be formed to indicate supported
 
144
 * modes.
 
145
 */
 
146
typedef enum
 
147
{
 
148
        SFRM_ValuePerCall = 0x01,       /* one value returned per call */
 
149
        SFRM_Materialize = 0x02         /* result set instantiated in Tuplestore */
 
150
} SetFunctionReturnMode;
 
151
 
 
152
/*
 
153
 * When calling a function that might return a set (multiple rows),
 
154
 * a node of this type is passed as fcinfo->resultinfo to allow
 
155
 * return status to be passed back.  A function returning set should
 
156
 * raise an error if no such resultinfo is provided.
 
157
 */
 
158
typedef struct ReturnSetInfo
 
159
{
 
160
        NodeTag         type;
 
161
        /* values set by caller: */
 
162
        ExprContext *econtext;          /* context function is being called in */
 
163
        TupleDesc       expectedDesc;   /* tuple descriptor expected by caller */
 
164
        int                     allowedModes;   /* bitmask: return modes caller can handle */
 
165
        /* result status from function (but pre-initialized by caller): */
 
166
        SetFunctionReturnMode returnMode;       /* actual return mode */
 
167
        ExprDoneCond isDone;            /* status for ValuePerCall mode */
 
168
        /* fields filled by function in Materialize return mode: */
 
169
        Tuplestorestate *setResult; /* holds the complete returned tuple set */
 
170
        TupleDesc       setDesc;                /* actual descriptor for returned tuples */
 
171
} ReturnSetInfo;
 
172
 
 
173
/* ----------------
 
174
 *              ProjectionInfo node information
 
175
 *
 
176
 *              This is all the information needed to perform projections ---
 
177
 *              that is, form new tuples by evaluation of targetlist expressions.
 
178
 *              Nodes which need to do projections create one of these.
 
179
 *              In theory, when a node wants to perform a projection
 
180
 *              it should just update this information as necessary and then
 
181
 *              call ExecProject().  -cim 6/3/91
 
182
 *
 
183
 *              ExecProject() evaluates the tlist, forms a tuple, and stores it
 
184
 *              in the given slot.      As a side-effect, the actual datum values and
 
185
 *              null indicators are placed in the work arrays tupValues/tupNulls.
 
186
 *
 
187
 *              targetlist              target list for projection
 
188
 *              exprContext             expression context in which to evaluate targetlist
 
189
 *              slot                    slot to place projection result in
 
190
 *              tupValues               array of computed values
 
191
 *              tupNull                 array of null indicators
 
192
 *              itemIsDone              workspace for ExecProject
 
193
 * ----------------
 
194
 */
 
195
typedef struct ProjectionInfo
 
196
{
 
197
        NodeTag         type;
 
198
        List       *pi_targetlist;
 
199
        ExprContext *pi_exprContext;
 
200
        TupleTableSlot *pi_slot;
 
201
        Datum      *pi_tupValues;
 
202
        char       *pi_tupNulls;
 
203
        ExprDoneCond *pi_itemIsDone;
 
204
} ProjectionInfo;
 
205
 
 
206
/* ----------------
 
207
 *        JunkFilter
 
208
 *
 
209
 *        This class is used to store information regarding junk attributes.
 
210
 *        A junk attribute is an attribute in a tuple that is needed only for
 
211
 *        storing intermediate information in the executor, and does not belong
 
212
 *        in emitted tuples.  For example, when we do an UPDATE query,
 
213
 *        the planner adds a "junk" entry to the targetlist so that the tuples
 
214
 *        returned to ExecutePlan() contain an extra attribute: the ctid of
 
215
 *        the tuple to be updated.      This is needed to do the update, but we
 
216
 *        don't want the ctid to be part of the stored new tuple!  So, we
 
217
 *        apply a "junk filter" to remove the junk attributes and form the
 
218
 *        real output tuple.
 
219
 *
 
220
 *        targetList:           the original target list (including junk attributes).
 
221
 *        cleanTupType:         the tuple descriptor for the "clean" tuple (with
 
222
 *                                              junk attributes removed).
 
223
 *        cleanMap:                     A map with the correspondence between the non-junk
 
224
 *                                              attribute numbers of the "original" tuple and the
 
225
 *                                              attribute numbers of the "clean" tuple.
 
226
 *        resultSlot:           tuple slot that can be used to hold cleaned tuple.
 
227
 * ----------------
 
228
 */
 
229
typedef struct JunkFilter
 
230
{
 
231
        NodeTag         type;
 
232
        List       *jf_targetList;
 
233
        TupleDesc       jf_cleanTupType;
 
234
        AttrNumber *jf_cleanMap;
 
235
        TupleTableSlot *jf_resultSlot;
 
236
} JunkFilter;
 
237
 
 
238
/* ----------------
 
239
 *        ResultRelInfo information
 
240
 *
 
241
 *              Whenever we update an existing relation, we have to
 
242
 *              update indices on the relation, and perhaps also fire triggers.
 
243
 *              The ResultRelInfo class is used to hold all the information needed
 
244
 *              about a result relation, including indices.. -cim 10/15/89
 
245
 *
 
246
 *              RangeTableIndex                 result relation's range table index
 
247
 *              RelationDesc                    relation descriptor for result relation
 
248
 *              NumIndices                              # of indices existing on result relation
 
249
 *              IndexRelationDescs              array of relation descriptors for indices
 
250
 *              IndexRelationInfo               array of key/attr info for indices
 
251
 *              TrigDesc                                triggers to be fired, if any
 
252
 *              TrigFunctions                   cached lookup info for trigger functions
 
253
 *              ConstraintExprs                 array of constraint-checking expr states
 
254
 *              junkFilter                              for removing junk attributes from tuples
 
255
 * ----------------
 
256
 */
 
257
typedef struct ResultRelInfo
 
258
{
 
259
        NodeTag         type;
 
260
        Index           ri_RangeTableIndex;
 
261
        Relation        ri_RelationDesc;
 
262
        int                     ri_NumIndices;
 
263
        RelationPtr ri_IndexRelationDescs;
 
264
        IndexInfo **ri_IndexRelationInfo;
 
265
        TriggerDesc *ri_TrigDesc;
 
266
        FmgrInfo   *ri_TrigFunctions;
 
267
        List      **ri_ConstraintExprs;
 
268
        JunkFilter *ri_junkFilter;
 
269
} ResultRelInfo;
 
270
 
 
271
/* ----------------
 
272
 *        EState information
 
273
 *
 
274
 * Master working state for an Executor invocation
 
275
 * ----------------
 
276
 */
 
277
typedef struct EState
 
278
{
 
279
        NodeTag         type;
 
280
 
 
281
        /* Basic state for all query types: */
 
282
        ScanDirection es_direction; /* current scan direction */
 
283
        Snapshot        es_snapshot;    /* time qual to use */
 
284
        Snapshot        es_crosscheck_snapshot; /* crosscheck time qual for RI */
 
285
        List       *es_range_table; /* List of RangeTableEntrys */
 
286
 
 
287
        /* Info about target table for insert/update/delete queries: */
 
288
        ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
 
289
        int                     es_num_result_relations;                /* length of array */
 
290
        ResultRelInfo *es_result_relation_info;         /* currently active array
 
291
                                                                                                 * elt */
 
292
        JunkFilter *es_junkFilter;      /* currently active junk filter */
 
293
        Relation        es_into_relation_descriptor;    /* for SELECT INTO */
 
294
 
 
295
        /* Parameter info: */
 
296
        ParamListInfo es_param_list_info;       /* values of external params */
 
297
        ParamExecData *es_param_exec_vals;      /* values of internal params */
 
298
 
 
299
        /* Other working state: */
 
300
        MemoryContext es_query_cxt; /* per-query context in which EState lives */
 
301
 
 
302
        TupleTable      es_tupleTable;  /* Array of TupleTableSlots */
 
303
 
 
304
        uint32          es_processed;   /* # of tuples processed */
 
305
        Oid                     es_lastoid;             /* last oid processed (by INSERT) */
 
306
        List       *es_rowMark;         /* not good place, but there is no other */
 
307
 
 
308
        bool            es_instrument;  /* true requests runtime instrumentation */
 
309
        bool            es_select_into; /* true if doing SELECT INTO */
 
310
        bool            es_into_oids;   /* true to generate OIDs in SELECT INTO */
 
311
 
 
312
        List       *es_exprcontexts;    /* List of ExprContexts within EState */
 
313
 
 
314
        /*
 
315
         * this ExprContext is for per-output-tuple operations, such as
 
316
         * constraint checks and index-value computations.      It will be reset
 
317
         * for each output tuple.  Note that it will be created only if
 
318
         * needed.
 
319
         */
 
320
        ExprContext *es_per_tuple_exprcontext;
 
321
 
 
322
        /* Below is to re-evaluate plan qual in READ COMMITTED mode */
 
323
        Plan       *es_topPlan;         /* link to top of plan tree */
 
324
        struct evalPlanQual *es_evalPlanQual;           /* chain of PlanQual
 
325
                                                                                                 * states */
 
326
        bool       *es_evTupleNull; /* local array of EPQ status */
 
327
        HeapTuple  *es_evTuple;         /* shared array of EPQ substitute tuples */
 
328
        bool            es_useEvalPlan; /* evaluating EPQ tuples? */
 
329
} EState;
 
330
 
 
331
 
 
332
/* ----------------------------------------------------------------
 
333
 *                               Tuple Hash Tables
 
334
 *
 
335
 * All-in-memory tuple hash tables are used for a number of purposes.
 
336
 * ----------------------------------------------------------------
 
337
 */
 
338
typedef struct TupleHashEntryData *TupleHashEntry;
 
339
typedef struct TupleHashTableData *TupleHashTable;
 
340
 
 
341
typedef struct TupleHashEntryData
 
342
{
 
343
        /* firstTuple must be the first field in this struct! */
 
344
        HeapTuple       firstTuple;             /* copy of first tuple in this group */
 
345
        /* there may be additional data beyond the end of this struct */
 
346
} TupleHashEntryData;                   /* VARIABLE LENGTH STRUCT */
 
347
 
 
348
typedef struct TupleHashTableData
 
349
{
 
350
        HTAB       *hashtab;            /* underlying dynahash table */
 
351
        int                     numCols;                /* number of columns in lookup key */
 
352
        AttrNumber *keyColIdx;          /* attr numbers of key columns */
 
353
        FmgrInfo   *eqfunctions;        /* lookup data for comparison functions */
 
354
        FmgrInfo   *hashfunctions;      /* lookup data for hash functions */
 
355
        MemoryContext tablecxt;         /* memory context containing table */
 
356
        MemoryContext tempcxt;          /* context for function evaluations */
 
357
        Size            entrysize;              /* actual size to make each hash entry */
 
358
        TupleDesc       tupdesc;                /* tuple descriptor */
 
359
} TupleHashTableData;
 
360
 
 
361
typedef HASH_SEQ_STATUS TupleHashIterator;
 
362
 
 
363
#define ResetTupleHashIterator(htable, iter) \
 
364
        hash_seq_init(iter, (htable)->hashtab)
 
365
#define ScanTupleHashTable(iter) \
 
366
        ((TupleHashEntry) hash_seq_search(iter))
 
367
 
 
368
 
 
369
/* ----------------------------------------------------------------
 
370
 *                               Expression State Trees
 
371
 *
 
372
 * Each executable expression tree has a parallel ExprState tree.
 
373
 *
 
374
 * Unlike PlanState, there is not an exact one-for-one correspondence between
 
375
 * ExprState node types and Expr node types.  Many Expr node types have no
 
376
 * need for node-type-specific run-time state, and so they can use plain
 
377
 * ExprState or GenericExprState as their associated ExprState node type.
 
378
 * ----------------------------------------------------------------
 
379
 */
 
380
 
 
381
/* ----------------
 
382
 *              ExprState node
 
383
 *
 
384
 * ExprState is the common superclass for all ExprState-type nodes.
 
385
 *
 
386
 * It can also be instantiated directly for leaf Expr nodes that need no
 
387
 * local run-time state (such as Var, Const, or Param).
 
388
 *
 
389
 * To save on dispatch overhead, each ExprState node contains a function
 
390
 * pointer to the routine to execute to evaluate the node.
 
391
 * ----------------
 
392
 */
 
393
 
 
394
typedef struct ExprState ExprState;
 
395
 
 
396
typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
 
397
                                                                                                ExprContext *econtext,
 
398
                                                                                                bool *isNull,
 
399
                                                                                                ExprDoneCond *isDone);
 
400
 
 
401
struct ExprState
 
402
{
 
403
        NodeTag         type;
 
404
        Expr       *expr;                       /* associated Expr node */
 
405
        ExprStateEvalFunc evalfunc; /* routine to run to execute node */
 
406
};
 
407
 
 
408
/* ----------------
 
409
 *              GenericExprState node
 
410
 *
 
411
 * This is used for Expr node types that need no local run-time state,
 
412
 * but have one child Expr node.
 
413
 * ----------------
 
414
 */
 
415
typedef struct GenericExprState
 
416
{
 
417
        ExprState       xprstate;
 
418
        ExprState  *arg;                        /* state of my child node */
 
419
} GenericExprState;
 
420
 
 
421
/* ----------------
 
422
 *              AggrefExprState node
 
423
 * ----------------
 
424
 */
 
425
typedef struct AggrefExprState
 
426
{
 
427
        ExprState       xprstate;
 
428
        ExprState  *target;                     /* state of my child node */
 
429
        int                     aggno;                  /* ID number for agg within its plan node */
 
430
} AggrefExprState;
 
431
 
 
432
/* ----------------
 
433
 *              ArrayRefExprState node
 
434
 *
 
435
 * Note: array types can be fixed-length (typlen > 0), but only when the
 
436
 * element type is itself fixed-length.  Otherwise they are varlena structures
 
437
 * and have typlen = -1.  In any case, an array type is never pass-by-value.
 
438
 * ----------------
 
439
 */
 
440
typedef struct ArrayRefExprState
 
441
{
 
442
        ExprState       xprstate;
 
443
        List       *refupperindexpr;    /* states for child nodes */
 
444
        List       *reflowerindexpr;
 
445
        ExprState  *refexpr;
 
446
        ExprState  *refassgnexpr;
 
447
        int16           refattrlength;  /* typlen of array type */
 
448
        int16           refelemlength;  /* typlen of the array element type */
 
449
        bool            refelembyval;   /* is the element type pass-by-value? */
 
450
        char            refelemalign;   /* typalign of the element type */
 
451
} ArrayRefExprState;
 
452
 
 
453
/* ----------------
 
454
 *              FuncExprState node
 
455
 *
 
456
 * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
 
457
 * and NullIf nodes; be careful to check what xprstate.expr is actually
 
458
 * pointing at!
 
459
 * ----------------
 
460
 */
 
461
typedef struct FuncExprState
 
462
{
 
463
        ExprState       xprstate;
 
464
        List       *args;                       /* states of argument expressions */
 
465
 
 
466
        /*
 
467
         * Function manager's lookup info for the target function.  If
 
468
         * func.fn_oid is InvalidOid, we haven't initialized it yet.
 
469
         */
 
470
        FmgrInfo        func;
 
471
 
 
472
        /*
 
473
         * We also need to store argument values across calls when evaluating
 
474
         * a function-returning-set.
 
475
         *
 
476
         * setArgsValid is true when we are evaluating a set-valued function and
 
477
         * we are in the middle of a call series; we want to pass the same
 
478
         * argument values to the function again (and again, until it returns
 
479
         * ExprEndResult).
 
480
         */
 
481
        bool            setArgsValid;
 
482
 
 
483
        /*
 
484
         * Flag to remember whether we found a set-valued argument to the
 
485
         * function. This causes the function result to be a set as well.
 
486
         * Valid only when setArgsValid is true.
 
487
         */
 
488
        bool            setHasSetArg;   /* some argument returns a set */
 
489
 
 
490
        /*
 
491
         * Flag to remember whether we have registered a shutdown callback for
 
492
         * this FuncExprState.  We do so only if setArgsValid has been true at
 
493
         * least once (since all the callback is for is to clear
 
494
         * setArgsValid).
 
495
         */
 
496
        bool            shutdown_reg;   /* a shutdown callback is registered */
 
497
 
 
498
        /*
 
499
         * Current argument data for a set-valued function; contains valid
 
500
         * data only if setArgsValid is true.
 
501
         */
 
502
        FunctionCallInfoData setArgs;
 
503
} FuncExprState;
 
504
 
 
505
/* ----------------
 
506
 *              ScalarArrayOpExprState node
 
507
 *
 
508
 * This is a FuncExprState plus some additional data.
 
509
 * ----------------
 
510
 */
 
511
typedef struct ScalarArrayOpExprState
 
512
{
 
513
        FuncExprState fxprstate;
 
514
        /* Cached info about array element type */
 
515
        Oid                     element_type;
 
516
        int16           typlen;
 
517
        bool            typbyval;
 
518
        char            typalign;
 
519
} ScalarArrayOpExprState;
 
520
 
 
521
/* ----------------
 
522
 *              BoolExprState node
 
523
 * ----------------
 
524
 */
 
525
typedef struct BoolExprState
 
526
{
 
527
        ExprState       xprstate;
 
528
        List       *args;                       /* states of argument expression(s) */
 
529
} BoolExprState;
 
530
 
 
531
/* ----------------
 
532
 *              SubPlanState node
 
533
 * ----------------
 
534
 */
 
535
typedef struct SubPlanState
 
536
{
 
537
        ExprState       xprstate;
 
538
        EState     *sub_estate;         /* subselect plan has its own EState */
 
539
        struct PlanState *planstate;    /* subselect plan's state tree */
 
540
        List       *exprs;                      /* states of combining expression(s) */
 
541
        List       *args;                       /* states of argument expression(s) */
 
542
        bool            needShutdown;   /* TRUE = need to shutdown subplan */
 
543
        HeapTuple       curTuple;               /* copy of most recent tuple from subplan */
 
544
        /* these are used when hashing the subselect's output: */
 
545
        ProjectionInfo *projLeft;       /* for projecting lefthand exprs */
 
546
        ProjectionInfo *projRight;      /* for projecting subselect output */
 
547
        TupleHashTable hashtable;       /* hash table for no-nulls subselect rows */
 
548
        TupleHashTable hashnulls;       /* hash table for rows with null(s) */
 
549
        bool            havehashrows;   /* TRUE if hashtable is not empty */
 
550
        bool            havenullrows;   /* TRUE if hashnulls is not empty */
 
551
        MemoryContext tablecxt;         /* memory context containing tables */
 
552
        ExprContext *innerecontext; /* working context for comparisons */
 
553
        AttrNumber *keyColIdx;          /* control data for hash tables */
 
554
        FmgrInfo   *eqfunctions;        /* comparison functions for hash tables */
 
555
        FmgrInfo   *hashfunctions;      /* lookup data for hash functions */
 
556
} SubPlanState;
 
557
 
 
558
/* ----------------
 
559
 *              FieldSelectState node
 
560
 * ----------------
 
561
 */
 
562
typedef struct FieldSelectState
 
563
{
 
564
        ExprState       xprstate;
 
565
        ExprState  *arg;                        /* input expression */
 
566
        TupleDesc       argdesc;                /* tupdesc for most recent input */
 
567
} FieldSelectState;
 
568
 
 
569
/* ----------------
 
570
 *              FieldStoreState node
 
571
 * ----------------
 
572
 */
 
573
typedef struct FieldStoreState
 
574
{
 
575
        ExprState       xprstate;
 
576
        ExprState  *arg;                        /* input tuple value */
 
577
        List       *newvals;            /* new value(s) for field(s) */
 
578
        TupleDesc       argdesc;                /* tupdesc for most recent input */
 
579
} FieldStoreState;
 
580
 
 
581
/* ----------------
 
582
 *              ConvertRowtypeExprState node
 
583
 * ----------------
 
584
 */
 
585
typedef struct ConvertRowtypeExprState
 
586
{
 
587
        ExprState       xprstate;
 
588
        ExprState  *arg;                        /* input tuple value */
 
589
        TupleDesc       indesc;                 /* tupdesc for source rowtype */
 
590
        TupleDesc       outdesc;                /* tupdesc for result rowtype */
 
591
        AttrNumber *attrMap;            /* indexes of input fields, or 0 for null */
 
592
        Datum      *invalues;           /* workspace for deconstructing source */
 
593
        char       *innulls;
 
594
        Datum      *outvalues;          /* workspace for constructing result */
 
595
        char       *outnulls;
 
596
} ConvertRowtypeExprState;
 
597
 
 
598
/* ----------------
 
599
 *              CaseExprState node
 
600
 * ----------------
 
601
 */
 
602
typedef struct CaseExprState
 
603
{
 
604
        ExprState       xprstate;
 
605
        ExprState  *arg;                        /* implicit equality comparison argument */
 
606
        List       *args;                       /* the arguments (list of WHEN clauses) */
 
607
        ExprState  *defresult;          /* the default result (ELSE clause) */
 
608
} CaseExprState;
 
609
 
 
610
/* ----------------
 
611
 *              CaseWhenState node
 
612
 * ----------------
 
613
 */
 
614
typedef struct CaseWhenState
 
615
{
 
616
        ExprState       xprstate;
 
617
        ExprState  *expr;                       /* condition expression */
 
618
        ExprState  *result;                     /* substitution result */
 
619
} CaseWhenState;
 
620
 
 
621
/* ----------------
 
622
 *              ArrayExprState node
 
623
 *
 
624
 * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
 
625
 * arrays.
 
626
 * ----------------
 
627
 */
 
628
typedef struct ArrayExprState
 
629
{
 
630
        ExprState       xprstate;
 
631
        List       *elements;           /* states for child nodes */
 
632
        int16           elemlength;             /* typlen of the array element type */
 
633
        bool            elembyval;              /* is the element type pass-by-value? */
 
634
        char            elemalign;              /* typalign of the element type */
 
635
} ArrayExprState;
 
636
 
 
637
/* ----------------
 
638
 *              RowExprState node
 
639
 * ----------------
 
640
 */
 
641
typedef struct RowExprState
 
642
{
 
643
        ExprState       xprstate;
 
644
        List       *args;                       /* the arguments */
 
645
        TupleDesc       tupdesc;                /* descriptor for result tuples */
 
646
} RowExprState;
 
647
 
 
648
/* ----------------
 
649
 *              CoalesceExprState node
 
650
 * ----------------
 
651
 */
 
652
typedef struct CoalesceExprState
 
653
{
 
654
        ExprState       xprstate;
 
655
        List       *args;                       /* the arguments */
 
656
} CoalesceExprState;
 
657
 
 
658
/* ----------------
 
659
 *              CoerceToDomainState node
 
660
 * ----------------
 
661
 */
 
662
typedef struct CoerceToDomainState
 
663
{
 
664
        ExprState       xprstate;
 
665
        ExprState  *arg;                        /* input expression */
 
666
        /* Cached list of constraints that need to be checked */
 
667
        List       *constraints;        /* list of DomainConstraintState nodes */
 
668
} CoerceToDomainState;
 
669
 
 
670
/*
 
671
 * DomainConstraintState - one item to check during CoerceToDomain
 
672
 *
 
673
 * Note: this is just a Node, and not an ExprState, because it has no
 
674
 * corresponding Expr to link to.  Nonetheless it is part of an ExprState
 
675
 * tree, so we give it a name following the xxxState convention.
 
676
 */
 
677
typedef enum DomainConstraintType
 
678
{
 
679
        DOM_CONSTRAINT_NOTNULL,
 
680
        DOM_CONSTRAINT_CHECK
 
681
} DomainConstraintType;
 
682
 
 
683
typedef struct DomainConstraintState
 
684
{
 
685
        NodeTag         type;
 
686
        DomainConstraintType constrainttype;            /* constraint type */
 
687
        char       *name;                       /* name of constraint (for error msgs) */
 
688
        ExprState  *check_expr;         /* for CHECK, a boolean expression */
 
689
} DomainConstraintState;
 
690
 
 
691
 
 
692
/* ----------------------------------------------------------------
 
693
 *                               Executor State Trees
 
694
 *
 
695
 * An executing query has a PlanState tree paralleling the Plan tree
 
696
 * that describes the plan.
 
697
 * ----------------------------------------------------------------
 
698
 */
 
699
 
 
700
/* ----------------
 
701
 *              PlanState node
 
702
 *
 
703
 * We never actually instantiate any PlanState nodes; this is just the common
 
704
 * abstract superclass for all PlanState-type nodes.
 
705
 * ----------------
 
706
 */
 
707
typedef struct PlanState
 
708
{
 
709
        NodeTag         type;
 
710
 
 
711
        Plan       *plan;                       /* associated Plan node */
 
712
 
 
713
        EState     *state;                      /* at execution time, state's of
 
714
                                                                 * individual nodes point to one EState
 
715
                                                                 * for the whole top-level plan */
 
716
 
 
717
        struct Instrumentation *instrument; /* Optional runtime stats for this
 
718
                                                                                 * plan node */
 
719
 
 
720
        /*
 
721
         * Common structural data for all Plan types.  These links to
 
722
         * subsidiary state trees parallel links in the associated plan tree
 
723
         * (except for the subPlan list, which does not exist in the plan
 
724
         * tree).
 
725
         */
 
726
        List       *targetlist;         /* target list to be computed at this node */
 
727
        List       *qual;                       /* implicitly-ANDed qual conditions */
 
728
        struct PlanState *lefttree; /* input plan tree(s) */
 
729
        struct PlanState *righttree;
 
730
        List       *initPlan;           /* Init SubPlanState nodes (un-correlated
 
731
                                                                 * expr subselects) */
 
732
        List       *subPlan;            /* SubPlanState nodes in my expressions */
 
733
 
 
734
        /*
 
735
         * State for management of parameter-change-driven rescanning
 
736
         */
 
737
        Bitmapset  *chgParam;           /* set of IDs of changed Params */
 
738
 
 
739
        /*
 
740
         * Other run-time state needed by most if not all node types.
 
741
         */
 
742
        TupleTableSlot *ps_OuterTupleSlot;      /* slot for current "outer" tuple */
 
743
        TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
 
744
        ExprContext *ps_ExprContext;    /* node's expression-evaluation context */
 
745
        ProjectionInfo *ps_ProjInfo;    /* info for doing tuple projection */
 
746
        bool            ps_TupFromTlist;/* state flag for processing set-valued
 
747
                                                                 * functions in targetlist */
 
748
} PlanState;
 
749
 
 
750
/* ----------------
 
751
 *      these are are defined to avoid confusion problems with "left"
 
752
 *      and "right" and "inner" and "outer".  The convention is that
 
753
 *      the "left" plan is the "outer" plan and the "right" plan is
 
754
 *      the inner plan, but these make the code more readable.
 
755
 * ----------------
 
756
 */
 
757
#define innerPlanState(node)            (((PlanState *)(node))->righttree)
 
758
#define outerPlanState(node)            (((PlanState *)(node))->lefttree)
 
759
 
 
760
 
 
761
/* ----------------
 
762
 *       ResultState information
 
763
 * ----------------
 
764
 */
 
765
typedef struct ResultState
 
766
{
 
767
        PlanState       ps;                             /* its first field is NodeTag */
 
768
        ExprState  *resconstantqual;
 
769
        bool            rs_done;                /* are we done? */
 
770
        bool            rs_checkqual;   /* do we need to check the qual? */
 
771
} ResultState;
 
772
 
 
773
/* ----------------
 
774
 *       AppendState information
 
775
 *
 
776
 *              nplans                  how many plans are in the list
 
777
 *              whichplan               which plan is being executed (0 .. n-1)
 
778
 *              firstplan               first plan to execute (usually 0)
 
779
 *              lastplan                last plan to execute (usually n-1)
 
780
 * ----------------
 
781
 */
 
782
typedef struct AppendState
 
783
{
 
784
        PlanState       ps;                             /* its first field is NodeTag */
 
785
        PlanState **appendplans;        /* array of PlanStates for my inputs */
 
786
        int                     as_nplans;
 
787
        int                     as_whichplan;
 
788
        int                     as_firstplan;
 
789
        int                     as_lastplan;
 
790
} AppendState;
 
791
 
 
792
/* ----------------------------------------------------------------
 
793
 *                               Scan State Information
 
794
 * ----------------------------------------------------------------
 
795
 */
 
796
 
 
797
/* ----------------
 
798
 *       ScanState information
 
799
 *
 
800
 *              ScanState extends PlanState for node types that represent
 
801
 *              scans of an underlying relation.  It can also be used for nodes
 
802
 *              that scan the output of an underlying plan node --- in that case,
 
803
 *              only ScanTupleSlot is actually useful, and it refers to the tuple
 
804
 *              retrieved from the subplan.
 
805
 *
 
806
 *              currentRelation    relation being scanned (NULL if none)
 
807
 *              currentScanDesc    current scan descriptor for scan (NULL if none)
 
808
 *              ScanTupleSlot      pointer to slot in tuple table holding scan tuple
 
809
 * ----------------
 
810
 */
 
811
typedef struct ScanState
 
812
{
 
813
        PlanState       ps;                             /* its first field is NodeTag */
 
814
        Relation        ss_currentRelation;
 
815
        HeapScanDesc ss_currentScanDesc;
 
816
        TupleTableSlot *ss_ScanTupleSlot;
 
817
} ScanState;
 
818
 
 
819
/*
 
820
 * SeqScan uses a bare ScanState as its state node, since it needs
 
821
 * no additional fields.
 
822
 */
 
823
typedef ScanState SeqScanState;
 
824
 
 
825
/* ----------------
 
826
 *       IndexScanState information
 
827
 *
 
828
 *              indxqualorig       execution state for indxqualorig expressions
 
829
 *              NumIndices                 number of indices in this scan
 
830
 *              IndexPtr                   current index in use
 
831
 *              MarkIndexPtr       IndexPtr for marked scan point
 
832
 *              ScanKeys                   Skey structures to scan index rels
 
833
 *              NumScanKeys                array of no of keys in each Skey struct
 
834
 *              RuntimeKeyInfo     array of array of exprstates for Skeys
 
835
 *                                                 that will be evaluated at runtime
 
836
 *              RuntimeContext     expr context for evaling runtime Skeys
 
837
 *              RuntimeKeysReady   true if runtime Skeys have been computed
 
838
 *              RelationDescs      ptr to array of relation descriptors
 
839
 *              ScanDescs                  ptr to array of scan descriptors
 
840
 *              LossyQuals                 ptr to array of qual lists for lossy operators
 
841
 *              DupHash                    hashtable for recognizing dups in multiple scan
 
842
 *              MaxHash                    max # entries we will allow in hashtable
 
843
 * ----------------
 
844
 */
 
845
typedef struct IndexScanState
 
846
{
 
847
        ScanState       ss;                             /* its first field is NodeTag */
 
848
        List       *indxqualorig;
 
849
        int                     iss_NumIndices;
 
850
        int                     iss_IndexPtr;
 
851
        int                     iss_MarkIndexPtr;
 
852
        ScanKey    *iss_ScanKeys;
 
853
        int                *iss_NumScanKeys;
 
854
        ExprState ***iss_RuntimeKeyInfo;
 
855
        ExprContext *iss_RuntimeContext;
 
856
        bool            iss_RuntimeKeysReady;
 
857
        RelationPtr iss_RelationDescs;
 
858
        IndexScanDescPtr iss_ScanDescs;
 
859
        List      **iss_LossyQuals;
 
860
        HTAB       *iss_DupHash;
 
861
        long            iss_MaxHash;
 
862
} IndexScanState;
 
863
 
 
864
/* ----------------
 
865
 *       TidScanState information
 
866
 *
 
867
 *              NumTids            number of tids in this scan
 
868
 *              TidPtr             current tid in use
 
869
 *              TidList            evaluated item pointers
 
870
 * ----------------
 
871
 */
 
872
typedef struct TidScanState
 
873
{
 
874
        ScanState       ss;                             /* its first field is NodeTag */
 
875
        List       *tss_tideval;        /* list of ExprState nodes */
 
876
        int                     tss_NumTids;
 
877
        int                     tss_TidPtr;
 
878
        int                     tss_MarkTidPtr;
 
879
        ItemPointerData *tss_TidList;
 
880
        HeapTupleData tss_htup;
 
881
} TidScanState;
 
882
 
 
883
/* ----------------
 
884
 *       SubqueryScanState information
 
885
 *
 
886
 *              SubqueryScanState is used for scanning a sub-query in the range table.
 
887
 *              The sub-query will have its own EState, which we save here.
 
888
 *              ScanTupleSlot references the current output tuple of the sub-query.
 
889
 *
 
890
 *              SubEState                  exec state for sub-query
 
891
 * ----------------
 
892
 */
 
893
typedef struct SubqueryScanState
 
894
{
 
895
        ScanState       ss;                             /* its first field is NodeTag */
 
896
        PlanState  *subplan;
 
897
        EState     *sss_SubEState;
 
898
} SubqueryScanState;
 
899
 
 
900
/* ----------------
 
901
 *       FunctionScanState information
 
902
 *
 
903
 *              Function nodes are used to scan the results of a
 
904
 *              function appearing in FROM (typically a function returning set).
 
905
 *
 
906
 *              tupdesc                         expected return tuple description
 
907
 *              tuplestorestate         private state of tuplestore.c
 
908
 *              funcexpr                        state for function expression being evaluated
 
909
 * ----------------
 
910
 */
 
911
typedef struct FunctionScanState
 
912
{
 
913
        ScanState       ss;                             /* its first field is NodeTag */
 
914
        TupleDesc       tupdesc;
 
915
        Tuplestorestate *tuplestorestate;
 
916
        ExprState  *funcexpr;
 
917
} FunctionScanState;
 
918
 
 
919
/* ----------------------------------------------------------------
 
920
 *                               Join State Information
 
921
 * ----------------------------------------------------------------
 
922
 */
 
923
 
 
924
/* ----------------
 
925
 *       JoinState information
 
926
 *
 
927
 *              Superclass for state nodes of join plans.
 
928
 * ----------------
 
929
 */
 
930
typedef struct JoinState
 
931
{
 
932
        PlanState       ps;
 
933
        JoinType        jointype;
 
934
        List       *joinqual;           /* JOIN quals (in addition to ps.qual) */
 
935
} JoinState;
 
936
 
 
937
/* ----------------
 
938
 *       NestLoopState information
 
939
 *
 
940
 *              NeedNewOuter       true if need new outer tuple on next call
 
941
 *              MatchedOuter       true if found a join match for current outer tuple
 
942
 *              NullInnerTupleSlot prepared null tuple for left outer joins
 
943
 * ----------------
 
944
 */
 
945
typedef struct NestLoopState
 
946
{
 
947
        JoinState       js;                             /* its first field is NodeTag */
 
948
        bool            nl_NeedNewOuter;
 
949
        bool            nl_MatchedOuter;
 
950
        TupleTableSlot *nl_NullInnerTupleSlot;
 
951
} NestLoopState;
 
952
 
 
953
/* ----------------
 
954
 *       MergeJoinState information
 
955
 *
 
956
 *              OuterSkipQual      outerKey1 < innerKey1 ...
 
957
 *              InnerSkipQual      outerKey1 > innerKey1 ...
 
958
 *              JoinState                  current "state" of join. see executor.h
 
959
 *              MatchedOuter       true if found a join match for current outer tuple
 
960
 *              MatchedInner       true if found a join match for current inner tuple
 
961
 *              OuterTupleSlot     pointer to slot in tuple table for cur outer tuple
 
962
 *              InnerTupleSlot     pointer to slot in tuple table for cur inner tuple
 
963
 *              MarkedTupleSlot    pointer to slot in tuple table for marked tuple
 
964
 *              NullOuterTupleSlot prepared null tuple for right outer joins
 
965
 *              NullInnerTupleSlot prepared null tuple for left outer joins
 
966
 * ----------------
 
967
 */
 
968
typedef struct MergeJoinState
 
969
{
 
970
        JoinState       js;                             /* its first field is NodeTag */
 
971
        List       *mergeclauses;       /* list of ExprState nodes */
 
972
        List       *mj_OuterSkipQual;           /* list of ExprState nodes */
 
973
        List       *mj_InnerSkipQual;           /* list of ExprState nodes */
 
974
        int                     mj_JoinState;
 
975
        bool            mj_MatchedOuter;
 
976
        bool            mj_MatchedInner;
 
977
        TupleTableSlot *mj_OuterTupleSlot;
 
978
        TupleTableSlot *mj_InnerTupleSlot;
 
979
        TupleTableSlot *mj_MarkedTupleSlot;
 
980
        TupleTableSlot *mj_NullOuterTupleSlot;
 
981
        TupleTableSlot *mj_NullInnerTupleSlot;
 
982
} MergeJoinState;
 
983
 
 
984
/* ----------------
 
985
 *       HashJoinState information
 
986
 *
 
987
 *              hj_HashTable                    hash table for the hashjoin
 
988
 *              hj_CurBucketNo                  bucket# for current outer tuple
 
989
 *              hj_CurTuple                             last inner tuple matched to current outer
 
990
 *                                                              tuple, or NULL if starting search
 
991
 *                                                              (CurBucketNo and CurTuple are meaningless
 
992
 *                                                               unless OuterTupleSlot is nonempty!)
 
993
 *              hj_OuterHashKeys                the outer hash keys in the hashjoin condition
 
994
 *              hj_InnerHashKeys                the inner hash keys in the hashjoin condition
 
995
 *              hj_HashOperators                the join operators in the hashjoin condition
 
996
 *              hj_OuterTupleSlot               tuple slot for outer tuples
 
997
 *              hj_HashTupleSlot                tuple slot for hashed tuples
 
998
 *              hj_NullInnerTupleSlot   prepared null tuple for left outer joins
 
999
 *              hj_NeedNewOuter                 true if need new outer tuple on next call
 
1000
 *              hj_MatchedOuter                 true if found a join match for current outer
 
1001
 *              hj_hashdone                             true if hash-table-build phase is done
 
1002
 * ----------------
 
1003
 */
 
1004
typedef struct HashJoinState
 
1005
{
 
1006
        JoinState       js;                             /* its first field is NodeTag */
 
1007
        List       *hashclauses;        /* list of ExprState nodes */
 
1008
        HashJoinTable hj_HashTable;
 
1009
        int                     hj_CurBucketNo;
 
1010
        HashJoinTuple hj_CurTuple;
 
1011
        List       *hj_OuterHashKeys;           /* list of ExprState nodes */
 
1012
        List       *hj_InnerHashKeys;           /* list of ExprState nodes */
 
1013
        List       *hj_HashOperators;           /* list of operator OIDs */
 
1014
        TupleTableSlot *hj_OuterTupleSlot;
 
1015
        TupleTableSlot *hj_HashTupleSlot;
 
1016
        TupleTableSlot *hj_NullInnerTupleSlot;
 
1017
        bool            hj_NeedNewOuter;
 
1018
        bool            hj_MatchedOuter;
 
1019
        bool            hj_hashdone;
 
1020
} HashJoinState;
 
1021
 
 
1022
 
 
1023
/* ----------------------------------------------------------------
 
1024
 *                               Materialization State Information
 
1025
 * ----------------------------------------------------------------
 
1026
 */
 
1027
 
 
1028
/* ----------------
 
1029
 *       MaterialState information
 
1030
 *
 
1031
 *              materialize nodes are used to materialize the results
 
1032
 *              of a subplan into a temporary file.
 
1033
 *
 
1034
 *              ss.ss_ScanTupleSlot refers to output of underlying plan.
 
1035
 * ----------------
 
1036
 */
 
1037
typedef struct MaterialState
 
1038
{
 
1039
        ScanState       ss;                             /* its first field is NodeTag */
 
1040
        void       *tuplestorestate;    /* private state of tuplestore.c */
 
1041
        bool            eof_underlying; /* reached end of underlying plan? */
 
1042
} MaterialState;
 
1043
 
 
1044
/* ----------------
 
1045
 *       SortState information
 
1046
 * ----------------
 
1047
 */
 
1048
typedef struct SortState
 
1049
{
 
1050
        ScanState       ss;                             /* its first field is NodeTag */
 
1051
        bool            sort_Done;              /* sort completed yet? */
 
1052
        void       *tuplesortstate; /* private state of tuplesort.c */
 
1053
} SortState;
 
1054
 
 
1055
/* ---------------------
 
1056
 *      GroupState information
 
1057
 * -------------------------
 
1058
 */
 
1059
typedef struct GroupState
 
1060
{
 
1061
        ScanState       ss;                             /* its first field is NodeTag */
 
1062
        FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
 
1063
        HeapTuple       grp_firstTuple; /* copy of first tuple of current group */
 
1064
        bool            grp_done;               /* indicates completion of Group scan */
 
1065
} GroupState;
 
1066
 
 
1067
/* ---------------------
 
1068
 *      AggState information
 
1069
 *
 
1070
 *      ss.ss_ScanTupleSlot refers to output of underlying plan.
 
1071
 *
 
1072
 *      Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
 
1073
 *      ecxt_aggnulls arrays, which hold the computed agg values for the current
 
1074
 *      input group during evaluation of an Agg node's output tuple(s).  We
 
1075
 *      create a second ExprContext, tmpcontext, in which to evaluate input
 
1076
 *      expressions and run the aggregate transition functions.
 
1077
 * -------------------------
 
1078
 */
 
1079
/* these structs are private in nodeAgg.c: */
 
1080
typedef struct AggStatePerAggData *AggStatePerAgg;
 
1081
typedef struct AggStatePerGroupData *AggStatePerGroup;
 
1082
 
 
1083
typedef struct AggState
 
1084
{
 
1085
        ScanState       ss;                             /* its first field is NodeTag */
 
1086
        List       *aggs;                       /* all Aggref nodes in targetlist & quals */
 
1087
        int                     numaggs;                /* length of list (could be zero!) */
 
1088
        FmgrInfo   *eqfunctions;        /* per-grouping-field equality fns */
 
1089
        FmgrInfo   *hashfunctions;      /* per-grouping-field hash fns */
 
1090
        AggStatePerAgg peragg;          /* per-Aggref information */
 
1091
        MemoryContext aggcontext;       /* memory context for long-lived data */
 
1092
        ExprContext *tmpcontext;        /* econtext for input expressions */
 
1093
        bool            agg_done;               /* indicates completion of Agg scan */
 
1094
        /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
 
1095
        AggStatePerGroup pergroup;      /* per-Aggref-per-group working state */
 
1096
        HeapTuple       grp_firstTuple; /* copy of first tuple of current group */
 
1097
        /* these fields are used in AGG_HASHED mode: */
 
1098
        TupleHashTable hashtable;       /* hash table with one entry per group */
 
1099
        bool            table_filled;   /* hash table filled yet? */
 
1100
        TupleHashIterator hashiter; /* for iterating through hash table */
 
1101
} AggState;
 
1102
 
 
1103
/* ----------------
 
1104
 *       UniqueState information
 
1105
 *
 
1106
 *              Unique nodes are used "on top of" sort nodes to discard
 
1107
 *              duplicate tuples returned from the sort phase.  Basically
 
1108
 *              all it does is compare the current tuple from the subplan
 
1109
 *              with the previously fetched tuple stored in priorTuple.
 
1110
 *              If the two are identical in all interesting fields, then
 
1111
 *              we just fetch another tuple from the sort and try again.
 
1112
 * ----------------
 
1113
 */
 
1114
typedef struct UniqueState
 
1115
{
 
1116
        PlanState       ps;                             /* its first field is NodeTag */
 
1117
        FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
 
1118
        HeapTuple       priorTuple;             /* most recently returned tuple, or NULL */
 
1119
        MemoryContext tempContext;      /* short-term context for comparisons */
 
1120
} UniqueState;
 
1121
 
 
1122
/* ----------------
 
1123
 *       HashState information
 
1124
 * ----------------
 
1125
 */
 
1126
typedef struct HashState
 
1127
{
 
1128
        PlanState       ps;                             /* its first field is NodeTag */
 
1129
        HashJoinTable hashtable;        /* hash table for the hashjoin */
 
1130
        List       *hashkeys;           /* list of ExprState nodes */
 
1131
        /* hashkeys is same as parent's hj_InnerHashKeys */
 
1132
} HashState;
 
1133
 
 
1134
/* ----------------
 
1135
 *       SetOpState information
 
1136
 *
 
1137
 *              SetOp nodes are used "on top of" sort nodes to discard
 
1138
 *              duplicate tuples returned from the sort phase.  These are
 
1139
 *              more complex than a simple Unique since we have to count
 
1140
 *              how many duplicates to return.
 
1141
 * ----------------
 
1142
 */
 
1143
typedef struct SetOpState
 
1144
{
 
1145
        PlanState       ps;                             /* its first field is NodeTag */
 
1146
        FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
 
1147
        bool            subplan_done;   /* has subplan returned EOF? */
 
1148
        long            numLeft;                /* number of left-input dups of cur group */
 
1149
        long            numRight;               /* number of right-input dups of cur group */
 
1150
        long            numOutput;              /* number of dups left to output */
 
1151
        MemoryContext tempContext;      /* short-term context for comparisons */
 
1152
} SetOpState;
 
1153
 
 
1154
/* ----------------
 
1155
 *       LimitState information
 
1156
 *
 
1157
 *              Limit nodes are used to enforce LIMIT/OFFSET clauses.
 
1158
 *              They just select the desired subrange of their subplan's output.
 
1159
 *
 
1160
 * offset is the number of initial tuples to skip (0 does nothing).
 
1161
 * count is the number of tuples to return after skipping the offset tuples.
 
1162
 * If no limit count was specified, count is undefined and noCount is true.
 
1163
 * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
 
1164
 * ----------------
 
1165
 */
 
1166
typedef enum
 
1167
{
 
1168
        LIMIT_INITIAL,                          /* initial state for LIMIT node */
 
1169
        LIMIT_EMPTY,                            /* there are no returnable rows */
 
1170
        LIMIT_INWINDOW,                         /* have returned a row in the window */
 
1171
        LIMIT_SUBPLANEOF,                       /* at EOF of subplan (within window) */
 
1172
        LIMIT_WINDOWEND,                        /* stepped off end of window */
 
1173
        LIMIT_WINDOWSTART                       /* stepped off beginning of window */
 
1174
} LimitStateCond;
 
1175
 
 
1176
typedef struct LimitState
 
1177
{
 
1178
        PlanState       ps;                             /* its first field is NodeTag */
 
1179
        ExprState  *limitOffset;        /* OFFSET parameter, or NULL if none */
 
1180
        ExprState  *limitCount;         /* COUNT parameter, or NULL if none */
 
1181
        long            offset;                 /* current OFFSET value */
 
1182
        long            count;                  /* current COUNT, if any */
 
1183
        bool            noCount;                /* if true, ignore count */
 
1184
        LimitStateCond lstate;          /* state machine status, as above */
 
1185
        long            position;               /* 1-based index of last tuple returned */
 
1186
        TupleTableSlot *subSlot;        /* tuple last obtained from subplan */
 
1187
} LimitState;
 
1188
 
 
1189
#endif   /* EXECNODES_H */