Header And Logo

PostgreSQL
| The world's most advanced open source database.

execnodes.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * execnodes.h
00004  *    definitions for executor state nodes
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/nodes/execnodes.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef EXECNODES_H
00015 #define EXECNODES_H
00016 
00017 #include "access/genam.h"
00018 #include "access/heapam.h"
00019 #include "executor/instrument.h"
00020 #include "nodes/params.h"
00021 #include "nodes/plannodes.h"
00022 #include "utils/reltrigger.h"
00023 #include "utils/sortsupport.h"
00024 #include "utils/tuplestore.h"
00025 
00026 
00027 /* ----------------
00028  *    IndexInfo information
00029  *
00030  *      this struct holds the information needed to construct new index
00031  *      entries for a particular index.  Used for both index_build and
00032  *      retail creation of index entries.
00033  *
00034  *      NumIndexAttrs       number of columns in this index
00035  *      KeyAttrNumbers      underlying-rel attribute numbers used as keys
00036  *                          (zeroes indicate expressions)
00037  *      Expressions         expr trees for expression entries, or NIL if none
00038  *      ExpressionsState    exec state for expressions, or NIL if none
00039  *      Predicate           partial-index predicate, or NIL if none
00040  *      PredicateState      exec state for predicate, or NIL if none
00041  *      ExclusionOps        Per-column exclusion operators, or NULL if none
00042  *      ExclusionProcs      Underlying function OIDs for ExclusionOps
00043  *      ExclusionStrats     Opclass strategy numbers for ExclusionOps
00044  *      Unique              is it a unique index?
00045  *      ReadyForInserts     is it valid for inserts?
00046  *      Concurrent          are we doing a concurrent index build?
00047  *      BrokenHotChain      did we detect any broken HOT chains?
00048  *
00049  * ii_Concurrent and ii_BrokenHotChain are used only during index build;
00050  * they're conventionally set to false otherwise.
00051  * ----------------
00052  */
00053 typedef struct IndexInfo
00054 {
00055     NodeTag     type;
00056     int         ii_NumIndexAttrs;
00057     AttrNumber  ii_KeyAttrNumbers[INDEX_MAX_KEYS];
00058     List       *ii_Expressions; /* list of Expr */
00059     List       *ii_ExpressionsState;    /* list of ExprState */
00060     List       *ii_Predicate;   /* list of Expr */
00061     List       *ii_PredicateState;      /* list of ExprState */
00062     Oid        *ii_ExclusionOps;    /* array with one entry per column */
00063     Oid        *ii_ExclusionProcs;      /* array with one entry per column */
00064     uint16     *ii_ExclusionStrats;     /* array with one entry per column */
00065     bool        ii_Unique;
00066     bool        ii_ReadyForInserts;
00067     bool        ii_Concurrent;
00068     bool        ii_BrokenHotChain;
00069 } IndexInfo;
00070 
00071 /* ----------------
00072  *    ExprContext_CB
00073  *
00074  *      List of callbacks to be called at ExprContext shutdown.
00075  * ----------------
00076  */
00077 typedef void (*ExprContextCallbackFunction) (Datum arg);
00078 
00079 typedef struct ExprContext_CB
00080 {
00081     struct ExprContext_CB *next;
00082     ExprContextCallbackFunction function;
00083     Datum       arg;
00084 } ExprContext_CB;
00085 
00086 /* ----------------
00087  *    ExprContext
00088  *
00089  *      This class holds the "current context" information
00090  *      needed to evaluate expressions for doing tuple qualifications
00091  *      and tuple projections.  For example, if an expression refers
00092  *      to an attribute in the current inner tuple then we need to know
00093  *      what the current inner tuple is and so we look at the expression
00094  *      context.
00095  *
00096  *  There are two memory contexts associated with an ExprContext:
00097  *  * ecxt_per_query_memory is a query-lifespan context, typically the same
00098  *    context the ExprContext node itself is allocated in.  This context
00099  *    can be used for purposes such as storing function call cache info.
00100  *  * ecxt_per_tuple_memory is a short-term context for expression results.
00101  *    As the name suggests, it will typically be reset once per tuple,
00102  *    before we begin to evaluate expressions for that tuple.  Each
00103  *    ExprContext normally has its very own per-tuple memory context.
00104  *
00105  *  CurrentMemoryContext should be set to ecxt_per_tuple_memory before
00106  *  calling ExecEvalExpr() --- see ExecEvalExprSwitchContext().
00107  * ----------------
00108  */
00109 typedef struct ExprContext
00110 {
00111     NodeTag     type;
00112 
00113     /* Tuples that Var nodes in expression may refer to */
00114     TupleTableSlot *ecxt_scantuple;
00115     TupleTableSlot *ecxt_innertuple;
00116     TupleTableSlot *ecxt_outertuple;
00117 
00118     /* Memory contexts for expression evaluation --- see notes above */
00119     MemoryContext ecxt_per_query_memory;
00120     MemoryContext ecxt_per_tuple_memory;
00121 
00122     /* Values to substitute for Param nodes in expression */
00123     ParamExecData *ecxt_param_exec_vals;        /* for PARAM_EXEC params */
00124     ParamListInfo ecxt_param_list_info; /* for other param types */
00125 
00126     /*
00127      * Values to substitute for Aggref nodes in the expressions of an Agg
00128      * node, or for WindowFunc nodes within a WindowAgg node.
00129      */
00130     Datum      *ecxt_aggvalues; /* precomputed values for aggs/windowfuncs */
00131     bool       *ecxt_aggnulls;  /* null flags for aggs/windowfuncs */
00132 
00133     /* Value to substitute for CaseTestExpr nodes in expression */
00134     Datum       caseValue_datum;
00135     bool        caseValue_isNull;
00136 
00137     /* Value to substitute for CoerceToDomainValue nodes in expression */
00138     Datum       domainValue_datum;
00139     bool        domainValue_isNull;
00140 
00141     /* Link to containing EState (NULL if a standalone ExprContext) */
00142     struct EState *ecxt_estate;
00143 
00144     /* Functions to call back when ExprContext is shut down */
00145     ExprContext_CB *ecxt_callbacks;
00146 } ExprContext;
00147 
00148 /*
00149  * Set-result status returned by ExecEvalExpr()
00150  */
00151 typedef enum
00152 {
00153     ExprSingleResult,           /* expression does not return a set */
00154     ExprMultipleResult,         /* this result is an element of a set */
00155     ExprEndResult               /* there are no more elements in the set */
00156 } ExprDoneCond;
00157 
00158 /*
00159  * Return modes for functions returning sets.  Note values must be chosen
00160  * as separate bits so that a bitmask can be formed to indicate supported
00161  * modes.  SFRM_Materialize_Random and SFRM_Materialize_Preferred are
00162  * auxiliary flags about SFRM_Materialize mode, rather than separate modes.
00163  */
00164 typedef enum
00165 {
00166     SFRM_ValuePerCall = 0x01,   /* one value returned per call */
00167     SFRM_Materialize = 0x02,    /* result set instantiated in Tuplestore */
00168     SFRM_Materialize_Random = 0x04,     /* Tuplestore needs randomAccess */
00169     SFRM_Materialize_Preferred = 0x08   /* caller prefers Tuplestore */
00170 } SetFunctionReturnMode;
00171 
00172 /*
00173  * When calling a function that might return a set (multiple rows),
00174  * a node of this type is passed as fcinfo->resultinfo to allow
00175  * return status to be passed back.  A function returning set should
00176  * raise an error if no such resultinfo is provided.
00177  */
00178 typedef struct ReturnSetInfo
00179 {
00180     NodeTag     type;
00181     /* values set by caller: */
00182     ExprContext *econtext;      /* context function is being called in */
00183     TupleDesc   expectedDesc;   /* tuple descriptor expected by caller */
00184     int         allowedModes;   /* bitmask: return modes caller can handle */
00185     /* result status from function (but pre-initialized by caller): */
00186     SetFunctionReturnMode returnMode;   /* actual return mode */
00187     ExprDoneCond isDone;        /* status for ValuePerCall mode */
00188     /* fields filled by function in Materialize return mode: */
00189     Tuplestorestate *setResult; /* holds the complete returned tuple set */
00190     TupleDesc   setDesc;        /* actual descriptor for returned tuples */
00191 } ReturnSetInfo;
00192 
00193 /* ----------------
00194  *      ProjectionInfo node information
00195  *
00196  *      This is all the information needed to perform projections ---
00197  *      that is, form new tuples by evaluation of targetlist expressions.
00198  *      Nodes which need to do projections create one of these.
00199  *
00200  *      ExecProject() evaluates the tlist, forms a tuple, and stores it
00201  *      in the given slot.  Note that the result will be a "virtual" tuple
00202  *      unless ExecMaterializeSlot() is then called to force it to be
00203  *      converted to a physical tuple.  The slot must have a tupledesc
00204  *      that matches the output of the tlist!
00205  *
00206  *      The planner very often produces tlists that consist entirely of
00207  *      simple Var references (lower levels of a plan tree almost always
00208  *      look like that).  And top-level tlists are often mostly Vars too.
00209  *      We therefore optimize execution of simple-Var tlist entries.
00210  *      The pi_targetlist list actually contains only the tlist entries that
00211  *      aren't simple Vars, while those that are Vars are processed using the
00212  *      varSlotOffsets/varNumbers/varOutputCols arrays.
00213  *
00214  *      The lastXXXVar fields are used to optimize fetching of fields from
00215  *      input tuples: they let us do a slot_getsomeattrs() call to ensure
00216  *      that all needed attributes are extracted in one pass.
00217  *
00218  *      targetlist      target list for projection (non-Var expressions only)
00219  *      exprContext     expression context in which to evaluate targetlist
00220  *      slot            slot to place projection result in
00221  *      itemIsDone      workspace array for ExecProject
00222  *      directMap       true if varOutputCols[] is an identity map
00223  *      numSimpleVars   number of simple Vars found in original tlist
00224  *      varSlotOffsets  array indicating which slot each simple Var is from
00225  *      varNumbers      array containing input attr numbers of simple Vars
00226  *      varOutputCols   array containing output attr numbers of simple Vars
00227  *      lastInnerVar    highest attnum from inner tuple slot (0 if none)
00228  *      lastOuterVar    highest attnum from outer tuple slot (0 if none)
00229  *      lastScanVar     highest attnum from scan tuple slot (0 if none)
00230  * ----------------
00231  */
00232 typedef struct ProjectionInfo
00233 {
00234     NodeTag     type;
00235     List       *pi_targetlist;
00236     ExprContext *pi_exprContext;
00237     TupleTableSlot *pi_slot;
00238     ExprDoneCond *pi_itemIsDone;
00239     bool        pi_directMap;
00240     int         pi_numSimpleVars;
00241     int        *pi_varSlotOffsets;
00242     int        *pi_varNumbers;
00243     int        *pi_varOutputCols;
00244     int         pi_lastInnerVar;
00245     int         pi_lastOuterVar;
00246     int         pi_lastScanVar;
00247 } ProjectionInfo;
00248 
00249 /* ----------------
00250  *    JunkFilter
00251  *
00252  *    This class is used to store information regarding junk attributes.
00253  *    A junk attribute is an attribute in a tuple that is needed only for
00254  *    storing intermediate information in the executor, and does not belong
00255  *    in emitted tuples.  For example, when we do an UPDATE query,
00256  *    the planner adds a "junk" entry to the targetlist so that the tuples
00257  *    returned to ExecutePlan() contain an extra attribute: the ctid of
00258  *    the tuple to be updated.  This is needed to do the update, but we
00259  *    don't want the ctid to be part of the stored new tuple!  So, we
00260  *    apply a "junk filter" to remove the junk attributes and form the
00261  *    real output tuple.  The junkfilter code also provides routines to
00262  *    extract the values of the junk attribute(s) from the input tuple.
00263  *
00264  *    targetList:       the original target list (including junk attributes).
00265  *    cleanTupType:     the tuple descriptor for the "clean" tuple (with
00266  *                      junk attributes removed).
00267  *    cleanMap:         A map with the correspondence between the non-junk
00268  *                      attribute numbers of the "original" tuple and the
00269  *                      attribute numbers of the "clean" tuple.
00270  *    resultSlot:       tuple slot used to hold cleaned tuple.
00271  *    junkAttNo:        not used by junkfilter code.  Can be used by caller
00272  *                      to remember the attno of a specific junk attribute
00273  *                      (execMain.c stores the "ctid" attno here).
00274  * ----------------
00275  */
00276 typedef struct JunkFilter
00277 {
00278     NodeTag     type;
00279     List       *jf_targetList;
00280     TupleDesc   jf_cleanTupType;
00281     AttrNumber *jf_cleanMap;
00282     TupleTableSlot *jf_resultSlot;
00283     AttrNumber  jf_junkAttNo;
00284 } JunkFilter;
00285 
00286 /* ----------------
00287  *    ResultRelInfo information
00288  *
00289  *      Whenever we update an existing relation, we have to
00290  *      update indices on the relation, and perhaps also fire triggers.
00291  *      The ResultRelInfo class is used to hold all the information needed
00292  *      about a result relation, including indices.. -cim 10/15/89
00293  *
00294  *      RangeTableIndex         result relation's range table index
00295  *      RelationDesc            relation descriptor for result relation
00296  *      NumIndices              # of indices existing on result relation
00297  *      IndexRelationDescs      array of relation descriptors for indices
00298  *      IndexRelationInfo       array of key/attr info for indices
00299  *      TrigDesc                triggers to be fired, if any
00300  *      TrigFunctions           cached lookup info for trigger functions
00301  *      TrigWhenExprs           array of trigger WHEN expr states
00302  *      TrigInstrument          optional runtime measurements for triggers
00303  *      ConstraintExprs         array of constraint-checking expr states
00304  *      junkFilter              for removing junk attributes from tuples
00305  *      projectReturning        for computing a RETURNING list
00306  * ----------------
00307  */
00308 typedef struct ResultRelInfo
00309 {
00310     NodeTag     type;
00311     Index       ri_RangeTableIndex;
00312     Relation    ri_RelationDesc;
00313     int         ri_NumIndices;
00314     RelationPtr ri_IndexRelationDescs;
00315     IndexInfo **ri_IndexRelationInfo;
00316     TriggerDesc *ri_TrigDesc;
00317     FmgrInfo   *ri_TrigFunctions;
00318     List      **ri_TrigWhenExprs;
00319     Instrumentation *ri_TrigInstrument;
00320     List      **ri_ConstraintExprs;
00321     JunkFilter *ri_junkFilter;
00322     ProjectionInfo *ri_projectReturning;
00323 } ResultRelInfo;
00324 
00325 /* ----------------
00326  *    EState information
00327  *
00328  * Master working state for an Executor invocation
00329  * ----------------
00330  */
00331 typedef struct EState
00332 {
00333     NodeTag     type;
00334 
00335     /* Basic state for all query types: */
00336     ScanDirection es_direction; /* current scan direction */
00337     Snapshot    es_snapshot;    /* time qual to use */
00338     Snapshot    es_crosscheck_snapshot; /* crosscheck time qual for RI */
00339     List       *es_range_table; /* List of RangeTblEntry */
00340     PlannedStmt *es_plannedstmt;    /* link to top of plan tree */
00341 
00342     JunkFilter *es_junkFilter;  /* top-level junk filter, if any */
00343 
00344     /* If query can insert/delete tuples, the command ID to mark them with */
00345     CommandId   es_output_cid;
00346 
00347     /* Info about target table(s) for insert/update/delete queries: */
00348     ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
00349     int         es_num_result_relations;        /* length of array */
00350     ResultRelInfo *es_result_relation_info;     /* currently active array elt */
00351 
00352     /* Stuff used for firing triggers: */
00353     List       *es_trig_target_relations;       /* trigger-only ResultRelInfos */
00354     TupleTableSlot *es_trig_tuple_slot; /* for trigger output tuples */
00355     TupleTableSlot *es_trig_oldtup_slot;        /* for TriggerEnabled */
00356     TupleTableSlot *es_trig_newtup_slot;        /* for TriggerEnabled */
00357 
00358     /* Parameter info: */
00359     ParamListInfo es_param_list_info;   /* values of external params */
00360     ParamExecData *es_param_exec_vals;  /* values of internal params */
00361 
00362     /* Other working state: */
00363     MemoryContext es_query_cxt; /* per-query context in which EState lives */
00364 
00365     List       *es_tupleTable;  /* List of TupleTableSlots */
00366 
00367     List       *es_rowMarks;    /* List of ExecRowMarks */
00368 
00369     uint32      es_processed;   /* # of tuples processed */
00370     Oid         es_lastoid;     /* last oid processed (by INSERT) */
00371 
00372     int         es_top_eflags;  /* eflags passed to ExecutorStart */
00373     int         es_instrument;  /* OR of InstrumentOption flags */
00374     bool        es_finished;    /* true when ExecutorFinish is done */
00375 
00376     List       *es_exprcontexts;    /* List of ExprContexts within EState */
00377 
00378     List       *es_subplanstates;       /* List of PlanState for SubPlans */
00379 
00380     List       *es_auxmodifytables;     /* List of secondary ModifyTableStates */
00381 
00382     /*
00383      * this ExprContext is for per-output-tuple operations, such as constraint
00384      * checks and index-value computations.  It will be reset for each output
00385      * tuple.  Note that it will be created only if needed.
00386      */
00387     ExprContext *es_per_tuple_exprcontext;
00388 
00389     /*
00390      * These fields are for re-evaluating plan quals when an updated tuple is
00391      * substituted in READ COMMITTED mode.  es_epqTuple[] contains tuples that
00392      * scan plan nodes should return instead of whatever they'd normally
00393      * return, or NULL if nothing to return; es_epqTupleSet[] is true if a
00394      * particular array entry is valid; and es_epqScanDone[] is state to
00395      * remember if the tuple has been returned already.  Arrays are of size
00396      * list_length(es_range_table) and are indexed by scan node scanrelid - 1.
00397      */
00398     HeapTuple  *es_epqTuple;    /* array of EPQ substitute tuples */
00399     bool       *es_epqTupleSet; /* true if EPQ tuple is provided */
00400     bool       *es_epqScanDone; /* true if EPQ tuple has been fetched */
00401 } EState;
00402 
00403 
00404 /*
00405  * ExecRowMark -
00406  *     runtime representation of FOR [KEY] UPDATE/SHARE clauses
00407  *
00408  * When doing UPDATE, DELETE, or SELECT FOR [KEY] UPDATE/SHARE, we should have an
00409  * ExecRowMark for each non-target relation in the query (except inheritance
00410  * parent RTEs, which can be ignored at runtime).  See PlanRowMark for details
00411  * about most of the fields.  In addition to fields directly derived from
00412  * PlanRowMark, we store curCtid, which is used by the WHERE CURRENT OF code.
00413  *
00414  * EState->es_rowMarks is a list of these structs.
00415  */
00416 typedef struct ExecRowMark
00417 {
00418     Relation    relation;       /* opened and suitably locked relation */
00419     Index       rti;            /* its range table index */
00420     Index       prti;           /* parent range table index, if child */
00421     Index       rowmarkId;      /* unique identifier for resjunk columns */
00422     RowMarkType markType;       /* see enum in nodes/plannodes.h */
00423     bool        noWait;         /* NOWAIT option */
00424     ItemPointerData curCtid;    /* ctid of currently locked tuple, if any */
00425 } ExecRowMark;
00426 
00427 /*
00428  * ExecAuxRowMark -
00429  *     additional runtime representation of FOR [KEY] UPDATE/SHARE clauses
00430  *
00431  * Each LockRows and ModifyTable node keeps a list of the rowmarks it needs to
00432  * deal with.  In addition to a pointer to the related entry in es_rowMarks,
00433  * this struct carries the column number(s) of the resjunk columns associated
00434  * with the rowmark (see comments for PlanRowMark for more detail).  In the
00435  * case of ModifyTable, there has to be a separate ExecAuxRowMark list for
00436  * each child plan, because the resjunk columns could be at different physical
00437  * column positions in different subplans.
00438  */
00439 typedef struct ExecAuxRowMark
00440 {
00441     ExecRowMark *rowmark;       /* related entry in es_rowMarks */
00442     AttrNumber  ctidAttNo;      /* resno of ctid junk attribute, if any */
00443     AttrNumber  toidAttNo;      /* resno of tableoid junk attribute, if any */
00444     AttrNumber  wholeAttNo;     /* resno of whole-row junk attribute, if any */
00445 } ExecAuxRowMark;
00446 
00447 
00448 /* ----------------------------------------------------------------
00449  *               Tuple Hash Tables
00450  *
00451  * All-in-memory tuple hash tables are used for a number of purposes.
00452  *
00453  * Note: tab_hash_funcs are for the key datatype(s) stored in the table,
00454  * and tab_eq_funcs are non-cross-type equality operators for those types.
00455  * Normally these are the only functions used, but FindTupleHashEntry()
00456  * supports searching a hashtable using cross-data-type hashing.  For that,
00457  * the caller must supply hash functions for the LHS datatype as well as
00458  * the cross-type equality operators to use.  in_hash_funcs and cur_eq_funcs
00459  * are set to point to the caller's function arrays while doing such a search.
00460  * During LookupTupleHashEntry(), they point to tab_hash_funcs and
00461  * tab_eq_funcs respectively.
00462  * ----------------------------------------------------------------
00463  */
00464 typedef struct TupleHashEntryData *TupleHashEntry;
00465 typedef struct TupleHashTableData *TupleHashTable;
00466 
00467 typedef struct TupleHashEntryData
00468 {
00469     /* firstTuple must be the first field in this struct! */
00470     MinimalTuple firstTuple;    /* copy of first tuple in this group */
00471     /* there may be additional data beyond the end of this struct */
00472 } TupleHashEntryData;           /* VARIABLE LENGTH STRUCT */
00473 
00474 typedef struct TupleHashTableData
00475 {
00476     HTAB       *hashtab;        /* underlying dynahash table */
00477     int         numCols;        /* number of columns in lookup key */
00478     AttrNumber *keyColIdx;      /* attr numbers of key columns */
00479     FmgrInfo   *tab_hash_funcs; /* hash functions for table datatype(s) */
00480     FmgrInfo   *tab_eq_funcs;   /* equality functions for table datatype(s) */
00481     MemoryContext tablecxt;     /* memory context containing table */
00482     MemoryContext tempcxt;      /* context for function evaluations */
00483     Size        entrysize;      /* actual size to make each hash entry */
00484     TupleTableSlot *tableslot;  /* slot for referencing table entries */
00485     /* The following fields are set transiently for each table search: */
00486     TupleTableSlot *inputslot;  /* current input tuple's slot */
00487     FmgrInfo   *in_hash_funcs;  /* hash functions for input datatype(s) */
00488     FmgrInfo   *cur_eq_funcs;   /* equality functions for input vs. table */
00489 }   TupleHashTableData;
00490 
00491 typedef HASH_SEQ_STATUS TupleHashIterator;
00492 
00493 /*
00494  * Use InitTupleHashIterator/TermTupleHashIterator for a read/write scan.
00495  * Use ResetTupleHashIterator if the table can be frozen (in this case no
00496  * explicit scan termination is needed).
00497  */
00498 #define InitTupleHashIterator(htable, iter) \
00499     hash_seq_init(iter, (htable)->hashtab)
00500 #define TermTupleHashIterator(iter) \
00501     hash_seq_term(iter)
00502 #define ResetTupleHashIterator(htable, iter) \
00503     do { \
00504         hash_freeze((htable)->hashtab); \
00505         hash_seq_init(iter, (htable)->hashtab); \
00506     } while (0)
00507 #define ScanTupleHashTable(iter) \
00508     ((TupleHashEntry) hash_seq_search(iter))
00509 
00510 
00511 /* ----------------------------------------------------------------
00512  *               Expression State Trees
00513  *
00514  * Each executable expression tree has a parallel ExprState tree.
00515  *
00516  * Unlike PlanState, there is not an exact one-for-one correspondence between
00517  * ExprState node types and Expr node types.  Many Expr node types have no
00518  * need for node-type-specific run-time state, and so they can use plain
00519  * ExprState or GenericExprState as their associated ExprState node type.
00520  * ----------------------------------------------------------------
00521  */
00522 
00523 /* ----------------
00524  *      ExprState node
00525  *
00526  * ExprState is the common superclass for all ExprState-type nodes.
00527  *
00528  * It can also be instantiated directly for leaf Expr nodes that need no
00529  * local run-time state (such as Var, Const, or Param).
00530  *
00531  * To save on dispatch overhead, each ExprState node contains a function
00532  * pointer to the routine to execute to evaluate the node.
00533  * ----------------
00534  */
00535 
00536 typedef struct ExprState ExprState;
00537 
00538 typedef Datum (*ExprStateEvalFunc) (ExprState *expression,
00539                                                 ExprContext *econtext,
00540                                                 bool *isNull,
00541                                                 ExprDoneCond *isDone);
00542 
00543 struct ExprState
00544 {
00545     NodeTag     type;
00546     Expr       *expr;           /* associated Expr node */
00547     ExprStateEvalFunc evalfunc; /* routine to run to execute node */
00548 };
00549 
00550 /* ----------------
00551  *      GenericExprState node
00552  *
00553  * This is used for Expr node types that need no local run-time state,
00554  * but have one child Expr node.
00555  * ----------------
00556  */
00557 typedef struct GenericExprState
00558 {
00559     ExprState   xprstate;
00560     ExprState  *arg;            /* state of my child node */
00561 } GenericExprState;
00562 
00563 /* ----------------
00564  *      WholeRowVarExprState node
00565  * ----------------
00566  */
00567 typedef struct WholeRowVarExprState
00568 {
00569     ExprState   xprstate;
00570     struct PlanState *parent;   /* parent PlanState, or NULL if none */
00571     JunkFilter *wrv_junkFilter; /* JunkFilter to remove resjunk cols */
00572 } WholeRowVarExprState;
00573 
00574 /* ----------------
00575  *      AggrefExprState node
00576  * ----------------
00577  */
00578 typedef struct AggrefExprState
00579 {
00580     ExprState   xprstate;
00581     List       *args;           /* states of argument expressions */
00582     int         aggno;          /* ID number for agg within its plan node */
00583 } AggrefExprState;
00584 
00585 /* ----------------
00586  *      WindowFuncExprState node
00587  * ----------------
00588  */
00589 typedef struct WindowFuncExprState
00590 {
00591     ExprState   xprstate;
00592     List       *args;           /* states of argument expressions */
00593     int         wfuncno;        /* ID number for wfunc within its plan node */
00594 } WindowFuncExprState;
00595 
00596 /* ----------------
00597  *      ArrayRefExprState node
00598  *
00599  * Note: array types can be fixed-length (typlen > 0), but only when the
00600  * element type is itself fixed-length.  Otherwise they are varlena structures
00601  * and have typlen = -1.  In any case, an array type is never pass-by-value.
00602  * ----------------
00603  */
00604 typedef struct ArrayRefExprState
00605 {
00606     ExprState   xprstate;
00607     List       *refupperindexpr;    /* states for child nodes */
00608     List       *reflowerindexpr;
00609     ExprState  *refexpr;
00610     ExprState  *refassgnexpr;
00611     int16       refattrlength;  /* typlen of array type */
00612     int16       refelemlength;  /* typlen of the array element type */
00613     bool        refelembyval;   /* is the element type pass-by-value? */
00614     char        refelemalign;   /* typalign of the element type */
00615 } ArrayRefExprState;
00616 
00617 /* ----------------
00618  *      FuncExprState node
00619  *
00620  * Although named for FuncExpr, this is also used for OpExpr, DistinctExpr,
00621  * and NullIf nodes; be careful to check what xprstate.expr is actually
00622  * pointing at!
00623  * ----------------
00624  */
00625 typedef struct FuncExprState
00626 {
00627     ExprState   xprstate;
00628     List       *args;           /* states of argument expressions */
00629 
00630     /*
00631      * Function manager's lookup info for the target function.  If func.fn_oid
00632      * is InvalidOid, we haven't initialized it yet (nor any of the following
00633      * fields).
00634      */
00635     FmgrInfo    func;
00636 
00637     /*
00638      * For a set-returning function (SRF) that returns a tuplestore, we keep
00639      * the tuplestore here and dole out the result rows one at a time. The
00640      * slot holds the row currently being returned.
00641      */
00642     Tuplestorestate *funcResultStore;
00643     TupleTableSlot *funcResultSlot;
00644 
00645     /*
00646      * In some cases we need to compute a tuple descriptor for the function's
00647      * output.  If so, it's stored here.
00648      */
00649     TupleDesc   funcResultDesc;
00650     bool        funcReturnsTuple;       /* valid when funcResultDesc isn't
00651                                          * NULL */
00652 
00653     /*
00654      * setArgsValid is true when we are evaluating a set-returning function
00655      * that uses value-per-call mode and we are in the middle of a call
00656      * series; we want to pass the same argument values to the function again
00657      * (and again, until it returns ExprEndResult).  This indicates that
00658      * fcinfo_data already contains valid argument data.
00659      */
00660     bool        setArgsValid;
00661 
00662     /*
00663      * Flag to remember whether we found a set-valued argument to the
00664      * function. This causes the function result to be a set as well. Valid
00665      * only when setArgsValid is true or funcResultStore isn't NULL.
00666      */
00667     bool        setHasSetArg;   /* some argument returns a set */
00668 
00669     /*
00670      * Flag to remember whether we have registered a shutdown callback for
00671      * this FuncExprState.  We do so only if funcResultStore or setArgsValid
00672      * has been set at least once (since all the callback is for is to release
00673      * the tuplestore or clear setArgsValid).
00674      */
00675     bool        shutdown_reg;   /* a shutdown callback is registered */
00676 
00677     /*
00678      * Call parameter structure for the function.  This has been initialized
00679      * (by InitFunctionCallInfoData) if func.fn_oid is valid.  It also saves
00680      * argument values between calls, when setArgsValid is true.
00681      */
00682     FunctionCallInfoData fcinfo_data;
00683 } FuncExprState;
00684 
00685 /* ----------------
00686  *      ScalarArrayOpExprState node
00687  *
00688  * This is a FuncExprState plus some additional data.
00689  * ----------------
00690  */
00691 typedef struct ScalarArrayOpExprState
00692 {
00693     FuncExprState fxprstate;
00694     /* Cached info about array element type */
00695     Oid         element_type;
00696     int16       typlen;
00697     bool        typbyval;
00698     char        typalign;
00699 } ScalarArrayOpExprState;
00700 
00701 /* ----------------
00702  *      BoolExprState node
00703  * ----------------
00704  */
00705 typedef struct BoolExprState
00706 {
00707     ExprState   xprstate;
00708     List       *args;           /* states of argument expression(s) */
00709 } BoolExprState;
00710 
00711 /* ----------------
00712  *      SubPlanState node
00713  * ----------------
00714  */
00715 typedef struct SubPlanState
00716 {
00717     ExprState   xprstate;
00718     struct PlanState *planstate;    /* subselect plan's state tree */
00719     ExprState  *testexpr;       /* state of combining expression */
00720     List       *args;           /* states of argument expression(s) */
00721     HeapTuple   curTuple;       /* copy of most recent tuple from subplan */
00722     Datum       curArray;       /* most recent array from ARRAY() subplan */
00723     /* these are used when hashing the subselect's output: */
00724     ProjectionInfo *projLeft;   /* for projecting lefthand exprs */
00725     ProjectionInfo *projRight;  /* for projecting subselect output */
00726     TupleHashTable hashtable;   /* hash table for no-nulls subselect rows */
00727     TupleHashTable hashnulls;   /* hash table for rows with null(s) */
00728     bool        havehashrows;   /* TRUE if hashtable is not empty */
00729     bool        havenullrows;   /* TRUE if hashnulls is not empty */
00730     MemoryContext hashtablecxt; /* memory context containing hash tables */
00731     MemoryContext hashtempcxt;  /* temp memory context for hash tables */
00732     ExprContext *innerecontext; /* econtext for computing inner tuples */
00733     AttrNumber *keyColIdx;      /* control data for hash tables */
00734     FmgrInfo   *tab_hash_funcs; /* hash functions for table datatype(s) */
00735     FmgrInfo   *tab_eq_funcs;   /* equality functions for table datatype(s) */
00736     FmgrInfo   *lhs_hash_funcs; /* hash functions for lefthand datatype(s) */
00737     FmgrInfo   *cur_eq_funcs;   /* equality functions for LHS vs. table */
00738 } SubPlanState;
00739 
00740 /* ----------------
00741  *      AlternativeSubPlanState node
00742  * ----------------
00743  */
00744 typedef struct AlternativeSubPlanState
00745 {
00746     ExprState   xprstate;
00747     List       *subplans;       /* states of alternative subplans */
00748     int         active;         /* list index of the one we're using */
00749 } AlternativeSubPlanState;
00750 
00751 /* ----------------
00752  *      FieldSelectState node
00753  * ----------------
00754  */
00755 typedef struct FieldSelectState
00756 {
00757     ExprState   xprstate;
00758     ExprState  *arg;            /* input expression */
00759     TupleDesc   argdesc;        /* tupdesc for most recent input */
00760 } FieldSelectState;
00761 
00762 /* ----------------
00763  *      FieldStoreState node
00764  * ----------------
00765  */
00766 typedef struct FieldStoreState
00767 {
00768     ExprState   xprstate;
00769     ExprState  *arg;            /* input tuple value */
00770     List       *newvals;        /* new value(s) for field(s) */
00771     TupleDesc   argdesc;        /* tupdesc for most recent input */
00772 } FieldStoreState;
00773 
00774 /* ----------------
00775  *      CoerceViaIOState node
00776  * ----------------
00777  */
00778 typedef struct CoerceViaIOState
00779 {
00780     ExprState   xprstate;
00781     ExprState  *arg;            /* input expression */
00782     FmgrInfo    outfunc;        /* lookup info for source output function */
00783     FmgrInfo    infunc;         /* lookup info for result input function */
00784     Oid         intypioparam;   /* argument needed for input function */
00785 } CoerceViaIOState;
00786 
00787 /* ----------------
00788  *      ArrayCoerceExprState node
00789  * ----------------
00790  */
00791 typedef struct ArrayCoerceExprState
00792 {
00793     ExprState   xprstate;
00794     ExprState  *arg;            /* input array value */
00795     Oid         resultelemtype; /* element type of result array */
00796     FmgrInfo    elemfunc;       /* lookup info for element coercion function */
00797     /* use struct pointer to avoid including array.h here */
00798     struct ArrayMapState *amstate;      /* workspace for array_map */
00799 } ArrayCoerceExprState;
00800 
00801 /* ----------------
00802  *      ConvertRowtypeExprState node
00803  * ----------------
00804  */
00805 typedef struct ConvertRowtypeExprState
00806 {
00807     ExprState   xprstate;
00808     ExprState  *arg;            /* input tuple value */
00809     TupleDesc   indesc;         /* tupdesc for source rowtype */
00810     TupleDesc   outdesc;        /* tupdesc for result rowtype */
00811     /* use "struct" so we needn't include tupconvert.h here */
00812     struct TupleConversionMap *map;
00813     bool        initialized;
00814 } ConvertRowtypeExprState;
00815 
00816 /* ----------------
00817  *      CaseExprState node
00818  * ----------------
00819  */
00820 typedef struct CaseExprState
00821 {
00822     ExprState   xprstate;
00823     ExprState  *arg;            /* implicit equality comparison argument */
00824     List       *args;           /* the arguments (list of WHEN clauses) */
00825     ExprState  *defresult;      /* the default result (ELSE clause) */
00826 } CaseExprState;
00827 
00828 /* ----------------
00829  *      CaseWhenState node
00830  * ----------------
00831  */
00832 typedef struct CaseWhenState
00833 {
00834     ExprState   xprstate;
00835     ExprState  *expr;           /* condition expression */
00836     ExprState  *result;         /* substitution result */
00837 } CaseWhenState;
00838 
00839 /* ----------------
00840  *      ArrayExprState node
00841  *
00842  * Note: ARRAY[] expressions always produce varlena arrays, never fixed-length
00843  * arrays.
00844  * ----------------
00845  */
00846 typedef struct ArrayExprState
00847 {
00848     ExprState   xprstate;
00849     List       *elements;       /* states for child nodes */
00850     int16       elemlength;     /* typlen of the array element type */
00851     bool        elembyval;      /* is the element type pass-by-value? */
00852     char        elemalign;      /* typalign of the element type */
00853 } ArrayExprState;
00854 
00855 /* ----------------
00856  *      RowExprState node
00857  * ----------------
00858  */
00859 typedef struct RowExprState
00860 {
00861     ExprState   xprstate;
00862     List       *args;           /* the arguments */
00863     TupleDesc   tupdesc;        /* descriptor for result tuples */
00864 } RowExprState;
00865 
00866 /* ----------------
00867  *      RowCompareExprState node
00868  * ----------------
00869  */
00870 typedef struct RowCompareExprState
00871 {
00872     ExprState   xprstate;
00873     List       *largs;          /* the left-hand input arguments */
00874     List       *rargs;          /* the right-hand input arguments */
00875     FmgrInfo   *funcs;          /* array of comparison function info */
00876     Oid        *collations;     /* array of collations to use */
00877 } RowCompareExprState;
00878 
00879 /* ----------------
00880  *      CoalesceExprState node
00881  * ----------------
00882  */
00883 typedef struct CoalesceExprState
00884 {
00885     ExprState   xprstate;
00886     List       *args;           /* the arguments */
00887 } CoalesceExprState;
00888 
00889 /* ----------------
00890  *      MinMaxExprState node
00891  * ----------------
00892  */
00893 typedef struct MinMaxExprState
00894 {
00895     ExprState   xprstate;
00896     List       *args;           /* the arguments */
00897     FmgrInfo    cfunc;          /* lookup info for comparison func */
00898 } MinMaxExprState;
00899 
00900 /* ----------------
00901  *      XmlExprState node
00902  * ----------------
00903  */
00904 typedef struct XmlExprState
00905 {
00906     ExprState   xprstate;
00907     List       *named_args;     /* ExprStates for named arguments */
00908     List       *args;           /* ExprStates for other arguments */
00909 } XmlExprState;
00910 
00911 /* ----------------
00912  *      NullTestState node
00913  * ----------------
00914  */
00915 typedef struct NullTestState
00916 {
00917     ExprState   xprstate;
00918     ExprState  *arg;            /* input expression */
00919     /* used only if input is of composite type: */
00920     TupleDesc   argdesc;        /* tupdesc for most recent input */
00921 } NullTestState;
00922 
00923 /* ----------------
00924  *      CoerceToDomainState node
00925  * ----------------
00926  */
00927 typedef struct CoerceToDomainState
00928 {
00929     ExprState   xprstate;
00930     ExprState  *arg;            /* input expression */
00931     /* Cached list of constraints that need to be checked */
00932     List       *constraints;    /* list of DomainConstraintState nodes */
00933 } CoerceToDomainState;
00934 
00935 /*
00936  * DomainConstraintState - one item to check during CoerceToDomain
00937  *
00938  * Note: this is just a Node, and not an ExprState, because it has no
00939  * corresponding Expr to link to.  Nonetheless it is part of an ExprState
00940  * tree, so we give it a name following the xxxState convention.
00941  */
00942 typedef enum DomainConstraintType
00943 {
00944     DOM_CONSTRAINT_NOTNULL,
00945     DOM_CONSTRAINT_CHECK
00946 } DomainConstraintType;
00947 
00948 typedef struct DomainConstraintState
00949 {
00950     NodeTag     type;
00951     DomainConstraintType constrainttype;        /* constraint type */
00952     char       *name;           /* name of constraint (for error msgs) */
00953     ExprState  *check_expr;     /* for CHECK, a boolean expression */
00954 } DomainConstraintState;
00955 
00956 
00957 /* ----------------------------------------------------------------
00958  *               Executor State Trees
00959  *
00960  * An executing query has a PlanState tree paralleling the Plan tree
00961  * that describes the plan.
00962  * ----------------------------------------------------------------
00963  */
00964 
00965 /* ----------------
00966  *      PlanState node
00967  *
00968  * We never actually instantiate any PlanState nodes; this is just the common
00969  * abstract superclass for all PlanState-type nodes.
00970  * ----------------
00971  */
00972 typedef struct PlanState
00973 {
00974     NodeTag     type;
00975 
00976     Plan       *plan;           /* associated Plan node */
00977 
00978     EState     *state;          /* at execution time, states of individual
00979                                  * nodes point to one EState for the whole
00980                                  * top-level plan */
00981 
00982     Instrumentation *instrument;    /* Optional runtime stats for this node */
00983 
00984     /*
00985      * Common structural data for all Plan types.  These links to subsidiary
00986      * state trees parallel links in the associated plan tree (except for the
00987      * subPlan list, which does not exist in the plan tree).
00988      */
00989     List       *targetlist;     /* target list to be computed at this node */
00990     List       *qual;           /* implicitly-ANDed qual conditions */
00991     struct PlanState *lefttree; /* input plan tree(s) */
00992     struct PlanState *righttree;
00993     List       *initPlan;       /* Init SubPlanState nodes (un-correlated expr
00994                                  * subselects) */
00995     List       *subPlan;        /* SubPlanState nodes in my expressions */
00996 
00997     /*
00998      * State for management of parameter-change-driven rescanning
00999      */
01000     Bitmapset  *chgParam;       /* set of IDs of changed Params */
01001 
01002     /*
01003      * Other run-time state needed by most if not all node types.
01004      */
01005     TupleTableSlot *ps_ResultTupleSlot; /* slot for my result tuples */
01006     ExprContext *ps_ExprContext;    /* node's expression-evaluation context */
01007     ProjectionInfo *ps_ProjInfo;    /* info for doing tuple projection */
01008     bool        ps_TupFromTlist;/* state flag for processing set-valued
01009                                  * functions in targetlist */
01010 } PlanState;
01011 
01012 /* ----------------
01013  *  these are defined to avoid confusion problems with "left"
01014  *  and "right" and "inner" and "outer".  The convention is that
01015  *  the "left" plan is the "outer" plan and the "right" plan is
01016  *  the inner plan, but these make the code more readable.
01017  * ----------------
01018  */
01019 #define innerPlanState(node)        (((PlanState *)(node))->righttree)
01020 #define outerPlanState(node)        (((PlanState *)(node))->lefttree)
01021 
01022 /* Macros for inline access to certain instrumentation counters */
01023 #define InstrCountFiltered1(node, delta) \
01024     do { \
01025         if (((PlanState *)(node))->instrument) \
01026             ((PlanState *)(node))->instrument->nfiltered1 += (delta); \
01027     } while(0)
01028 #define InstrCountFiltered2(node, delta) \
01029     do { \
01030         if (((PlanState *)(node))->instrument) \
01031             ((PlanState *)(node))->instrument->nfiltered2 += (delta); \
01032     } while(0)
01033 
01034 /*
01035  * EPQState is state for executing an EvalPlanQual recheck on a candidate
01036  * tuple in ModifyTable or LockRows.  The estate and planstate fields are
01037  * NULL if inactive.
01038  */
01039 typedef struct EPQState
01040 {
01041     EState     *estate;         /* subsidiary EState */
01042     PlanState  *planstate;      /* plan state tree ready to be executed */
01043     TupleTableSlot *origslot;   /* original output tuple to be rechecked */
01044     Plan       *plan;           /* plan tree to be executed */
01045     List       *arowMarks;      /* ExecAuxRowMarks (non-locking only) */
01046     int         epqParam;       /* ID of Param to force scan node re-eval */
01047 } EPQState;
01048 
01049 
01050 /* ----------------
01051  *   ResultState information
01052  * ----------------
01053  */
01054 typedef struct ResultState
01055 {
01056     PlanState   ps;             /* its first field is NodeTag */
01057     ExprState  *resconstantqual;
01058     bool        rs_done;        /* are we done? */
01059     bool        rs_checkqual;   /* do we need to check the qual? */
01060 } ResultState;
01061 
01062 /* ----------------
01063  *   ModifyTableState information
01064  * ----------------
01065  */
01066 typedef struct ModifyTableState
01067 {
01068     PlanState   ps;             /* its first field is NodeTag */
01069     CmdType     operation;      /* INSERT, UPDATE, or DELETE */
01070     bool        canSetTag;      /* do we set the command tag/es_processed? */
01071     bool        mt_done;        /* are we done? */
01072     PlanState **mt_plans;       /* subplans (one per target rel) */
01073     int         mt_nplans;      /* number of plans in the array */
01074     int         mt_whichplan;   /* which one is being executed (0..n-1) */
01075     ResultRelInfo *resultRelInfo;       /* per-subplan target relations */
01076     List      **mt_arowmarks;   /* per-subplan ExecAuxRowMark lists */
01077     EPQState    mt_epqstate;    /* for evaluating EvalPlanQual rechecks */
01078     bool        fireBSTriggers; /* do we need to fire stmt triggers? */
01079 } ModifyTableState;
01080 
01081 /* ----------------
01082  *   AppendState information
01083  *
01084  *      nplans          how many plans are in the array
01085  *      whichplan       which plan is being executed (0 .. n-1)
01086  * ----------------
01087  */
01088 typedef struct AppendState
01089 {
01090     PlanState   ps;             /* its first field is NodeTag */
01091     PlanState **appendplans;    /* array of PlanStates for my inputs */
01092     int         as_nplans;
01093     int         as_whichplan;
01094 } AppendState;
01095 
01096 /* ----------------
01097  *   MergeAppendState information
01098  *
01099  *      nplans          how many plans are in the array
01100  *      nkeys           number of sort key columns
01101  *      sortkeys        sort keys in SortSupport representation
01102  *      slots           current output tuple of each subplan
01103  *      heap            heap of active tuples
01104  *      initialized     true if we have fetched first tuple from each subplan
01105  * ----------------
01106  */
01107 typedef struct MergeAppendState
01108 {
01109     PlanState   ps;             /* its first field is NodeTag */
01110     PlanState **mergeplans;     /* array of PlanStates for my inputs */
01111     int         ms_nplans;
01112     int         ms_nkeys;
01113     SortSupport ms_sortkeys;    /* array of length ms_nkeys */
01114     TupleTableSlot **ms_slots;  /* array of length ms_nplans */
01115     struct binaryheap *ms_heap; /* binary heap of slot indices */
01116     bool        ms_initialized; /* are subplans started? */
01117 } MergeAppendState;
01118 
01119 /* ----------------
01120  *   RecursiveUnionState information
01121  *
01122  *      RecursiveUnionState is used for performing a recursive union.
01123  *
01124  *      recursing           T when we're done scanning the non-recursive term
01125  *      intermediate_empty  T if intermediate_table is currently empty
01126  *      working_table       working table (to be scanned by recursive term)
01127  *      intermediate_table  current recursive output (next generation of WT)
01128  * ----------------
01129  */
01130 typedef struct RecursiveUnionState
01131 {
01132     PlanState   ps;             /* its first field is NodeTag */
01133     bool        recursing;
01134     bool        intermediate_empty;
01135     Tuplestorestate *working_table;
01136     Tuplestorestate *intermediate_table;
01137     /* Remaining fields are unused in UNION ALL case */
01138     FmgrInfo   *eqfunctions;    /* per-grouping-field equality fns */
01139     FmgrInfo   *hashfunctions;  /* per-grouping-field hash fns */
01140     MemoryContext tempContext;  /* short-term context for comparisons */
01141     TupleHashTable hashtable;   /* hash table for tuples already seen */
01142     MemoryContext tableContext; /* memory context containing hash table */
01143 } RecursiveUnionState;
01144 
01145 /* ----------------
01146  *   BitmapAndState information
01147  * ----------------
01148  */
01149 typedef struct BitmapAndState
01150 {
01151     PlanState   ps;             /* its first field is NodeTag */
01152     PlanState **bitmapplans;    /* array of PlanStates for my inputs */
01153     int         nplans;         /* number of input plans */
01154 } BitmapAndState;
01155 
01156 /* ----------------
01157  *   BitmapOrState information
01158  * ----------------
01159  */
01160 typedef struct BitmapOrState
01161 {
01162     PlanState   ps;             /* its first field is NodeTag */
01163     PlanState **bitmapplans;    /* array of PlanStates for my inputs */
01164     int         nplans;         /* number of input plans */
01165 } BitmapOrState;
01166 
01167 /* ----------------------------------------------------------------
01168  *               Scan State Information
01169  * ----------------------------------------------------------------
01170  */
01171 
01172 /* ----------------
01173  *   ScanState information
01174  *
01175  *      ScanState extends PlanState for node types that represent
01176  *      scans of an underlying relation.  It can also be used for nodes
01177  *      that scan the output of an underlying plan node --- in that case,
01178  *      only ScanTupleSlot is actually useful, and it refers to the tuple
01179  *      retrieved from the subplan.
01180  *
01181  *      currentRelation    relation being scanned (NULL if none)
01182  *      currentScanDesc    current scan descriptor for scan (NULL if none)
01183  *      ScanTupleSlot      pointer to slot in tuple table holding scan tuple
01184  * ----------------
01185  */
01186 typedef struct ScanState
01187 {
01188     PlanState   ps;             /* its first field is NodeTag */
01189     Relation    ss_currentRelation;
01190     HeapScanDesc ss_currentScanDesc;
01191     TupleTableSlot *ss_ScanTupleSlot;
01192 } ScanState;
01193 
01194 /*
01195  * SeqScan uses a bare ScanState as its state node, since it needs
01196  * no additional fields.
01197  */
01198 typedef ScanState SeqScanState;
01199 
01200 /*
01201  * These structs store information about index quals that don't have simple
01202  * constant right-hand sides.  See comments for ExecIndexBuildScanKeys()
01203  * for discussion.
01204  */
01205 typedef struct
01206 {
01207     ScanKey     scan_key;       /* scankey to put value into */
01208     ExprState  *key_expr;       /* expr to evaluate to get value */
01209     bool        key_toastable;  /* is expr's result a toastable datatype? */
01210 } IndexRuntimeKeyInfo;
01211 
01212 typedef struct
01213 {
01214     ScanKey     scan_key;       /* scankey to put value into */
01215     ExprState  *array_expr;     /* expr to evaluate to get array value */
01216     int         next_elem;      /* next array element to use */
01217     int         num_elems;      /* number of elems in current array value */
01218     Datum      *elem_values;    /* array of num_elems Datums */
01219     bool       *elem_nulls;     /* array of num_elems is-null flags */
01220 } IndexArrayKeyInfo;
01221 
01222 /* ----------------
01223  *   IndexScanState information
01224  *
01225  *      indexqualorig      execution state for indexqualorig expressions
01226  *      ScanKeys           Skey structures for index quals
01227  *      NumScanKeys        number of ScanKeys
01228  *      OrderByKeys        Skey structures for index ordering operators
01229  *      NumOrderByKeys     number of OrderByKeys
01230  *      RuntimeKeys        info about Skeys that must be evaluated at runtime
01231  *      NumRuntimeKeys     number of RuntimeKeys
01232  *      RuntimeKeysReady   true if runtime Skeys have been computed
01233  *      RuntimeContext     expr context for evaling runtime Skeys
01234  *      RelationDesc       index relation descriptor
01235  *      ScanDesc           index scan descriptor
01236  * ----------------
01237  */
01238 typedef struct IndexScanState
01239 {
01240     ScanState   ss;             /* its first field is NodeTag */
01241     List       *indexqualorig;
01242     ScanKey     iss_ScanKeys;
01243     int         iss_NumScanKeys;
01244     ScanKey     iss_OrderByKeys;
01245     int         iss_NumOrderByKeys;
01246     IndexRuntimeKeyInfo *iss_RuntimeKeys;
01247     int         iss_NumRuntimeKeys;
01248     bool        iss_RuntimeKeysReady;
01249     ExprContext *iss_RuntimeContext;
01250     Relation    iss_RelationDesc;
01251     IndexScanDesc iss_ScanDesc;
01252 } IndexScanState;
01253 
01254 /* ----------------
01255  *   IndexOnlyScanState information
01256  *
01257  *      indexqual          execution state for indexqual expressions
01258  *      ScanKeys           Skey structures for index quals
01259  *      NumScanKeys        number of ScanKeys
01260  *      OrderByKeys        Skey structures for index ordering operators
01261  *      NumOrderByKeys     number of OrderByKeys
01262  *      RuntimeKeys        info about Skeys that must be evaluated at runtime
01263  *      NumRuntimeKeys     number of RuntimeKeys
01264  *      RuntimeKeysReady   true if runtime Skeys have been computed
01265  *      RuntimeContext     expr context for evaling runtime Skeys
01266  *      RelationDesc       index relation descriptor
01267  *      ScanDesc           index scan descriptor
01268  *      VMBuffer           buffer in use for visibility map testing, if any
01269  *      HeapFetches        number of tuples we were forced to fetch from heap
01270  * ----------------
01271  */
01272 typedef struct IndexOnlyScanState
01273 {
01274     ScanState   ss;             /* its first field is NodeTag */
01275     List       *indexqual;
01276     ScanKey     ioss_ScanKeys;
01277     int         ioss_NumScanKeys;
01278     ScanKey     ioss_OrderByKeys;
01279     int         ioss_NumOrderByKeys;
01280     IndexRuntimeKeyInfo *ioss_RuntimeKeys;
01281     int         ioss_NumRuntimeKeys;
01282     bool        ioss_RuntimeKeysReady;
01283     ExprContext *ioss_RuntimeContext;
01284     Relation    ioss_RelationDesc;
01285     IndexScanDesc ioss_ScanDesc;
01286     Buffer      ioss_VMBuffer;
01287     long        ioss_HeapFetches;
01288 } IndexOnlyScanState;
01289 
01290 /* ----------------
01291  *   BitmapIndexScanState information
01292  *
01293  *      result             bitmap to return output into, or NULL
01294  *      ScanKeys           Skey structures for index quals
01295  *      NumScanKeys        number of ScanKeys
01296  *      RuntimeKeys        info about Skeys that must be evaluated at runtime
01297  *      NumRuntimeKeys     number of RuntimeKeys
01298  *      ArrayKeys          info about Skeys that come from ScalarArrayOpExprs
01299  *      NumArrayKeys       number of ArrayKeys
01300  *      RuntimeKeysReady   true if runtime Skeys have been computed
01301  *      RuntimeContext     expr context for evaling runtime Skeys
01302  *      RelationDesc       index relation descriptor
01303  *      ScanDesc           index scan descriptor
01304  * ----------------
01305  */
01306 typedef struct BitmapIndexScanState
01307 {
01308     ScanState   ss;             /* its first field is NodeTag */
01309     TIDBitmap  *biss_result;
01310     ScanKey     biss_ScanKeys;
01311     int         biss_NumScanKeys;
01312     IndexRuntimeKeyInfo *biss_RuntimeKeys;
01313     int         biss_NumRuntimeKeys;
01314     IndexArrayKeyInfo *biss_ArrayKeys;
01315     int         biss_NumArrayKeys;
01316     bool        biss_RuntimeKeysReady;
01317     ExprContext *biss_RuntimeContext;
01318     Relation    biss_RelationDesc;
01319     IndexScanDesc biss_ScanDesc;
01320 } BitmapIndexScanState;
01321 
01322 /* ----------------
01323  *   BitmapHeapScanState information
01324  *
01325  *      bitmapqualorig     execution state for bitmapqualorig expressions
01326  *      tbm                bitmap obtained from child index scan(s)
01327  *      tbmiterator        iterator for scanning current pages
01328  *      tbmres             current-page data
01329  *      prefetch_iterator  iterator for prefetching ahead of current page
01330  *      prefetch_pages     # pages prefetch iterator is ahead of current
01331  *      prefetch_target    target prefetch distance
01332  * ----------------
01333  */
01334 typedef struct BitmapHeapScanState
01335 {
01336     ScanState   ss;             /* its first field is NodeTag */
01337     List       *bitmapqualorig;
01338     TIDBitmap  *tbm;
01339     TBMIterator *tbmiterator;
01340     TBMIterateResult *tbmres;
01341     TBMIterator *prefetch_iterator;
01342     int         prefetch_pages;
01343     int         prefetch_target;
01344 } BitmapHeapScanState;
01345 
01346 /* ----------------
01347  *   TidScanState information
01348  *
01349  *      isCurrentOf    scan has a CurrentOfExpr qual
01350  *      NumTids        number of tids in this scan
01351  *      TidPtr         index of currently fetched tid
01352  *      TidList        evaluated item pointers (array of size NumTids)
01353  * ----------------
01354  */
01355 typedef struct TidScanState
01356 {
01357     ScanState   ss;             /* its first field is NodeTag */
01358     List       *tss_tidquals;   /* list of ExprState nodes */
01359     bool        tss_isCurrentOf;
01360     int         tss_NumTids;
01361     int         tss_TidPtr;
01362     int         tss_MarkTidPtr;
01363     ItemPointerData *tss_TidList;
01364     HeapTupleData tss_htup;
01365 } TidScanState;
01366 
01367 /* ----------------
01368  *   SubqueryScanState information
01369  *
01370  *      SubqueryScanState is used for scanning a sub-query in the range table.
01371  *      ScanTupleSlot references the current output tuple of the sub-query.
01372  * ----------------
01373  */
01374 typedef struct SubqueryScanState
01375 {
01376     ScanState   ss;             /* its first field is NodeTag */
01377     PlanState  *subplan;
01378 } SubqueryScanState;
01379 
01380 /* ----------------
01381  *   FunctionScanState information
01382  *
01383  *      Function nodes are used to scan the results of a
01384  *      function appearing in FROM (typically a function returning set).
01385  *
01386  *      eflags              node's capability flags
01387  *      tupdesc             expected return tuple description
01388  *      tuplestorestate     private state of tuplestore.c
01389  *      funcexpr            state for function expression being evaluated
01390  * ----------------
01391  */
01392 typedef struct FunctionScanState
01393 {
01394     ScanState   ss;             /* its first field is NodeTag */
01395     int         eflags;
01396     TupleDesc   tupdesc;
01397     Tuplestorestate *tuplestorestate;
01398     ExprState  *funcexpr;
01399 } FunctionScanState;
01400 
01401 /* ----------------
01402  *   ValuesScanState information
01403  *
01404  *      ValuesScan nodes are used to scan the results of a VALUES list
01405  *
01406  *      rowcontext          per-expression-list context
01407  *      exprlists           array of expression lists being evaluated
01408  *      array_len           size of array
01409  *      curr_idx            current array index (0-based)
01410  *      marked_idx          marked position (for mark/restore)
01411  *
01412  *  Note: ss.ps.ps_ExprContext is used to evaluate any qual or projection
01413  *  expressions attached to the node.  We create a second ExprContext,
01414  *  rowcontext, in which to build the executor expression state for each
01415  *  Values sublist.  Resetting this context lets us get rid of expression
01416  *  state for each row, avoiding major memory leakage over a long values list.
01417  * ----------------
01418  */
01419 typedef struct ValuesScanState
01420 {
01421     ScanState   ss;             /* its first field is NodeTag */
01422     ExprContext *rowcontext;
01423     List      **exprlists;
01424     int         array_len;
01425     int         curr_idx;
01426     int         marked_idx;
01427 } ValuesScanState;
01428 
01429 /* ----------------
01430  *   CteScanState information
01431  *
01432  *      CteScan nodes are used to scan a CommonTableExpr query.
01433  *
01434  * Multiple CteScan nodes can read out from the same CTE query.  We use
01435  * a tuplestore to hold rows that have been read from the CTE query but
01436  * not yet consumed by all readers.
01437  * ----------------
01438  */
01439 typedef struct CteScanState
01440 {
01441     ScanState   ss;             /* its first field is NodeTag */
01442     int         eflags;         /* capability flags to pass to tuplestore */
01443     int         readptr;        /* index of my tuplestore read pointer */
01444     PlanState  *cteplanstate;   /* PlanState for the CTE query itself */
01445     /* Link to the "leader" CteScanState (possibly this same node) */
01446     struct CteScanState *leader;
01447     /* The remaining fields are only valid in the "leader" CteScanState */
01448     Tuplestorestate *cte_table; /* rows already read from the CTE query */
01449     bool        eof_cte;        /* reached end of CTE query? */
01450 } CteScanState;
01451 
01452 /* ----------------
01453  *   WorkTableScanState information
01454  *
01455  *      WorkTableScan nodes are used to scan the work table created by
01456  *      a RecursiveUnion node.  We locate the RecursiveUnion node
01457  *      during executor startup.
01458  * ----------------
01459  */
01460 typedef struct WorkTableScanState
01461 {
01462     ScanState   ss;             /* its first field is NodeTag */
01463     RecursiveUnionState *rustate;
01464 } WorkTableScanState;
01465 
01466 /* ----------------
01467  *   ForeignScanState information
01468  *
01469  *      ForeignScan nodes are used to scan foreign-data tables.
01470  * ----------------
01471  */
01472 typedef struct ForeignScanState
01473 {
01474     ScanState   ss;             /* its first field is NodeTag */
01475     /* use struct pointer to avoid including fdwapi.h here */
01476     struct FdwRoutine *fdwroutine;
01477     void       *fdw_state;      /* foreign-data wrapper can keep state here */
01478 } ForeignScanState;
01479 
01480 /* ----------------------------------------------------------------
01481  *               Join State Information
01482  * ----------------------------------------------------------------
01483  */
01484 
01485 /* ----------------
01486  *   JoinState information
01487  *
01488  *      Superclass for state nodes of join plans.
01489  * ----------------
01490  */
01491 typedef struct JoinState
01492 {
01493     PlanState   ps;
01494     JoinType    jointype;
01495     List       *joinqual;       /* JOIN quals (in addition to ps.qual) */
01496 } JoinState;
01497 
01498 /* ----------------
01499  *   NestLoopState information
01500  *
01501  *      NeedNewOuter       true if need new outer tuple on next call
01502  *      MatchedOuter       true if found a join match for current outer tuple
01503  *      NullInnerTupleSlot prepared null tuple for left outer joins
01504  * ----------------
01505  */
01506 typedef struct NestLoopState
01507 {
01508     JoinState   js;             /* its first field is NodeTag */
01509     bool        nl_NeedNewOuter;
01510     bool        nl_MatchedOuter;
01511     TupleTableSlot *nl_NullInnerTupleSlot;
01512 } NestLoopState;
01513 
01514 /* ----------------
01515  *   MergeJoinState information
01516  *
01517  *      NumClauses         number of mergejoinable join clauses
01518  *      Clauses            info for each mergejoinable clause
01519  *      JoinState          current state of ExecMergeJoin state machine
01520  *      ExtraMarks         true to issue extra Mark operations on inner scan
01521  *      ConstFalseJoin     true if we have a constant-false joinqual
01522  *      FillOuter          true if should emit unjoined outer tuples anyway
01523  *      FillInner          true if should emit unjoined inner tuples anyway
01524  *      MatchedOuter       true if found a join match for current outer tuple
01525  *      MatchedInner       true if found a join match for current inner tuple
01526  *      OuterTupleSlot     slot in tuple table for cur outer tuple
01527  *      InnerTupleSlot     slot in tuple table for cur inner tuple
01528  *      MarkedTupleSlot    slot in tuple table for marked tuple
01529  *      NullOuterTupleSlot prepared null tuple for right outer joins
01530  *      NullInnerTupleSlot prepared null tuple for left outer joins
01531  *      OuterEContext      workspace for computing outer tuple's join values
01532  *      InnerEContext      workspace for computing inner tuple's join values
01533  * ----------------
01534  */
01535 /* private in nodeMergejoin.c: */
01536 typedef struct MergeJoinClauseData *MergeJoinClause;
01537 
01538 typedef struct MergeJoinState
01539 {
01540     JoinState   js;             /* its first field is NodeTag */
01541     int         mj_NumClauses;
01542     MergeJoinClause mj_Clauses; /* array of length mj_NumClauses */
01543     int         mj_JoinState;
01544     bool        mj_ExtraMarks;
01545     bool        mj_ConstFalseJoin;
01546     bool        mj_FillOuter;
01547     bool        mj_FillInner;
01548     bool        mj_MatchedOuter;
01549     bool        mj_MatchedInner;
01550     TupleTableSlot *mj_OuterTupleSlot;
01551     TupleTableSlot *mj_InnerTupleSlot;
01552     TupleTableSlot *mj_MarkedTupleSlot;
01553     TupleTableSlot *mj_NullOuterTupleSlot;
01554     TupleTableSlot *mj_NullInnerTupleSlot;
01555     ExprContext *mj_OuterEContext;
01556     ExprContext *mj_InnerEContext;
01557 } MergeJoinState;
01558 
01559 /* ----------------
01560  *   HashJoinState information
01561  *
01562  *      hashclauses             original form of the hashjoin condition
01563  *      hj_OuterHashKeys        the outer hash keys in the hashjoin condition
01564  *      hj_InnerHashKeys        the inner hash keys in the hashjoin condition
01565  *      hj_HashOperators        the join operators in the hashjoin condition
01566  *      hj_HashTable            hash table for the hashjoin
01567  *                              (NULL if table not built yet)
01568  *      hj_CurHashValue         hash value for current outer tuple
01569  *      hj_CurBucketNo          regular bucket# for current outer tuple
01570  *      hj_CurSkewBucketNo      skew bucket# for current outer tuple
01571  *      hj_CurTuple             last inner tuple matched to current outer
01572  *                              tuple, or NULL if starting search
01573  *                              (hj_CurXXX variables are undefined if
01574  *                              OuterTupleSlot is empty!)
01575  *      hj_OuterTupleSlot       tuple slot for outer tuples
01576  *      hj_HashTupleSlot        tuple slot for inner (hashed) tuples
01577  *      hj_NullOuterTupleSlot   prepared null tuple for right/full outer joins
01578  *      hj_NullInnerTupleSlot   prepared null tuple for left/full outer joins
01579  *      hj_FirstOuterTupleSlot  first tuple retrieved from outer plan
01580  *      hj_JoinState            current state of ExecHashJoin state machine
01581  *      hj_MatchedOuter         true if found a join match for current outer
01582  *      hj_OuterNotEmpty        true if outer relation known not empty
01583  * ----------------
01584  */
01585 
01586 /* these structs are defined in executor/hashjoin.h: */
01587 typedef struct HashJoinTupleData *HashJoinTuple;
01588 typedef struct HashJoinTableData *HashJoinTable;
01589 
01590 typedef struct HashJoinState
01591 {
01592     JoinState   js;             /* its first field is NodeTag */
01593     List       *hashclauses;    /* list of ExprState nodes */
01594     List       *hj_OuterHashKeys;       /* list of ExprState nodes */
01595     List       *hj_InnerHashKeys;       /* list of ExprState nodes */
01596     List       *hj_HashOperators;       /* list of operator OIDs */
01597     HashJoinTable hj_HashTable;
01598     uint32      hj_CurHashValue;
01599     int         hj_CurBucketNo;
01600     int         hj_CurSkewBucketNo;
01601     HashJoinTuple hj_CurTuple;
01602     TupleTableSlot *hj_OuterTupleSlot;
01603     TupleTableSlot *hj_HashTupleSlot;
01604     TupleTableSlot *hj_NullOuterTupleSlot;
01605     TupleTableSlot *hj_NullInnerTupleSlot;
01606     TupleTableSlot *hj_FirstOuterTupleSlot;
01607     int         hj_JoinState;
01608     bool        hj_MatchedOuter;
01609     bool        hj_OuterNotEmpty;
01610 } HashJoinState;
01611 
01612 
01613 /* ----------------------------------------------------------------
01614  *               Materialization State Information
01615  * ----------------------------------------------------------------
01616  */
01617 
01618 /* ----------------
01619  *   MaterialState information
01620  *
01621  *      materialize nodes are used to materialize the results
01622  *      of a subplan into a temporary file.
01623  *
01624  *      ss.ss_ScanTupleSlot refers to output of underlying plan.
01625  * ----------------
01626  */
01627 typedef struct MaterialState
01628 {
01629     ScanState   ss;             /* its first field is NodeTag */
01630     int         eflags;         /* capability flags to pass to tuplestore */
01631     bool        eof_underlying; /* reached end of underlying plan? */
01632     Tuplestorestate *tuplestorestate;
01633 } MaterialState;
01634 
01635 /* ----------------
01636  *   SortState information
01637  * ----------------
01638  */
01639 typedef struct SortState
01640 {
01641     ScanState   ss;             /* its first field is NodeTag */
01642     bool        randomAccess;   /* need random access to sort output? */
01643     bool        bounded;        /* is the result set bounded? */
01644     int64       bound;          /* if bounded, how many tuples are needed */
01645     bool        sort_Done;      /* sort completed yet? */
01646     bool        bounded_Done;   /* value of bounded we did the sort with */
01647     int64       bound_Done;     /* value of bound we did the sort with */
01648     void       *tuplesortstate; /* private state of tuplesort.c */
01649 } SortState;
01650 
01651 /* ---------------------
01652  *  GroupState information
01653  * -------------------------
01654  */
01655 typedef struct GroupState
01656 {
01657     ScanState   ss;             /* its first field is NodeTag */
01658     FmgrInfo   *eqfunctions;    /* per-field lookup data for equality fns */
01659     bool        grp_done;       /* indicates completion of Group scan */
01660 } GroupState;
01661 
01662 /* ---------------------
01663  *  AggState information
01664  *
01665  *  ss.ss_ScanTupleSlot refers to output of underlying plan.
01666  *
01667  *  Note: ss.ps.ps_ExprContext contains ecxt_aggvalues and
01668  *  ecxt_aggnulls arrays, which hold the computed agg values for the current
01669  *  input group during evaluation of an Agg node's output tuple(s).  We
01670  *  create a second ExprContext, tmpcontext, in which to evaluate input
01671  *  expressions and run the aggregate transition functions.
01672  * -------------------------
01673  */
01674 /* these structs are private in nodeAgg.c: */
01675 typedef struct AggStatePerAggData *AggStatePerAgg;
01676 typedef struct AggStatePerGroupData *AggStatePerGroup;
01677 
01678 typedef struct AggState
01679 {
01680     ScanState   ss;             /* its first field is NodeTag */
01681     List       *aggs;           /* all Aggref nodes in targetlist & quals */
01682     int         numaggs;        /* length of list (could be zero!) */
01683     FmgrInfo   *eqfunctions;    /* per-grouping-field equality fns */
01684     FmgrInfo   *hashfunctions;  /* per-grouping-field hash fns */
01685     AggStatePerAgg peragg;      /* per-Aggref information */
01686     MemoryContext aggcontext;   /* memory context for long-lived data */
01687     ExprContext *tmpcontext;    /* econtext for input expressions */
01688     bool        agg_done;       /* indicates completion of Agg scan */
01689     /* these fields are used in AGG_PLAIN and AGG_SORTED modes: */
01690     AggStatePerGroup pergroup;  /* per-Aggref-per-group working state */
01691     HeapTuple   grp_firstTuple; /* copy of first tuple of current group */
01692     /* these fields are used in AGG_HASHED mode: */
01693     TupleHashTable hashtable;   /* hash table with one entry per group */
01694     TupleTableSlot *hashslot;   /* slot for loading hash table */
01695     List       *hash_needed;    /* list of columns needed in hash table */
01696     bool        table_filled;   /* hash table filled yet? */
01697     TupleHashIterator hashiter; /* for iterating through hash table */
01698 } AggState;
01699 
01700 /* ----------------
01701  *  WindowAggState information
01702  * ----------------
01703  */
01704 /* these structs are private in nodeWindowAgg.c: */
01705 typedef struct WindowStatePerFuncData *WindowStatePerFunc;
01706 typedef struct WindowStatePerAggData *WindowStatePerAgg;
01707 
01708 typedef struct WindowAggState
01709 {
01710     ScanState   ss;             /* its first field is NodeTag */
01711 
01712     /* these fields are filled in by ExecInitExpr: */
01713     List       *funcs;          /* all WindowFunc nodes in targetlist */
01714     int         numfuncs;       /* total number of window functions */
01715     int         numaggs;        /* number that are plain aggregates */
01716 
01717     WindowStatePerFunc perfunc; /* per-window-function information */
01718     WindowStatePerAgg peragg;   /* per-plain-aggregate information */
01719     FmgrInfo   *partEqfunctions;    /* equality funcs for partition columns */
01720     FmgrInfo   *ordEqfunctions; /* equality funcs for ordering columns */
01721     Tuplestorestate *buffer;    /* stores rows of current partition */
01722     int         current_ptr;    /* read pointer # for current */
01723     int64       spooled_rows;   /* total # of rows in buffer */
01724     int64       currentpos;     /* position of current row in partition */
01725     int64       frameheadpos;   /* current frame head position */
01726     int64       frametailpos;   /* current frame tail position */
01727     /* use struct pointer to avoid including windowapi.h here */
01728     struct WindowObjectData *agg_winobj;        /* winobj for aggregate
01729                                                  * fetches */
01730     int64       aggregatedbase; /* start row for current aggregates */
01731     int64       aggregatedupto; /* rows before this one are aggregated */
01732 
01733     int         frameOptions;   /* frame_clause options, see WindowDef */
01734     ExprState  *startOffset;    /* expression for starting bound offset */
01735     ExprState  *endOffset;      /* expression for ending bound offset */
01736     Datum       startOffsetValue;       /* result of startOffset evaluation */
01737     Datum       endOffsetValue; /* result of endOffset evaluation */
01738 
01739     MemoryContext partcontext;  /* context for partition-lifespan data */
01740     MemoryContext aggcontext;   /* context for each aggregate data */
01741     ExprContext *tmpcontext;    /* short-term evaluation context */
01742 
01743     bool        all_first;      /* true if the scan is starting */
01744     bool        all_done;       /* true if the scan is finished */
01745     bool        partition_spooled;      /* true if all tuples in current
01746                                          * partition have been spooled into
01747                                          * tuplestore */
01748     bool        more_partitions;/* true if there's more partitions after this
01749                                  * one */
01750     bool        framehead_valid;/* true if frameheadpos is known up to date
01751                                  * for current row */
01752     bool        frametail_valid;/* true if frametailpos is known up to date
01753                                  * for current row */
01754 
01755     TupleTableSlot *first_part_slot;    /* first tuple of current or next
01756                                          * partition */
01757 
01758     /* temporary slots for tuples fetched back from tuplestore */
01759     TupleTableSlot *agg_row_slot;
01760     TupleTableSlot *temp_slot_1;
01761     TupleTableSlot *temp_slot_2;
01762 } WindowAggState;
01763 
01764 /* ----------------
01765  *   UniqueState information
01766  *
01767  *      Unique nodes are used "on top of" sort nodes to discard
01768  *      duplicate tuples returned from the sort phase.  Basically
01769  *      all it does is compare the current tuple from the subplan
01770  *      with the previously fetched tuple (stored in its result slot).
01771  *      If the two are identical in all interesting fields, then
01772  *      we just fetch another tuple from the sort and try again.
01773  * ----------------
01774  */
01775 typedef struct UniqueState
01776 {
01777     PlanState   ps;             /* its first field is NodeTag */
01778     FmgrInfo   *eqfunctions;    /* per-field lookup data for equality fns */
01779     MemoryContext tempContext;  /* short-term context for comparisons */
01780 } UniqueState;
01781 
01782 /* ----------------
01783  *   HashState information
01784  * ----------------
01785  */
01786 typedef struct HashState
01787 {
01788     PlanState   ps;             /* its first field is NodeTag */
01789     HashJoinTable hashtable;    /* hash table for the hashjoin */
01790     List       *hashkeys;       /* list of ExprState nodes */
01791     /* hashkeys is same as parent's hj_InnerHashKeys */
01792 } HashState;
01793 
01794 /* ----------------
01795  *   SetOpState information
01796  *
01797  *      Even in "sorted" mode, SetOp nodes are more complex than a simple
01798  *      Unique, since we have to count how many duplicates to return.  But
01799  *      we also support hashing, so this is really more like a cut-down
01800  *      form of Agg.
01801  * ----------------
01802  */
01803 /* this struct is private in nodeSetOp.c: */
01804 typedef struct SetOpStatePerGroupData *SetOpStatePerGroup;
01805 
01806 typedef struct SetOpState
01807 {
01808     PlanState   ps;             /* its first field is NodeTag */
01809     FmgrInfo   *eqfunctions;    /* per-grouping-field equality fns */
01810     FmgrInfo   *hashfunctions;  /* per-grouping-field hash fns */
01811     bool        setop_done;     /* indicates completion of output scan */
01812     long        numOutput;      /* number of dups left to output */
01813     MemoryContext tempContext;  /* short-term context for comparisons */
01814     /* these fields are used in SETOP_SORTED mode: */
01815     SetOpStatePerGroup pergroup;    /* per-group working state */
01816     HeapTuple   grp_firstTuple; /* copy of first tuple of current group */
01817     /* these fields are used in SETOP_HASHED mode: */
01818     TupleHashTable hashtable;   /* hash table with one entry per group */
01819     MemoryContext tableContext; /* memory context containing hash table */
01820     bool        table_filled;   /* hash table filled yet? */
01821     TupleHashIterator hashiter; /* for iterating through hash table */
01822 } SetOpState;
01823 
01824 /* ----------------
01825  *   LockRowsState information
01826  *
01827  *      LockRows nodes are used to enforce FOR [KEY] UPDATE/SHARE locking.
01828  * ----------------
01829  */
01830 typedef struct LockRowsState
01831 {
01832     PlanState   ps;             /* its first field is NodeTag */
01833     List       *lr_arowMarks;   /* List of ExecAuxRowMarks */
01834     EPQState    lr_epqstate;    /* for evaluating EvalPlanQual rechecks */
01835 } LockRowsState;
01836 
01837 /* ----------------
01838  *   LimitState information
01839  *
01840  *      Limit nodes are used to enforce LIMIT/OFFSET clauses.
01841  *      They just select the desired subrange of their subplan's output.
01842  *
01843  * offset is the number of initial tuples to skip (0 does nothing).
01844  * count is the number of tuples to return after skipping the offset tuples.
01845  * If no limit count was specified, count is undefined and noCount is true.
01846  * When lstate == LIMIT_INITIAL, offset/count/noCount haven't been set yet.
01847  * ----------------
01848  */
01849 typedef enum
01850 {
01851     LIMIT_INITIAL,              /* initial state for LIMIT node */
01852     LIMIT_RESCAN,               /* rescan after recomputing parameters */
01853     LIMIT_EMPTY,                /* there are no returnable rows */
01854     LIMIT_INWINDOW,             /* have returned a row in the window */
01855     LIMIT_SUBPLANEOF,           /* at EOF of subplan (within window) */
01856     LIMIT_WINDOWEND,            /* stepped off end of window */
01857     LIMIT_WINDOWSTART           /* stepped off beginning of window */
01858 } LimitStateCond;
01859 
01860 typedef struct LimitState
01861 {
01862     PlanState   ps;             /* its first field is NodeTag */
01863     ExprState  *limitOffset;    /* OFFSET parameter, or NULL if none */
01864     ExprState  *limitCount;     /* COUNT parameter, or NULL if none */
01865     int64       offset;         /* current OFFSET value */
01866     int64       count;          /* current COUNT, if any */
01867     bool        noCount;        /* if true, ignore count */
01868     LimitStateCond lstate;      /* state machine status, as above */
01869     int64       position;       /* 1-based index of last tuple returned */
01870     TupleTableSlot *subSlot;    /* tuple last obtained from subplan */
01871 } LimitState;
01872 
01873 #endif   /* EXECNODES_H */