]> granicus.if.org Git - postgresql/blobdiff - src/include/nodes/execnodes.h
Spell 'precedes', 'preceding' correctly in various places.
[postgresql] / src / include / nodes / execnodes.h
index 65d35a2977eff9d40fb778d1c3b4403de72faa55..97e76ccdfd5b8b929560fbbbcfd1ab8b257e168a 100644 (file)
@@ -4,10 +4,10 @@
  *       definitions for executor state nodes
  *
  *
- * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: execnodes.h,v 1.50 2000/09/29 18:21:38 tgl Exp $
+ * $Id: execnodes.h,v 1.67 2001/11/21 22:57:01 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -34,7 +34,7 @@
  *             NumKeyAttrs                     number of key attributes for this index
  *                                                     (ie, number of attrs from underlying relation)
  *             KeyAttrNumbers          underlying-rel attribute numbers used as keys
- *             Predicate                       partial-index predicate, or NULL if none
+ *             Predicate                       partial-index predicate, or NIL if none
  *             FuncOid                         OID of function, or InvalidOid if not f. index
  *             FuncInfo                        fmgr lookup data for function, if FuncOid valid
  *             Unique                          is it a unique index?
@@ -46,37 +46,12 @@ typedef struct IndexInfo
        int                     ii_NumIndexAttrs;
        int                     ii_NumKeyAttrs;
        AttrNumber      ii_KeyAttrNumbers[INDEX_MAX_KEYS];
-       Node       *ii_Predicate;
+       List       *ii_Predicate;
        Oid                     ii_FuncOid;
        FmgrInfo        ii_FuncInfo;
        bool            ii_Unique;
 } IndexInfo;
 
-/* ----------------
- *       RelationInfo information
- *
- *             whenever we update an existing relation, we have to
- *             update indices on the relation.  The RelationInfo class
- *             is used to hold all the information on result relations,
- *             including indices.. -cim 10/15/89
- *
- *             RangeTableIndex                 result relation's range table index
- *             RelationDesc                    relation descriptor for result relation
- *             NumIndices                              number indices existing on result relation
- *             IndexRelationDescs              array of relation descriptors for indices
- *             IndexRelationInfo               array of key/attr info for indices
- * ----------------
- */
-typedef struct RelationInfo
-{
-       NodeTag         type;
-       Index           ri_RangeTableIndex;
-       Relation        ri_RelationDesc;
-       int                     ri_NumIndices;
-       RelationPtr ri_IndexRelationDescs;
-       IndexInfo **ri_IndexRelationInfo;
-} RelationInfo;
-
 /* ----------------
  *       ExprContext
  *
@@ -90,7 +65,7 @@ typedef struct RelationInfo
  *     There are two memory contexts associated with an ExprContext:
  *     * ecxt_per_query_memory is a relatively long-lived context (such as
  *       TransactionCommandContext); typically it's the same context the
- *       ExprContext node itself is allocated in.  This context can be
+ *       ExprContext node itself is allocated in.      This context can be
  *       used for purposes such as storing operator/function fcache nodes.
  *     * ecxt_per_tuple_memory is a short-term context for expression results.
  *       As the name suggests, it will typically be reset once per tuple,
@@ -111,13 +86,11 @@ typedef struct ExprContext
        MemoryContext ecxt_per_query_memory;
        MemoryContext ecxt_per_tuple_memory;
        /* Values to substitute for Param nodes in expression */
-       ParamExecData *ecxt_param_exec_vals;    /* for PARAM_EXEC params */
-       ParamListInfo ecxt_param_list_info;             /* for other param types */
+       ParamExecData *ecxt_param_exec_vals;            /* for PARAM_EXEC params */
+       ParamListInfo ecxt_param_list_info; /* for other param types */
        /* Values to substitute for Aggref nodes in expression */
        Datum      *ecxt_aggvalues; /* precomputed values for Aggref nodes */
        bool       *ecxt_aggnulls;      /* null flags for Aggref nodes */
