Eneboo - Documentación para desarrolladores
src/libpq/include/nodes/execnodes.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * execnodes.h
00004  *        definitions for executor state nodes
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.139.2.3 2005/11/28 23:46:25 tgl Exp $
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef EXECNODES_H
00015 #define EXECNODES_H
00016 
00017 #include "access/relscan.h"
00018 #include "executor/tuptable.h"
00019 #include "fmgr.h"
00020 #include "nodes/bitmapset.h"
00021 #include "nodes/params.h"
00022 #include "nodes/plannodes.h"
00023 #include "nodes/tidbitmap.h"
00024 #include "utils/hsearch.h"
00025 #include "utils/tuplestore.h"
00026 
00027 
00028 /* ----------------
00029  *        IndexInfo information
00030  *
00031  *              this struct holds the information needed to construct new index
00032  *              entries for a particular index.  Used for both index_build and
00033  *              retail creation of index entries.
00034  *
00035  *              NumIndexAttrs           number of columns in this index
00036  *              KeyAttrNumbers          underlying-rel attribute numbers used as keys
00037  *                                                      (zeroes indicate expressions)
00038  *              Expressions                     expr trees for expression entries, or NIL if none
00039  *              ExpressionsState        exec state for expressions, or NIL if none
00040  *              Predicate                       partial-index predicate, or NIL if none
00041  *              PredicateState          exec state for predicate, or NIL if none
00042  *              Unique                          is it a unique index?
00043  * ----------------
00044  */
00045 typedef struct IndexInfo
00046 {
00047         NodeTag         type;
00048         int                     ii_NumIndexAttrs;
00049         AttrNumber      ii_KeyAttrNumbers[INDEX_MAX_KEYS];
00050         List       *ii_Expressions; /* list of Expr */
00051         List       *ii_ExpressionsState;        /* list of ExprState */
00052         List       *ii_Predicate;       /* list of Expr */
00053         List       *ii_PredicateState;          /* list of ExprState */
00054         bool            ii_Unique;
00055 } IndexInfo;
00056 
00057 /* ----------------
00058  *        ExprContext_CB
00059  *
00060  *              List of callbacks to be called at ExprContext shutdown.
00061  * ----------------
00062  */
00063 typedef void (*ExprContextCallbackFunction) (Datum arg);
00064 
00065 typedef struct ExprContext_CB
00066 {
00067         struct ExprContext_CB *next;
00068         ExprContextCallbackFunction function;
00069         Datum           arg;
00070 } ExprContext_CB;
00071 
00072 /* ----------------
00073  *        ExprContext
00074  *
00075  *              This class holds the "current context" information
00076  *              needed to evaluate expressions for doing tuple qualifications
00077  *              and tuple projections.  For example, if an expression refers
00078  *              to an attribute in the current inner tuple then we need to know
00079  *              what the current inner tuple is and so we look at the expression
00080  *              context.
00081  *
00082  *      There are two memory contexts associated with an ExprContext:
00083  *      * ecxt_per_query_memory is a query-lifespan context, typically the same
00084  *        context the ExprContext node itself is allocated in.  This context
00085  *        can be used for purposes such as storing function call cache info.
00086  *      * ecxt_per_tuple_memory is a short-term context for expression results.
00087  *        As the name suggests, it will typically be reset once per tuple,
00088  *        before we begin to evaluate expressions for that tuple.  Each
00089  *        ExprContext normally has its very own per-tuple memory context.
00090  *
00091  *      CurrentMemoryContext should be set to ecxt_per_tuple_memory before
00092  *      calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
00093  * ----------------
00094  */
00095 typedef struct ExprContext
00096 {
00097         NodeTag         type;
00098 
00099         /* Tuples that Var nodes in expression may refer to */
00100         TupleTableSlot *ecxt_scantuple;
00101         TupleTableSlot *ecxt_innertuple;
00102         TupleTableSlot *ecxt_outertuple;
00103 
00104         /* Memory contexts for expression evaluation --- see notes above */
00105         MemoryContext ecxt_per_query_memory;
00106         MemoryContext ecxt_per_tuple_memory;
00107 
00108         /* Values to substitute for Param nodes in expression */
00109         ParamExecData *ecxt_param_exec_vals;            /* for PARAM_EXEC params */
00110         ParamListInfo ecxt_param_list_info; /* for other param types */
00111 
00112         /* Values to substitute for Aggref nodes in expression */
00113         Datum      *ecxt_aggvalues; /* precomputed values for Aggref nodes */
00114         bool       *ecxt_aggnulls;      /* null flags for Aggref nodes */
00115 
00116         /* Value to substitute for CaseTestExpr nodes in expression */
00117         Datum           caseValue_datum;
00118         bool            caseValue_isNull;
00119 
00120         /* Value to substitute for CoerceToDomainValue nodes in expression */
00121         Datum           domainValue_datum;
00122         bool            domainValue_isNull;
00123 
00124         /* Link to containing EState */
00125         struct EState *ecxt_estate;
00126 
00127         /* Functions to call back when ExprContext is shut down */
00128         ExprContext_CB *ecxt_callbacks;
00129 } ExprContext;
00130 
00131 /*
00132  * Set-result status returned by ExecEvalExpr()
00133  */
00134 typedef enum
00135 {
00136         ExprSingleResult,                       /* expression does not return a set */
00137         ExprMultipleResult,                     /* this result is an element of a set */
00138         ExprEndResult                           /* there are no more elements in the set */
00139 } ExprDoneCond;
00140 
00141 /*
00142  * Return modes for functions returning sets.  Note values must be chosen
00143  * as separate bits so that a bitmask can be formed to indicate supported
00144  * modes.
00145  */
00146 typedef enum
00147 {
00148         SFRM_ValuePerCall = 0x01,       /* one value returned per call */
00149         SFRM_Materialize = 0x02         /* result set instantiated in Tuplestore */
00150 } SetFunctionReturnMode;
00151 
00152 /*
00153  * When calling a function that might return a set (multiple rows),
00154  * a node of this type is passed as fcinfo->resultinfo to allow
00155  * return status to be passed back.  A function returning set should
00156  * raise an error if no such resultinfo is provided.
00157  */
00158 typedef struct ReturnSetInfo
00159 {
00160         NodeTag         type;
00161         /* values set by caller: */
00162         ExprContext *econtext;          /* context function is being called in */
00163         TupleDesc       expectedDesc;   /* tuple descriptor expected by caller */
00164         int                     allowedModes;   /* bitmask: return modes caller can handle */
00165         /* result status from function (but pre-initialized by caller): */
00166         SetFunctionReturnMode returnMode;       /* actual return mode */
00167         ExprDoneCond isDone;            /* status for ValuePerCall mode */
00168         /* fields filled by function in Materialize return mode: */
00169         Tuplestorestate *setResult; /* holds the complete returned tuple set */
00170         TupleDesc       setDesc;                /* actual descriptor for returned tuples */
00171 } ReturnSetInfo;
00172 
00173 /* ----------------
00174  *              ProjectionInfo node information
00175  *
00176  *              This is all the information needed to perform projections ---
00177  *              that is, form new tuples by evaluation of targetlist expressions.
00178  *              Nodes which need to do projections create one of these.
00179  *
00180  *              ExecProject() evaluates the tlist, forms a tuple, and stores it
00181  *              in the given slot.      Note that the result will be a "virtual" tuple
00182  *              unless ExecMaterializeSlot() is then called to force it to be
00183  *              converted to a physical tuple.  The slot must have a tupledesc
00184  *              that matches the output of the tlist!
00185  *
00186  *              The planner very often produces tlists that consist entirely of
00187  *              simple Var references (lower levels of a plan tree almost always
00188  *              look like that).  So we have an optimization to handle that case
00189  *              with minimum overhead.
00190  *
00191  *              targetlist              target list for projection
00192  *              exprContext             expression context in which to evaluate targetlist
00193  *              slot                    slot to place projection result in
00194  *              itemIsDone              workspace for ExecProject
00195  *              isVarList               TRUE if simple-Var-list optimization applies
00196  *              varSlotOffsets  array indicating which slot each simple Var is from
00197  *              varNumbers              array indicating attr numbers of simple Vars
00198  *              lastInnerVar    highest attnum from inner tuple slot (0 if none)
00199  *              lastOuterVar    highest attnum from outer tuple slot (0 if none)
00200  *              lastScanVar             highest attnum from scan tuple slot (0 if none)
00201  * ----------------
00202  */
00203 typedef struct ProjectionInfo
00204 {
00205         NodeTag         type;
00206         List       *pi_targetlist;
00207         ExprContext *pi_exprContext;
00208         TupleTableSlot *pi_slot;
00209         ExprDoneCond *pi_itemIsDone;
00210         bool            pi_isVarList;
00211         int                *pi_varSlotOffsets;
00212         int                *pi_varNumbers;
00213         int                     pi_lastInnerVar;
00214         int                     pi_lastOuterVar;
00215         int                     pi_lastScanVar;
00216 } ProjectionInfo;
00217 
00218 /* ----------------
00219  *        JunkFilter
00220  *
00221  *        This class is used to store information regarding junk attributes.
00222  *        A junk attribute is an attribute in a tuple that is needed only for
00223  *        storing intermediate information in the executor, and does not belong
00224  *        in emitted tuples.  For example, when we do an UPDATE query,
00225  *        the planner adds a "junk" entry to the targetlist so that the tuples
00226  *        returned to ExecutePlan() contain an extra attribute: the ctid of
00227  *        the tuple to be updated.      This is needed to do the update, but we
00228  *        don't want the ctid to be part of the stored new tuple!  So, we
00229  *        apply a "junk filter" to remove the junk attributes and form the
00230  *        real output tuple.
00231  *
00232  *        targetList:           the original target list (including junk attributes).
00233  *        cleanTupType:         the tuple descriptor for the "clean" tuple (with
00234  *                                              junk attributes removed).
00235  *        cleanMap:                     A map with the correspondence between the non-junk
00236  *                                              attribute numbers of the "original" tuple and the
00237  *                                              attribute numbers of the "clean" tuple.
00238  *        resultSlot:           tuple slot used to hold cleaned tuple.
00239  * ----------------
00240  */
00241 typedef struct JunkFilter
00242 {
00243         NodeTag         type;
00244         List       *jf_targetList;
00245         TupleDesc       jf_cleanTupType;
00246         AttrNumber *jf_cleanMap;
00247         TupleTableSlot *jf_resultSlot;
00248 } JunkFilter;
00249 
00250 /* ----------------
00251  *        ResultRelInfo information
00252  *
00253  *              Whenever we update an existing relation, we have to
00254  *              update indices on the relation, and perhaps also fire triggers.
00255  *              The ResultRelInfo class is used to hold all the information needed
00256  *              about a result relation, including indices.. -cim 10/15/89
00257  *
00258  *              RangeTableIndex                 result relation's range table index
00259  *              RelationDesc                    relation descriptor for result relation
00260  *              NumIndices                              # of indices existing on result relation
00261  *              IndexRelationDescs              array of relation descriptors for indices
00262  *              IndexRelationInfo               array of key/attr info for indices
00263  *              TrigDesc                                triggers to be fired, if any
00264  *              TrigFunctions                   cached lookup info for trigger functions
00265  *              TrigInstrument                  optional runtime measurements for triggers
00266  *              ConstraintExprs                 array of constraint-checking expr states
00267  *              junkFilter                              for removing junk attributes from tuples
00268  * ----------------
00269  */
00270 typedef struct ResultRelInfo
00271 {
00272         NodeTag         type;
00273         Index           ri_RangeTableIndex;
00274         Relation        ri_RelationDesc;
00275         int                     ri_NumIndices;
00276         RelationPtr ri_IndexRelationDescs;
00277         IndexInfo **ri_IndexRelationInfo;
00278         TriggerDesc *ri_TrigDesc;
00279         FmgrInfo   *ri_TrigFunctions;
00280         struct Instrumentation *ri_TrigInstrument;
00281         List      **ri_ConstraintExprs;
00282         JunkFilter *ri_junkFilter;
00283 } ResultRelInfo;
00284 
00285 /* ----------------
00286  *        EState information
00287  *
00288  * Master working state for an Executor invocation
00289  * ----------------
00290  */
00291 typedef struct EState
00292 {
00293         NodeTag         type;
00294 
00295         /* Basic state for all query types: */
00296         ScanDirection es_direction; /* current scan direction */
00297         Snapshot        es_snapshot;    /* time qual to use */
00298         Snapshot        es_crosscheck_snapshot; /* crosscheck time qual for RI */
00299         List       *es_range_table; /* List of RangeTableEntrys */
00300 
00301         /* Info about target table for insert/update/delete queries: */
00302         ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
00303         int                     es_num_result_relations;                /* length of array */
00304         ResultRelInfo *es_result_relation_info;         /* currently active array elt */
00305         JunkFilter *es_junkFilter;      /* currently active junk filter */
00306 
00307         Relation        es_into_relation_descriptor;    /* for SELECT INTO */
00308         bool            es_into_relation_use_wal;
00309 
00310         /* Parameter info: */
00311         ParamListInfo es_param_list_info;       /* values of external params */
00312         ParamExecData *es_param_exec_vals;      /* values of internal params */
00313 
00314         /* Other working state: */
00315         MemoryContext es_query_cxt; /* per-query context in which EState lives */
00316 
00317         TupleTable      es_tupleTable;  /* Array of TupleTableSlots */
00318 
00319         uint32          es_processed;   /* # of tuples processed */
00320         Oid                     es_lastoid;             /* last oid processed (by INSERT) */
00321         List       *es_rowMarks;        /* not good place, but there is no other */
00322         bool            es_forUpdate;   /* true = FOR UPDATE, false = FOR SHARE */
00323         bool            es_rowNoWait;   /* FOR UPDATE/SHARE NOWAIT option */
00324 
00325         bool            es_instrument;  /* true requests runtime instrumentation */
00326         bool            es_select_into; /* true if doing SELECT INTO */
00327         bool            es_into_oids;   /* true to generate OIDs in SELECT INTO */
00328 
00329         List       *es_exprcontexts;    /* List of ExprContexts within EState */
00330 
00331         /*
00332          * this ExprContext is for per-output-tuple operations, such as constraint
00333          * checks and index-value computations.  It will be reset for each output
00334          * tuple.  Note that it will be created only if needed.
00335          */
00336         ExprContext *es_per_tuple_exprcontext;
00337 
00338         /* Below is to re-evaluate plan qual in READ COMMITTED mode */
00339         Plan       *es_topPlan;         /* link to top of plan tree */
00340         struct evalPlanQual *es_evalPlanQual;           /* chain of PlanQual states */
00341         bool       *es_evTupleNull; /* local array of EPQ status */
00342         HeapTuple  *es_evTuple;         /* shared array of EPQ substitute tuples */
00343         bool            es_useEvalPlan; /* evaluating EPQ tuples? */
00344 
00345         /*
00346          * this field added at end of struct to avoid post-release ABI breakage in
00347          * 8.1 series.  It'll be in a more logical place in 8.2.
00348          */
00349         TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
00350 } EState;
00351 
00352 
00353 /* ----------------------------------------------------------------
00354  *                               Tuple Hash Tables
00355  *
00356  * All-in-memory tuple hash tables are used for a number of purposes.
00357  * ----------------------------------------------------------------
00358  */
00359 typedef struct TupleHashEntryData *TupleHashEntry;
00360 typedef struct TupleHashTableData *TupleHashTable;
00361 
00362 typedef struct TupleHashEntryData
00363 {
00364         /* firstTuple must be the first field in this struct! */
00365         HeapTuple       firstTuple;             /* copy of first tuple in this group */
00366         /* there may be additional data beyond the end of this struct */
00367 } TupleHashEntryData;                   /* VARIABLE LENGTH STRUCT */
00368 
00369 typedef struct TupleHashTableData
00370 {
00371         HTAB       *hashtab;            /* underlying dynahash table */
00372         int                     numCols;                /* number of columns in lookup key */
00373         AttrNumber *keyColIdx;          /* attr numbers of key columns */
00374         FmgrInfo   *eqfunctions;        /* lookup data for comparison functions */
00375         FmgrInfo   *hashfunctions;      /* lookup data for hash functions */
00376         MemoryContext tablecxt;         /* memory context containing table */
00377         MemoryContext tempcxt;          /* context for function evaluations */
00378         Size            entrysize;              /* actual size to make each hash entry */
00379         TupleTableSlot *tableslot;      /* slot for referencing table entries */
00380         TupleTableSlot *inputslot;      /* current input tuple's slot */
00381 } TupleHashTableData;
00382 
00383 typedef HASH_SEQ_STATUS TupleHashIterator;
00384 
00385 #define ResetTupleHashIterator(htable, iter) \
00386         hash_seq_init(iter, (htable)->hashtab)
00387 #define ScanTupleHashTable(iter) \
00388         ((TupleHashEntry) hash_seq_search(iter))
00389 
00390 
00391 /* ----------------------------------------------------------------
00392  *                               Expression State Trees
00393  *
00394  * Each executable expression tree has a parallel ExprState tree.
00395  *
00396  * Unlike PlanState, there is not an exact one-for-one correspondence between
00397  * ExprState node types and Expr node types.  Many Expr node types have no
00398  * need for node-type-specific run-time state, and so they can use plain
00399  * ExprState or GenericExprState as their associated ExprState node type.
00400  * ----------------------------------------------------------------
00401  */
00402 
00403 /* ----------------
00404  *              ExprState node
00405  *
00406  * ExprState is the common superclass for all ExprState-type nodes.
00407  *
00408  * It can also be instantiated directly for leaf Expr nodes that need no
00409  * local run-time state (such as Var, Const, or Param).
00410  *
00411  * To save on dispatch overhead, each ExprState node contains a function
00412  * pointer to the routine to execute to evaluate the node.
00413  * ----------------
00414  */
00415 
00416 typedef struct ExprState ExprState;
00417 
00418 typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
00419                                                                                                 ExprContext *econtext,
00420                                                                                                 bool *isNull,
00421                                                                                                 ExprDoneCond *isDone);
00422 
00423 struct ExprState
00424 {
00425         NodeTag         type;
00426         Expr       *expr;                       /* associated Expr node */
00427         ExprStateEvalFunc evalfunc; /* routine to run to execute node */
00428 };
00429 
00430 /* ----------------
00431  *              GenericExprState node
00432  *
00433  * This is used for Expr node types that need no local run-time state,
00434  * but have one child Expr node.
00435  * ----------------
00436  */
00437 typedef struct GenericExprState
00438 {
00439         ExprState       xprstate;
00440         ExprState  *arg;                        /* state of my child node */
00441 } GenericExprState;
00442 
00443 /* ----------------
00444  *              AggrefExprState node
00445  * ----------------
00446  */
00447 typedef struct AggrefExprState
00448 {
00449         ExprState       xprstate;
00450         ExprState  *target;                     /* state of my child node */
00451         int                     aggno;                  /* ID number for agg within its plan node */
00452 } AggrefExprState;
00453 
00454 /* ----------------
00455  *              ArrayRefExprState node
00456  *
00457  * Note: array types can be fixed-length (typlen > 0), but only when the
00458  * element type is itself fixed-length.  Otherwise they are varlena structures
00459  * and have typlen = -1.  In any case, an array type is never pass-by-value.
00460  * ----------------
00461  */
00462 typedef struct ArrayRefExprState
00463 {
00464         ExprState       xprstate;
00465         List       *refupperindexpr;    /* states for child nodes */
00466         List       *reflowerindexpr;
00467         ExprState  *refexpr;
00468         ExprState  *refassgnexpr;
00469         int16           refattrlength;  /* typlen of array type */
00470         int16           refelemlength;  /* typlen of the array element type */
00471         bool            refelembyval;   /* is the element type pass-by-value? */
00472         char            refelemalign;   /* typalign of the element type */
00473 } ArrayRefExprState;
00474 
00475 /* ----------------
00476  *              FuncExprState node
00477  *
00478  * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
00479  * and NullIf nodes; be careful to check what xprstate.expr is actually
00480  * pointing at!
00481  * ----------------
00482  */
00483 typedef struct FuncExprState
00484 {
00485         ExprState       xprstate;
00486         List       *args;                       /* states of argument expressions */
00487 
00488         /*
00489          * Function manager's lookup info for the target function.  If func.fn_oid
00490          * is InvalidOid, we haven't initialized it yet.
00491          */
00492         FmgrInfo        func;
00493 
00494         /*
00495          * We also need to store argument values across calls when evaluating a
00496          * function-returning-set.
00497          *
00498          * setArgsValid is true when we are evaluating a set-valued function and
00499          * we are in the middle of a call series; we want to pass the same
00500          * argument values to the function again (and again, until it returns
00501          * ExprEndResult).
00502          */
00503         bool            setArgsValid;
00504 
00505         /*
00506          * Flag to remember whether we found a set-valued argument to the
00507          * function. This causes the function result to be a set as well. Valid
00508          * only when setArgsValid is true.
00509          */
00510         bool            setHasSetArg;   /* some argument returns a set */
00511 
00512         /*
00513          * Flag to remember whether we have registered a shutdown callback for
00514          * this FuncExprState.  We do so only if setArgsValid has been true at
00515          * least once (since all the callback is for is to clear setArgsValid).
00516          */
00517         bool            shutdown_reg;   /* a shutdown callback is registered */
00518 
00519         /*
00520          * Current argument data for a set-valued function; contains valid data
00521          * only if setArgsValid is true.
00522          */
00523         FunctionCallInfoData setArgs;
00524 } FuncExprState;
00525 
00526 /* ----------------
00527  *              ScalarArrayOpExprState node
00528  *
00529  * This is a FuncExprState plus some additional data.
00530  * ----------------
00531  */
00532 typedef struct ScalarArrayOpExprState
00533 {
00534         FuncExprState fxprstate;
00535         /* Cached info about array element type */
00536         Oid                     element_type;
00537         int16           typlen;
00538         bool            typbyval;
00539         char            typalign;
00540 } ScalarArrayOpExprState;
00541 
00542 /* ----------------
00543  *              BoolExprState node
00544  * ----------------
00545  */
00546 typedef struct BoolExprState
00547 {
00548         ExprState       xprstate;
00549         List       *args;                       /* states of argument expression(s) */
00550 } BoolExprState;
00551 
00552 /* ----------------
00553  *              SubPlanState node
00554  * ----------------
00555  */
00556 typedef struct SubPlanState
00557 {
00558         ExprState       xprstate;
00559         EState     *sub_estate;         /* subselect plan has its own EState */
00560         struct PlanState *planstate;    /* subselect plan's state tree */
00561         List       *exprs;                      /* states of combining expression(s) */
00562         List       *args;                       /* states of argument expression(s) */
00563         bool            needShutdown;   /* TRUE = need to shutdown subplan */
00564         HeapTuple       curTuple;               /* copy of most recent tuple from subplan */
00565         /* these are used when hashing the subselect's output: */
00566         ProjectionInfo *projLeft;       /* for projecting lefthand exprs */
00567         ProjectionInfo *projRight;      /* for projecting subselect output */
00568         TupleHashTable hashtable;       /* hash table for no-nulls subselect rows */
00569         TupleHashTable hashnulls;       /* hash table for rows with null(s) */
00570         bool            havehashrows;   /* TRUE if hashtable is not empty */
00571         bool            havenullrows;   /* TRUE if hashnulls is not empty */
00572         MemoryContext tablecxt;         /* memory context containing tables */
00573         ExprContext *innerecontext; /* working context for comparisons */
00574         AttrNumber *keyColIdx;          /* control data for hash tables */
00575         FmgrInfo   *eqfunctions;        /* comparison functions for hash tables */
00576         FmgrInfo   *hashfunctions;      /* lookup data for hash functions */
00577 } SubPlanState;
00578 
00579 /* ----------------
00580  *              FieldSelectState node
00581  * ----------------
00582  */
00583 typedef struct FieldSelectState
00584 {
00585         ExprState       xprstate;
00586         ExprState  *arg;                        /* input expression */
00587         TupleDesc       argdesc;                /* tupdesc for most recent input */
00588 } FieldSelectState;
00589 
00590 /* ----------------
00591  *              FieldStoreState node
00592  * ----------------
00593  */
00594 typedef struct FieldStoreState
00595 {
00596         ExprState       xprstate;
00597         ExprState  *arg;                        /* input tuple value */
00598         List       *newvals;            /* new value(s) for field(s) */
00599         TupleDesc       argdesc;                /* tupdesc for most recent input */
00600 } FieldStoreState;
00601 
00602 /* ----------------
00603  *              ConvertRowtypeExprState node
00604  * ----------------
00605  */
00606 typedef struct ConvertRowtypeExprState
00607 {
00608         ExprState       xprstate;
00609         ExprState  *arg;                        /* input tuple value */
00610         TupleDesc       indesc;                 /* tupdesc for source rowtype */
00611         TupleDesc       outdesc;                /* tupdesc for result rowtype */
00612         AttrNumber *attrMap;            /* indexes of input fields, or 0 for null */
00613         Datum      *invalues;           /* workspace for deconstructing source */
00614         bool       *inisnull;
00615         Datum      *outvalues;          /* workspace for constructing result */
00616         bool       *outisnull;
00617 } ConvertRowtypeExprState;
00618 
00619 /* ----------------
00620  *              CaseExprState node
00621  * ----------------
00622  */
00623 typedef struct CaseExprState
00624 {
00625         ExprState       xprstate;
00626         ExprState  *arg;                        /* implicit equality comparison argument */
00627         List       *args;                       /* the arguments (list of WHEN clauses) */
00628         ExprState  *defresult;          /* the default result (ELSE clause) */
00629 } CaseExprState;
00630 
00631 /* ----------------
00632  *              CaseWhenState node
00633  * ----------------
00634  */
00635 typedef struct CaseWhenState
00636 {
00637         ExprState       xprstate;
00638         ExprState  *expr;                       /* condition expression */
00639         ExprState  *result;                     /* substitution result */
00640 } CaseWhenState;
00641 
00642 /* ----------------
00643  *              ArrayExprState node
00644  *
00645  * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
00646  * arrays.
00647  * ----------------
00648  */
00649 typedef struct ArrayExprState
00650 {
00651         ExprState       xprstate;
00652         List       *elements;           /* states for child nodes */
00653         int16           elemlength;             /* typlen of the array element type */
00654         bool            elembyval;              /* is the element type pass-by-value? */
00655         char            elemalign;              /* typalign of the element type */
00656 } ArrayExprState;
00657 
00658 /* ----------------
00659  *              RowExprState node
00660  * ----------------
00661  */
00662 typedef struct RowExprState
00663 {
00664         ExprState       xprstate;
00665         List       *args;                       /* the arguments */
00666         TupleDesc       tupdesc;                /* descriptor for result tuples */
00667 } RowExprState;
00668 
00669 /* ----------------
00670  *              CoalesceExprState node
00671  * ----------------
00672  */
00673 typedef struct CoalesceExprState
00674 {
00675         ExprState       xprstate;
00676         List       *args;                       /* the arguments */
00677 } CoalesceExprState;
00678 
00679 /* ----------------
00680  *              MinMaxExprState node
00681  * ----------------
00682  */
00683 typedef struct MinMaxExprState
00684 {
00685         ExprState       xprstate;
00686         List       *args;                       /* the arguments */
00687         FmgrInfo        cfunc;                  /* lookup info for comparison func */
00688 } MinMaxExprState;
00689 
00690 /* ----------------
00691  *              CoerceToDomainState node
00692  * ----------------
00693  */
00694 typedef struct CoerceToDomainState
00695 {
00696         ExprState       xprstate;
00697         ExprState  *arg;                        /* input expression */
00698         /* Cached list of constraints that need to be checked */
00699         List       *constraints;        /* list of DomainConstraintState nodes */
00700 } CoerceToDomainState;
00701 
00702 /*
00703  * DomainConstraintState - one item to check during CoerceToDomain
00704  *
00705  * Note: this is just a Node, and not an ExprState, because it has no
00706  * corresponding Expr to link to.  Nonetheless it is part of an ExprState
00707  * tree, so we give it a name following the xxxState convention.
00708  */
00709 typedef enum DomainConstraintType
00710 {
00711         DOM_CONSTRAINT_NOTNULL,
00712         DOM_CONSTRAINT_CHECK
00713 } DomainConstraintType;
00714 
00715 typedef struct DomainConstraintState
00716 {
00717         NodeTag         type;
00718         DomainConstraintType constrainttype;            /* constraint type */
00719         char       *name;                       /* name of constraint (for error msgs) */
00720         ExprState  *check_expr;         /* for CHECK, a boolean expression */
00721 } DomainConstraintState;
00722 
00723 
00724 /* ----------------------------------------------------------------
00725  *                               Executor State Trees
00726  *
00727  * An executing query has a PlanState tree paralleling the Plan tree
00728  * that describes the plan.
00729  * ----------------------------------------------------------------
00730  */
00731 
00732 /* ----------------
00733  *              PlanState node
00734  *
00735  * We never actually instantiate any PlanState nodes; this is just the common
00736  * abstract superclass for all PlanState-type nodes.
00737  * ----------------
00738  */
00739 typedef struct PlanState
00740 {
00741         NodeTag         type;
00742 
00743         Plan       *plan;                       /* associated Plan node */
00744 
00745         EState     *state;                      /* at execution time, state's of individual
00746                                                                  * nodes point to one EState for the whole
00747                                                                  * top-level plan */
00748 
00749         struct Instrumentation *instrument; /* Optional runtime stats for this
00750                                                                                  * plan node */
00751 
00752         /*
00753          * Common structural data for all Plan types.  These links to subsidiary
00754          * state trees parallel links in the associated plan tree (except for the
00755          * subPlan list, which does not exist in the plan tree).
00756          */
00757         List       *targetlist;         /* target list to be computed at this node */
00758         List       *qual;                       /* implicitly-ANDed qual conditions */
00759         struct PlanState *lefttree; /* input plan tree(s) */
00760         struct PlanState *righttree;
00761         List       *initPlan;           /* Init SubPlanState nodes (un-correlated expr
00762                                                                  * subselects) */
00763         List       *subPlan;            /* SubPlanState nodes in my expressions */
00764 
00765         /*
00766          * State for management of parameter-change-driven rescanning
00767          */
00768         Bitmapset  *chgParam;           /* set of IDs of changed Params */
00769 
00770         /*
00771          * Other run-time state needed by most if not all node types.
00772          */
00773         TupleTableSlot *ps_OuterTupleSlot;      /* slot for current "outer" tuple */
00774         TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
00775         ExprContext *ps_ExprContext;    /* node's expression-evaluation context */
00776         ProjectionInfo *ps_ProjInfo;    /* info for doing tuple projection */
00777         bool            ps_TupFromTlist;/* state flag for processing set-valued
00778                                                                  * functions in targetlist */
00779 } PlanState;
00780 
00781 /* ----------------
00782  *      these are are defined to avoid confusion problems with "left"
00783  *      and "right" and "inner" and "outer".  The convention is that
00784  *      the "left" plan is the "outer" plan and the "right" plan is
00785  *      the inner plan, but these make the code more readable.
00786  * ----------------
00787  */
00788 #define innerPlanState(node)            (((PlanState *)(node))->righttree)
00789 #define outerPlanState(node)            (((PlanState *)(node))->lefttree)
00790 
00791 
00792 /* ----------------
00793  *       ResultState information
00794  * ----------------
00795  */
00796 typedef struct ResultState
00797 {
00798         PlanState       ps;                             /* its first field is NodeTag */
00799         ExprState  *resconstantqual;
00800         bool            rs_done;                /* are we done? */
00801         bool            rs_checkqual;   /* do we need to check the qual? */
00802 } ResultState;
00803 
00804 /* ----------------
00805  *       AppendState information
00806  *
00807  *              nplans                  how many plans are in the list
00808  *              whichplan               which plan is being executed (0 .. n-1)
00809  *              firstplan               first plan to execute (usually 0)
00810  *              lastplan                last plan to execute (usually n-1)
00811  * ----------------
00812  */
00813 typedef struct AppendState
00814 {
00815         PlanState       ps;                             /* its first field is NodeTag */
00816         PlanState **appendplans;        /* array of PlanStates for my inputs */
00817         int                     as_nplans;
00818         int                     as_whichplan;
00819         int                     as_firstplan;
00820         int                     as_lastplan;
00821 } AppendState;
00822 
00823 /* ----------------
00824  *       BitmapAndState information
00825  * ----------------
00826  */
00827 typedef struct BitmapAndState
00828 {
00829         PlanState       ps;                             /* its first field is NodeTag */
00830         PlanState **bitmapplans;        /* array of PlanStates for my inputs */
00831         int                     nplans;                 /* number of input plans */
00832 } BitmapAndState;
00833 
00834 /* ----------------
00835  *       BitmapOrState information
00836  * ----------------
00837  */
00838 typedef struct BitmapOrState
00839 {
00840         PlanState       ps;                             /* its first field is NodeTag */
00841         PlanState **bitmapplans;        /* array of PlanStates for my inputs */
00842         int                     nplans;                 /* number of input plans */
00843 } BitmapOrState;
00844 
00845 /* ----------------------------------------------------------------
00846  *                               Scan State Information
00847  * ----------------------------------------------------------------
00848  */
00849 
00850 /* ----------------
00851  *       ScanState information
00852  *
00853  *              ScanState extends PlanState for node types that represent
00854  *              scans of an underlying relation.  It can also be used for nodes
00855  *              that scan the output of an underlying plan node --- in that case,
00856  *              only ScanTupleSlot is actually useful, and it refers to the tuple
00857  *              retrieved from the subplan.
00858  *
00859  *              currentRelation    relation being scanned (NULL if none)
00860  *              currentScanDesc    current scan descriptor for scan (NULL if none)
00861  *              ScanTupleSlot      pointer to slot in tuple table holding scan tuple
00862  * ----------------
00863  */
00864 typedef struct ScanState
00865 {
00866         PlanState       ps;                             /* its first field is NodeTag */
00867         Relation        ss_currentRelation;
00868         HeapScanDesc ss_currentScanDesc;
00869         TupleTableSlot *ss_ScanTupleSlot;
00870 } ScanState;
00871 
00872 /*
00873  * SeqScan uses a bare ScanState as its state node, since it needs
00874  * no additional fields.
00875  */
00876 typedef ScanState SeqScanState;
00877 
00878 /* ----------------
00879  *       IndexScanState information
00880  *
00881  *              indexqualorig      execution state for indexqualorig expressions
00882  *              ScanKeys                   Skey structures to scan index rel
00883  *              NumScanKeys                number of Skey structs
00884  *              RuntimeKeyInfo     array of exprstates for Skeys
00885  *                                                 that will be evaluated at runtime
00886  *              RuntimeContext     expr context for evaling runtime Skeys
00887  *              RuntimeKeysReady   true if runtime Skeys have been computed
00888  *              RelationDesc       index relation descriptor
00889  *              ScanDesc                   index scan descriptor
00890  * ----------------
00891  */
00892 typedef struct IndexScanState
00893 {
00894         ScanState       ss;                             /* its first field is NodeTag */
00895         List       *indexqualorig;
00896         ScanKey         iss_ScanKeys;
00897         int                     iss_NumScanKeys;
00898         ExprState **iss_RuntimeKeyInfo;
00899         ExprContext *iss_RuntimeContext;
00900         bool            iss_RuntimeKeysReady;
00901         Relation        iss_RelationDesc;
00902         IndexScanDesc iss_ScanDesc;
00903 } IndexScanState;
00904 
00905 /* ----------------
00906  *       BitmapIndexScanState information
00907  *
00908  *              result                     bitmap to return output into, or NULL
00909  *              ScanKeys                   Skey structures to scan index rel
00910  *              NumScanKeys                number of Skey structs
00911  *              RuntimeKeyInfo     array of exprstates for Skeys
00912  *                                                 that will be evaluated at runtime
00913  *              RuntimeContext     expr context for evaling runtime Skeys
00914  *              RuntimeKeysReady   true if runtime Skeys have been computed
00915  *              RelationDesc       index relation descriptor
00916  *              ScanDesc                   index scan descriptor
00917  * ----------------
00918  */
00919 typedef struct BitmapIndexScanState
00920 {
00921         ScanState       ss;                             /* its first field is NodeTag */
00922         TIDBitmap  *biss_result;
00923         ScanKey         biss_ScanKeys;
00924         int                     biss_NumScanKeys;
00925         ExprState **biss_RuntimeKeyInfo;
00926         ExprContext *biss_RuntimeContext;
00927         bool            biss_RuntimeKeysReady;
00928         Relation        biss_RelationDesc;
00929         IndexScanDesc biss_ScanDesc;
00930 } BitmapIndexScanState;
00931 
00932 /* ----------------
00933  *       BitmapHeapScanState information
00934  *
00935  *              bitmapqualorig     execution state for bitmapqualorig expressions
00936  *              tbm                                bitmap obtained from child index scan(s)
00937  *              tbmres                     current-page data
00938  *              curslot                    current tbmres index or tuple offset on page
00939  *              minslot                    lowest tbmres index or tuple offset to try
00940  *              maxslot                    highest tbmres index or tuple offset to try
00941  * ----------------
00942  */
00943 typedef struct BitmapHeapScanState
00944 {
00945         ScanState       ss;                             /* its first field is NodeTag */
00946         List       *bitmapqualorig;
00947         TIDBitmap  *tbm;
00948         TBMIterateResult *tbmres;
00949         int                     curslot;
00950         int                     minslot;
00951         int                     maxslot;
00952 } BitmapHeapScanState;
00953 
00954 /* ----------------
00955  *       TidScanState information
00956  *
00957  *              NumTids            number of tids in this scan
00958  *              TidPtr             current tid in use
00959  *              TidList            evaluated item pointers
00960  * ----------------
00961  */
00962 typedef struct TidScanState
00963 {
00964         ScanState       ss;                             /* its first field is NodeTag */
00965         List       *tss_tideval;        /* list of ExprState nodes */
00966         int                     tss_NumTids;
00967         int                     tss_TidPtr;
00968         int                     tss_MarkTidPtr;
00969         ItemPointerData *tss_TidList;
00970         HeapTupleData tss_htup;
00971 } TidScanState;
00972 
00973 /* ----------------
00974  *       SubqueryScanState information
00975  *
00976  *              SubqueryScanState is used for scanning a sub-query in the range table.
00977  *              The sub-query will have its own EState, which we save here.
00978  *              ScanTupleSlot references the current output tuple of the sub-query.
00979  *
00980  *              SubEState                  exec state for sub-query
00981  * ----------------
00982  */
00983 typedef struct SubqueryScanState
00984 {
00985         ScanState       ss;                             /* its first field is NodeTag */
00986         PlanState  *subplan;
00987         EState     *sss_SubEState;
00988 } SubqueryScanState;
00989 
00990 /* ----------------
00991  *       FunctionScanState information
00992  *
00993  *              Function nodes are used to scan the results of a
00994  *              function appearing in FROM (typically a function returning set).
00995  *
00996  *              tupdesc                         expected return tuple description
00997  *              tuplestorestate         private state of tuplestore.c
00998  *              funcexpr                        state for function expression being evaluated
00999  * ----------------
01000  */
01001 typedef struct FunctionScanState
01002 {
01003         ScanState       ss;                             /* its first field is NodeTag */
01004         TupleDesc       tupdesc;
01005         Tuplestorestate *tuplestorestate;
01006         ExprState  *funcexpr;
01007 } FunctionScanState;
01008 
01009 /* ----------------------------------------------------------------
01010  *                               Join State Information
01011  * ----------------------------------------------------------------
01012  */
01013 
01014 /* ----------------
01015  *       JoinState information
01016  *
01017  *              Superclass for state nodes of join plans.
01018  * ----------------
01019  */
01020 typedef struct JoinState
01021 {
01022         PlanState       ps;
01023         JoinType        jointype;
01024         List       *joinqual;           /* JOIN quals (in addition to ps.qual) */
01025 } JoinState;
01026 
01027 /* ----------------
01028  *       NestLoopState information
01029  *
01030  *              NeedNewOuter       true if need new outer tuple on next call
01031  *              MatchedOuter       true if found a join match for current outer tuple
01032  *              NullInnerTupleSlot prepared null tuple for left outer joins
01033  * ----------------
01034  */
01035 typedef struct NestLoopState
01036 {
01037         JoinState       js;                             /* its first field is NodeTag */
01038         bool            nl_NeedNewOuter;
01039         bool            nl_MatchedOuter;
01040         TupleTableSlot *nl_NullInnerTupleSlot;
01041 } NestLoopState;
01042 
01043 /* ----------------
01044  *       MergeJoinState information
01045  *
01046  *              NumClauses                 number of mergejoinable join clauses
01047  *              Clauses                    info for each mergejoinable clause
01048  *              JoinState                  current "state" of join.  see execdefs.h
01049  *              FillOuter                  true if should emit unjoined outer tuples anyway
01050  *              FillInner                  true if should emit unjoined inner tuples anyway
01051  *              MatchedOuter       true if found a join match for current outer tuple
01052  *              MatchedInner       true if found a join match for current inner tuple
01053  *              OuterTupleSlot     slot in tuple table for cur outer tuple
01054  *              InnerTupleSlot     slot in tuple table for cur inner tuple
01055  *              MarkedTupleSlot    slot in tuple table for marked tuple
01056  *              NullOuterTupleSlot prepared null tuple for right outer joins
01057  *              NullInnerTupleSlot prepared null tuple for left outer joins
01058  *              OuterEContext      workspace for computing outer tuple's join values
01059  *              InnerEContext      workspace for computing inner tuple's join values
01060  * ----------------
01061  */
01062 /* private in nodeMergejoin.c: */
01063 typedef struct MergeJoinClauseData *MergeJoinClause;
01064 
01065 typedef struct MergeJoinState
01066 {
01067         JoinState       js;                             /* its first field is NodeTag */
01068         int                     mj_NumClauses;
01069         MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
01070         int                     mj_JoinState;
01071         bool            mj_FillOuter;
01072         bool            mj_FillInner;
01073         bool            mj_MatchedOuter;
01074         bool            mj_MatchedInner;
01075         TupleTableSlot *mj_OuterTupleSlot;
01076         TupleTableSlot *mj_InnerTupleSlot;
01077         TupleTableSlot *mj_MarkedTupleSlot;
01078         TupleTableSlot *mj_NullOuterTupleSlot;
01079         TupleTableSlot *mj_NullInnerTupleSlot;
01080         ExprContext *mj_OuterEContext;
01081         ExprContext *mj_InnerEContext;
01082 } MergeJoinState;
01083 
01084 /* ----------------
01085  *       HashJoinState information
01086  *
01087  *              hj_HashTable                    hash table for the hashjoin
01088  *                                                              (NULL if table not built yet)
01089  *              hj_CurHashValue                 hash value for current outer tuple
01090  *              hj_CurBucketNo                  bucket# for current outer tuple
01091  *              hj_CurTuple                             last inner tuple matched to current outer
01092  *                                                              tuple, or NULL if starting search
01093  *                                                              (CurHashValue, CurBucketNo and CurTuple are
01094  *                                                               undefined if OuterTupleSlot is empty!)
01095  *              hj_OuterHashKeys                the outer hash keys in the hashjoin condition
01096  *              hj_InnerHashKeys                the inner hash keys in the hashjoin condition
01097  *              hj_HashOperators                the join operators in the hashjoin condition
01098  *              hj_OuterTupleSlot               tuple slot for outer tuples
01099  *              hj_HashTupleSlot                tuple slot for hashed tuples
01100  *              hj_NullInnerTupleSlot   prepared null tuple for left outer joins
01101  *              hj_FirstOuterTupleSlot  first tuple retrieved from outer plan
01102  *              hj_NeedNewOuter                 true if need new outer tuple on next call
01103  *              hj_MatchedOuter                 true if found a join match for current outer
01104  *              hj_OuterNotEmpty                true if outer relation known not empty
01105  * ----------------
01106  */
01107 
01108 /* these structs are defined in executor/hashjoin.h: */
01109 typedef struct HashJoinTupleData *HashJoinTuple;
01110 typedef struct HashJoinTableData *HashJoinTable;
01111 
01112 typedef struct HashJoinState
01113 {
01114         JoinState       js;                             /* its first field is NodeTag */
01115         List       *hashclauses;        /* list of ExprState nodes */
01116         HashJoinTable hj_HashTable;
01117         uint32          hj_CurHashValue;
01118         int                     hj_CurBucketNo;
01119         HashJoinTuple hj_CurTuple;
01120         List       *hj_OuterHashKeys;           /* list of ExprState nodes */
01121         List       *hj_InnerHashKeys;           /* list of ExprState nodes */
01122         List       *hj_HashOperators;           /* list of operator OIDs */
01123         TupleTableSlot *hj_OuterTupleSlot;
01124         TupleTableSlot *hj_HashTupleSlot;
01125         TupleTableSlot *hj_NullInnerTupleSlot;
01126         TupleTableSlot *hj_FirstOuterTupleSlot;
01127         bool            hj_NeedNewOuter;
01128         bool            hj_MatchedOuter;
01129         bool            hj_OuterNotEmpty;
01130 } HashJoinState;
01131 
01132 
01133 /* ----------------------------------------------------------------
01134  *                               Materialization State Information
01135  * ----------------------------------------------------------------
01136  */
01137 
01138 /* ----------------
01139  *       MaterialState information
01140  *
01141  *              materialize nodes are used to materialize the results
01142  *              of a subplan into a temporary file.
01143  *
01144  *              ss.ss_ScanTupleSlot refers to output of underlying plan.
01145  * ----------------
01146  */
01147 typedef struct MaterialState
01148 {
01149         ScanState       ss;                             /* its first field is NodeTag */
01150         void       *tuplestorestate;    /* private state of tuplestore.c */
01151         bool            eof_underlying; /* reached end of underlying plan? */
01152 } MaterialState;
01153 
01154 /* ----------------
01155  *       SortState information
01156  * ----------------
01157  */
01158 typedef struct SortState
01159 {
01160         ScanState       ss;                             /* its first field is NodeTag */
01161         bool            sort_Done;              /* sort completed yet? */
01162         void       *tuplesortstate; /* private state of tuplesort.c */
01163 } SortState;
01164 
01165 /* ---------------------
01166  *      GroupState information
01167  * -------------------------
01168  */
01169 typedef struct GroupState
01170 {
01171         ScanState       ss;                             /* its first field is NodeTag */
01172         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
01173         bool            grp_done;               /* indicates completion of Group scan */
01174 } GroupState;
01175 
01176 /* ---------------------
01177  *      AggState information
01178  *
01179  *      ss.ss_ScanTupleSlot refers to output of underlying plan.
01180  *
01181  *      Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
01182  *      ecxt_aggnulls arrays, which hold the computed agg values for the current
01183  *      input group during evaluation of an Agg node's output tuple(s).  We
01184  *      create a second ExprContext, tmpcontext, in which to evaluate input
01185  *      expressions and run the aggregate transition functions.
01186  * -------------------------
01187  */
01188 /* these structs are private in nodeAgg.c: */
01189 typedef struct AggStatePerAggData *AggStatePerAgg;
01190 typedef struct AggStatePerGroupData *AggStatePerGroup;
01191 
01192 typedef struct AggState
01193 {
01194         ScanState       ss;                             /* its first field is NodeTag */
01195         List       *aggs;                       /* all Aggref nodes in targetlist & quals */
01196         int                     numaggs;                /* length of list (could be zero!) */
01197         FmgrInfo   *eqfunctions;        /* per-grouping-field equality fns */
01198         FmgrInfo   *hashfunctions;      /* per-grouping-field hash fns */
01199         AggStatePerAgg peragg;          /* per-Aggref information */
01200         MemoryContext aggcontext;       /* memory context for long-lived data */
01201         ExprContext *tmpcontext;        /* econtext for input expressions */
01202         bool            agg_done;               /* indicates completion of Agg scan */
01203         /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
01204         AggStatePerGroup pergroup;      /* per-Aggref-per-group working state */
01205         HeapTuple       grp_firstTuple; /* copy of first tuple of current group */
01206         /* these fields are used in AGG_HASHED mode: */
01207         TupleHashTable hashtable;       /* hash table with one entry per group */
01208         bool            table_filled;   /* hash table filled yet? */
01209         TupleHashIterator hashiter; /* for iterating through hash table */
01210 } AggState;
01211 
01212 /* ----------------
01213  *       UniqueState information
01214  *
01215  *              Unique nodes are used "on top of" sort nodes to discard
01216  *              duplicate tuples returned from the sort phase.  Basically
01217  *              all it does is compare the current tuple from the subplan
01218  *              with the previously fetched tuple (stored in its result slot).
01219  *              If the two are identical in all interesting fields, then
01220  *              we just fetch another tuple from the sort and try again.
01221  * ----------------
01222  */
01223 typedef struct UniqueState
01224 {
01225         PlanState       ps;                             /* its first field is NodeTag */
01226         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
01227         MemoryContext tempContext;      /* short-term context for comparisons */
01228 } UniqueState;
01229 
01230 /* ----------------
01231  *       HashState information
01232  * ----------------
01233  */
01234 typedef struct HashState
01235 {
01236         PlanState       ps;                             /* its first field is NodeTag */
01237         HashJoinTable hashtable;        /* hash table for the hashjoin */
01238         List       *hashkeys;           /* list of ExprState nodes */
01239         /* hashkeys is same as parent's hj_InnerHashKeys */
01240 } HashState;
01241 
01242 /* ----------------
01243  *       SetOpState information
01244  *
01245  *              SetOp nodes are used "on top of" sort nodes to discard
01246  *              duplicate tuples returned from the sort phase.  These are
01247  *              more complex than a simple Unique since we have to count
01248  *              how many duplicates to return.
01249  * ----------------
01250  */
01251 typedef struct SetOpState
01252 {
01253         PlanState       ps;                             /* its first field is NodeTag */
01254         FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
01255         bool            subplan_done;   /* has subplan returned EOF? */
01256         long            numLeft;                /* number of left-input dups of cur group */
01257         long            numRight;               /* number of right-input dups of cur group */
01258         long            numOutput;              /* number of dups left to output */
01259         MemoryContext tempContext;      /* short-term context for comparisons */
01260 } SetOpState;
01261 
01262 /* ----------------
01263  *       LimitState information
01264  *
01265  *              Limit nodes are used to enforce LIMIT/OFFSET clauses.
01266  *              They just select the desired subrange of their subplan's output.
01267  *
01268  * offset is the number of initial tuples to skip (0 does nothing).
01269  * count is the number of tuples to return after skipping the offset tuples.
01270  * If no limit count was specified, count is undefined and noCount is true.
01271  * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
01272  * ----------------
01273  */
01274 typedef enum
01275 {
01276         LIMIT_INITIAL,                          /* initial state for LIMIT node */
01277         LIMIT_EMPTY,                            /* there are no returnable rows */
01278         LIMIT_INWINDOW,                         /* have returned a row in the window */
01279         LIMIT_SUBPLANEOF,                       /* at EOF of subplan (within window) */
01280         LIMIT_WINDOWEND,                        /* stepped off end of window */
01281         LIMIT_WINDOWSTART                       /* stepped off beginning of window */
01282 } LimitStateCond;
01283 
01284 typedef struct LimitState
01285 {
01286         PlanState       ps;                             /* its first field is NodeTag */
01287         ExprState  *limitOffset;        /* OFFSET parameter, or NULL if none */
01288         ExprState  *limitCount;         /* COUNT parameter, or NULL if none */
01289         long            offset;                 /* current OFFSET value */
01290         long            count;                  /* current COUNT, if any */
01291         bool            noCount;                /* if true, ignore count */
01292         LimitStateCond lstate;          /* state machine status, as above */
01293         long            position;               /* 1-based index of last tuple returned */
01294         TupleTableSlot *subSlot;        /* tuple last obtained from subplan */
01295 } LimitState;
01296 
01297 #endif   /* EXECNODES_H */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'