-       /* Range table that Vars in expression refer to --- seldom needed */
-       List       *ecxt_range_table;
 } ExprContext;
 
 /*
@@ -180,7 +153,7 @@ typedef struct ProjectionInfo
  *       in emitted tuples.    For example, when we do an UPDATE query,
  *       the planner adds a "junk" entry to the targetlist so that the tuples
  *       returned to ExecutePlan() contain an extra attribute: the ctid of
- *       the tuple to be updated.  This is needed to do the update, but we
+ *       the tuple to be updated.      This is needed to do the update, but we
  *       don't want the ctid to be part of the stored new tuple!  So, we
  *       apply a "junk filter" to remove the junk attributes and form the
  *       real output tuple.
@@ -191,11 +164,21 @@ typedef struct ProjectionInfo
  *                                             (including the junk attributes).
  *       cleanTargetList:      the "clean" target list (junk attributes removed).
  *       cleanLength:          the length of 'cleanTargetList'
- *       cleanTupTyp         the tuple descriptor of the "clean" tuple (with
+ *       cleanTupType:         the tuple descriptor of the "clean" tuple (with
  *                                             junk attributes removed).
- *       cleanMap:                     A map with the correspondance between the non junk
- *                                             attributes of the "original" tuple and the
- *                                             attributes of the "clean" tuple.
+ *       cleanMap:                     A map with the correspondence between the non-junk
+ *                                             attribute numbers of the "original" tuple and the
+ *                                             attribute numbers of the "clean" tuple.
+ *       junkContext:          memory context holding the JunkFilter node and all
+ *                                             its subsidiary data structures.
+ *       resultSlot:           tuple slot that can be used to hold cleaned tuple.
+ *
+ * NOTE: the original targetList and tupType are passed to ExecInitJunkFilter,
+ * as is the resultSlot.  These items do not belong to the JunkFilter. All
+ * the other subsidiary structures are created during ExecInitJunkFilter,
+ * and all of them can be freed by deleting the memory context junkContext.
+ * This would not be needed if we had a cleaner approach to managing
+ * query-lifetime data structures...
  * ----------------
  */
 typedef struct JunkFilter
@@ -208,8 +191,43 @@ typedef struct JunkFilter
        int                     jf_cleanLength;
        TupleDesc       jf_cleanTupType;
        AttrNumber *jf_cleanMap;
+       MemoryContext jf_junkContext;
+       TupleTableSlot *jf_resultSlot;
 } JunkFilter;
 
+/* ----------------
+ *       ResultRelInfo information
+ *
+ *             Whenever we update an existing relation, we have to
+ *             update indices on the relation, and perhaps also fire triggers.
+ *             The ResultRelInfo class is used to hold all the information needed
+ *             about a result relation, including indices.. -cim 10/15/89
+ *
+ *             RangeTableIndex                 result relation's range table index
+ *             RelationDesc                    relation descriptor for result relation
+ *             NumIndices                              # of indices existing on result relation
+ *             IndexRelationDescs              array of relation descriptors for indices
+ *             IndexRelationInfo               array of key/attr info for indices
+ *             TrigDesc                                triggers to be fired, if any
+ *             TrigFunctions                   cached lookup info for trigger functions
+ *             ConstraintExprs                 array of constraint-checking expressions
+ *             junkFilter                              for removing junk attributes from tuples
+ * ----------------
+ */
+typedef struct ResultRelInfo
+{
+       NodeTag         type;
+       Index           ri_RangeTableIndex;
+       Relation        ri_RelationDesc;
+       int                     ri_NumIndices;
+       RelationPtr ri_IndexRelationDescs;
+       IndexInfo **ri_IndexRelationInfo;
+       TriggerDesc *ri_TrigDesc;
+       FmgrInfo   *ri_TrigFunctions;
+       List      **ri_ConstraintExprs;
+       JunkFilter *ri_junkFilter;
+} ResultRelInfo;
+
 /* ----------------
  *       EState information
  *
@@ -217,7 +235,7 @@ typedef struct JunkFilter
  *
  *             range_table                                             array of scan relation information
  *
- *             result_relation_information             for update queries
+ *             result_relation information             for insert/update/delete queries
  *
  *             into_relation_descriptor                relation being retrieved "into"
  *
@@ -227,10 +245,6 @@ typedef struct JunkFilter
  *             tupleTable                                              this is a pointer to an array
  *                                                                             of pointers to tuples used by
  *                                                                             the executor at any given moment.
- *
- *             junkFilter                                              contains information used to
- *                                                                             extract junk attributes from a tuple.
- *                                                                             (see JunkFilter above)
  * ----------------
  */
 typedef struct EState
@@ -239,23 +253,27 @@ typedef struct EState
        ScanDirection es_direction;
        Snapshot        es_snapshot;
        List       *es_range_table;
-       RelationInfo *es_result_relation_info;
+       ResultRelInfo *es_result_relations; /* array of ResultRelInfos */
+       int                     es_num_result_relations;                /* length of array */
+       ResultRelInfo *es_result_relation_info;         /* currently active array
+                                                                                                * elt */
+       JunkFilter *es_junkFilter;      /* currently active junk filter */
        Relation        es_into_relation_descriptor;
        ParamListInfo es_param_list_info;
        ParamExecData *es_param_exec_vals;      /* this is for subselects */
        TupleTable      es_tupleTable;
-       JunkFilter *es_junkFilter;
        uint32          es_processed;   /* # of tuples processed */
        Oid                     es_lastoid;             /* last oid processed (by INSERT) */
        List       *es_rowMark;         /* not good place, but there is no other */
-       MemoryContext es_query_cxt;     /* per-query context in which EState lives */
-       /* this ExprContext is for per-output-tuple operations, such as
-        * constraint checks and index-value computations.  It can be reset
-        * for each output tuple.  Note that it will be created only if needed.
+       MemoryContext es_query_cxt; /* per-query context in which EState lives */
+
+       /*
+        * this ExprContext is for per-output-tuple operations, such as
+        * constraint checks and index-value computations.      It will be reset
+        * for each output tuple.  Note that it will be created only if
+        * needed.
         */
        ExprContext *es_per_tuple_exprcontext;
-       /* this field is storage space for ExecConstraints(): */
-       List      **es_result_relation_constraints;
        /* Below is to re-evaluate plan qual in READ COMMITTED mode */
        struct Plan *es_origPlan;
        Pointer         es_evalPlanQual;
@@ -284,7 +302,7 @@ typedef struct EState
  *|
  *|                      As a result, many classes have extra slots which they
  *|                      don't use.  These slots are denoted (unused) in the
- *|                      comment preceeding the class definition.      If you
+ *|                      comment preceding the class definition.       If you
  *|                      comes up with a better idea of a way of doing things
  *|                      along these lines, then feel free to make your idea
  *|                      known to me.. -cim 10/15/89
@@ -341,27 +359,21 @@ typedef struct ResultState
 /* ----------------
  *      AppendState information
  *
- *             append nodes have this field "unionplans" which is this
- *             list of plans to execute in sequence..  these variables
- *             keep track of things..
- *
- *             whichplan               which plan is being executed
+ *             whichplan               which plan is being executed (0 .. n-1)
+ *             firstplan               first plan to execute (usually 0)
+ *             lastplan                last plan to execute (usually n-1)
  *             nplans                  how many plans are in the list
  *             initialized             array of ExecInitNode() results
- *             rtentries               range table for the current plan
- *             result_relation_info_list  array of each subplan's result relation info
- *             junkFilter_list  array of each subplan's junk filter
  * ----------------
  */
 typedef struct AppendState
 {
        CommonState cstate;                     /* its first field is NodeTag */
        int                     as_whichplan;
+       int                     as_firstplan;
+       int                     as_lastplan;
        int                     as_nplans;
        bool       *as_initialized;
-       List       *as_rtentries;
-       List       *as_result_relation_info_list;
-       List       *as_junkFilter_list;
 } AppendState;
 
 /* ----------------------------------------------------------------
@@ -449,7 +461,7 @@ typedef struct TidScanState
        int                     tss_NumTids;
        int                     tss_TidPtr;
        int                     tss_MarkTidPtr;
-       ItemPointer *tss_TidList;
+       ItemPointerData *tss_TidList;
        HeapTupleData tss_htup;
 } TidScanState;
 
@@ -460,14 +472,12 @@ typedef struct TidScanState
  *             The sub-query will have its own EState, which we save here.
  *             ScanTupleSlot references the current output tuple of the sub-query.
  *
- *             SubQueryDesc       queryDesc for sub-query
  *             SubEState                  exec state for sub-query
  * ----------------
  */
 typedef struct SubqueryScanState
 {
        CommonScanState csstate;        /* its first field is NodeTag */
-       struct QueryDesc *sss_SubQueryDesc;
        EState     *sss_SubEState;
 } SubqueryScanState;
 
@@ -488,8 +498,8 @@ typedef CommonState JoinState;
 /* ----------------
  *      NestLoopState information
  *
- *             NeedNewOuter       true if need new outer tuple on next call
- *             MatchedOuter       true if found a join match for current outer tuple
+ *             NeedNewOuter       true if need new outer tuple on next call
+ *             MatchedOuter       true if found a join match for current outer tuple
  *             NullInnerTupleSlot prepared null tuple for left outer joins
  * ----------------
  */
@@ -507,10 +517,10 @@ typedef struct NestLoopState
  *             OuterSkipQual      outerKey1 < innerKey1 ...
  *             InnerSkipQual      outerKey1 > innerKey1 ...
  *             JoinState                  current "state" of join. see executor.h
- *             MatchedOuter       true if found a join match for current outer tuple
- *             MatchedInner       true if found a join match for current inner tuple
- *             OuterTupleSlot     pointer to slot in tuple table for cur outer tuple
- *             InnerTupleSlot     pointer to slot in tuple table for cur inner tuple
+ *             MatchedOuter       true if found a join match for current outer tuple
+ *             MatchedInner       true if found a join match for current inner tuple
+ *             OuterTupleSlot     pointer to slot in tuple table for cur outer tuple
+ *             InnerTupleSlot     pointer to slot in tuple table for cur inner tuple
  *             MarkedTupleSlot    pointer to slot in tuple table for marked tuple
  *             NullOuterTupleSlot prepared null tuple for right outer joins
  *             NullInnerTupleSlot prepared null tuple for left outer joins
@@ -543,9 +553,9 @@ typedef struct MergeJoinState
  *             hj_InnerHashKey                 the inner hash key in the hashjoin condition
  *             hj_OuterTupleSlot               tuple slot for outer tuples
  *             hj_HashTupleSlot                tuple slot for hashed tuples
- *             hj_NullInnerTupleSlot   prepared null tuple for left outer joins
- *             hj_NeedNewOuter         true if need new outer tuple on next call
- *             hj_MatchedOuter         true if found a join match for current outer
+ *             hj_NullInnerTupleSlot   prepared null tuple for left outer joins
+ *             hj_NeedNewOuter                 true if need new outer tuple on next call
+ *             hj_MatchedOuter                 true if found a join match for current outer
  *             hj_hashdone                             true if hash-table-build phase is done
  * ----------------
  */
@@ -597,7 +607,7 @@ typedef struct MaterialState
  *     during evaluation of an Agg node's output tuple(s).
  * -------------------------
  */
-typedef struct AggStatePerAggData *AggStatePerAgg;     /* private in nodeAgg.c */
+typedef struct AggStatePerAggData *AggStatePerAgg;             /* private in nodeAgg.c */
 
 typedef struct AggState
 {
@@ -605,7 +615,8 @@ typedef struct AggState
        List       *aggs;                       /* all Aggref nodes in targetlist & quals */
        int                     numaggs;                /* length of list (could be zero!) */
        AggStatePerAgg peragg;          /* per-Aggref working state */
-       MemoryContext tup_cxt;          /* context for per-output-tuple expressions */
+       MemoryContext tup_cxt;          /* context for per-output-tuple
+                                                                * expressions */
        MemoryContext agg_cxt[2];       /* pair of expression eval memory contexts */
        int                     which_cxt;              /* 0 or 1, indicates current agg_cxt */
        bool            agg_done;               /* indicates completion of Agg scan */
@@ -628,7 +639,6 @@ typedef struct GroupState
  *      SortState information
  *
  *             sort_Done               indicates whether sort has been performed yet
- *             sort_Keys               scan key structures describing the sort keys
  *             tuplesortstate  private state of tuplesort.c
  * ----------------
  */
@@ -636,7 +646,6 @@ typedef struct SortState
 {
        CommonScanState csstate;        /* its first field is NodeTag */
        bool            sort_Done;
-       ScanKey         sort_Keys;
        void       *tuplesortstate;
 } SortState;
 
@@ -659,6 +668,48 @@ typedef struct UniqueState
        MemoryContext tempContext;      /* short-term context for comparisons */
 } UniqueState;
 
+/* ----------------
+ *      SetOpState information
+ *
+ *             SetOp nodes are used "on top of" sort nodes to discard
+ *             duplicate tuples returned from the sort phase.  These are
+ *             more complex than a simple Unique since we have to count
+ *             how many duplicates to return.
+ * ----------------
+ */
+typedef struct SetOpState
+{
+       CommonState cstate;                     /* its first field is NodeTag */
+       FmgrInfo   *eqfunctions;        /* per-field lookup data for equality fns */
+       bool            subplan_done;   /* has subplan returned EOF? */
+       long            numLeft;                /* number of left-input dups of cur group */
+       long            numRight;               /* number of right-input dups of cur group */
+       long            numOutput;              /* number of dups left to output */
+       MemoryContext tempContext;      /* short-term context for comparisons */
+} SetOpState;
+
+/* ----------------
+ *      LimitState information
+ *
+ *             Limit nodes are used to enforce LIMIT/OFFSET clauses.
+ *             They just select the desired subrange of their subplan's output.
+ *
+ * offset is the number of initial tuples to skip (0 does nothing).
+ * count is the number of tuples to return after skipping the offset tuples.
+ * If no limit count was specified, count is undefined and noCount is true.
+ * ----------------
+ */
+typedef struct LimitState
+{
+       CommonState cstate;                     /* its first field is NodeTag */
+       long            offset;                 /* current OFFSET value */
+       long            count;                  /* current COUNT, if any */
+       long            position;               /* 1-based index of last tuple fetched */
+       bool            parmsSet;               /* have we calculated offset/limit yet? */
+       bool            noCount;                /* if true, ignore count */
+       bool            atEnd;                  /* if true, we've reached EOF of subplan */
+} LimitState;
+
 
 /* ----------------
  *      HashState information
@@ -698,8 +749,7 @@ typedef struct TeeState
        MemoryContext tee_mcxt;
        HeapScanDesc tee_leftScanDesc,
                                tee_rightScanDesc;
-}                      TeeState;
-
+}      TeeState;
 #endif
 
-#endif  /* EXECNODES_H */
+#endif   /* EXECNODES_H */