home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre3.z / postgre3 / src / lib / H / nodes / execnodes.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  37.1 KB  |  1,046 lines

  1. /* ----------------------------------------------------------------
  2.  *   FILE
  3.  *      execnodes.h
  4.  *      
  5.  *   DESCRIPTION
  6.  *      definitions for executor state nodes
  7.  *
  8.  *   NOTES
  9.  *      this file is listed in lib/Gen/inherits.sh and in the
  10.  *      INH_SRC list in conf/inh.mk and is used to generate the
  11.  *      obj/lib/C/plannodes.c file
  12.  *
  13.  *   IDENTIFICATION
  14.  *      $Header: /private/postgres/src/lib/H/nodes/RCS/execnodes.h,v 1.62 1992/08/21 05:43:04 mer Exp $
  15.  * ----------------------------------------------------------------
  16.  */
  17.  
  18. #ifndef ExecNodesIncluded
  19. #define ExecNodesIncluded
  20.  
  21. #include "tmp/postgres.h"
  22.  
  23. #include "executor/recursion_a.h" /* recursion stuff that must go first - JRB */
  24. #include "nodes/primnodes.h"
  25. #include "nodes/pg_lisp.h"
  26. #include "nodes/nodes.h"              /* bogus inheritance system */
  27. #include "nodes/execnodes.gen"          /* to get generated accessor macros */
  28. #include "rules/params.h"             /* parameterized plan stuff... */
  29. #include "rules/prs2.h"               /* for the prs2_info field of EState */
  30.  
  31. #include "storage/item.h"
  32. #include "access/sdir.h"
  33. #include "access/htup.h"
  34. #include "access/tupdesc.h"
  35. #include "access/funcindex.h"
  36. #include "utils/rel.h"
  37. #include "access/relscan.h"
  38. #include "executor/hashjoin.h"
  39. #include "executor/tuptable.h"
  40. #include "access/rulescan.h"
  41.  
  42. /* ----------------------------------------------------------------
  43.  *      Node Function Declarations
  44.  *
  45.  *  All of these #defines indicate that we have written print/equal/copy
  46.  *  support for the classes named.  The print routines are in
  47.  *  lib/C/printfuncs.c, the equal functions are in lib/C/equalfincs.c and
  48.  *  the copy functions can be found in lib/C/copyfuncs.c
  49.  *
  50.  *  An interface routine is generated automatically by Gen_creator.sh for
  51.  *  each node type.  This routine will call either do nothing or call
  52.  *  an _print, _equal or _copy function defined in one of the above
  53.  *  files, depending on whether or not the appropriate #define is specified.
  54.  *
  55.  *  Thus, when adding a new node type, you have to add a set of
  56.  *  _print, _equal and _copy functions to the above files and then
  57.  *  add some #defines below.
  58.  *
  59.  *  This is pretty complicated, and a better-designed system needs to be
  60.  *  implemented.
  61.  * ----------------------------------------------------------------
  62.  */
  63.  
  64. #define OutEStateExists
  65.  
  66.  
  67. /* ----------------------------------------------------------------
  68.  *                      Executor Support Types
  69.  * ----------------------------------------------------------------
  70.  */
  71.  
  72. #define abstime AbsoluteTime
  73.  
  74. typedef int     *IntPtr;
  75. typedef void    (*HookFunction)();
  76.  
  77. /* ----------------
  78.  *    IndexInfo information
  79.  *
  80.  *      this class holds the information saying what attributes
  81.  *      are the key attributes for this index. -cim 10/15/89
  82.  *
  83.  *      NumKeyAttributes        number of key attributes for this index
  84.  *      KeyAttributeNumbers     array of attribute numbers used as keys
  85.  * ----------------
  86.  */
  87.  
  88. class (IndexInfo) public (Node) {
  89.     inherits0(Node);
  90.     int                 ii_NumKeyAttributes;
  91.     AttributeNumberPtr  ii_KeyAttributeNumbers;
  92.     FuncIndexInfoPtr    ii_FuncIndexInfo;
  93. };
  94.  
  95. typedef IndexInfo       *IndexInfoPtr;
  96.  
  97. /* ----------------
  98.  *    RelationInfo information
  99.  *
  100.  *      whenever we update an existing relation, we have to
  101.  *      update indices on the relation.  The RelationInfo class
  102.  *      is used to hold all the information on result relations,
  103.  *      including indices.. -cim 10/15/89
  104.  *
  105.  *      RangeTableIndex         result relation's range table index
  106.  *      RelationDesc            relation descriptor for result relation
  107.  *      NumIndices              number indices existing on result relation
  108.  *      IndexRelationDescs      array of relation descriptors for indices
  109.  *      IndexInfoPtr            array of key/attr info for indices
  110.  * ----------------
  111.  */
  112.  
  113. class (RelationInfo) public (Node) {
  114.     inherits0(Node);
  115.     Index               ri_RangeTableIndex;
  116.     Relation            ri_RelationDesc;
  117.     int                 ri_NumIndices;
  118.     RelationPtr         ri_IndexRelationDescs;
  119.     IndexInfoPtr        ri_IndexRelationInfo;
  120. };
  121.  
  122. /* ----------------
  123.  *      TupleCount node information
  124.  *
  125.  *      retrieved       number of tuples seen by ExecRetrieve
  126.  *      appended        number of tuples seen by ExecAppend
  127.  *      deleted         number of tuples seen by ExecDelete
  128.  *      replaced        number of tuples seen by ExecReplace
  129.  *      inserted        number of index tuples inserted
  130.  *      processed       number of tuples processed by the plan
  131.  * ----------------
  132.  */
  133. class (TupleCount) public (Node) {
  134.       inherits0(Node);
  135.   /* private: */
  136.       int       tc_retrieved;
  137.       int       tc_appended;
  138.       int       tc_deleted;
  139.       int       tc_replaced;
  140.       int       tc_inserted;
  141.       int       tc_processed;
  142.   /* public: */
  143. };
  144.  
  145.  
  146. /* ----------------
  147.  *    Note:  the executor tuple table is managed and manipulated by special
  148.  *    code and macros in executor/tuple.c and lib/H/executor/tuptable.h
  149.  *    -cim 1/18/90
  150.  *
  151.  *    TupleTableSlot information
  152.  *
  153.  *        shouldFree        boolean - should we call pfree() on tuple
  154.  *        descIsNew        boolean - true when tupleDescriptor changes
  155.  *        tupleDescriptor    type information kept regarding the tuple data
  156.  *        buffer        the buffer for tuples pointing to disk pages
  157.  *
  158.  *    LispValue information
  159.  *
  160.  *        val.car        pointer to tuple data
  161.  *        cdr            pointer to special info (currenty unused)
  162.  *
  163.  *    The executor stores pointers to tuples in a ``tuple table''
  164.  *    which is composed of TupleTableSlot's.  Some of the tuples
  165.  *    are pointers to buffer pages and others are pointers to
  166.  *    palloc'ed memory and the shouldFree variable tells us when
  167.  *    we may call pfree() on a tuple.  -cim 9/23/90
  168.  *
  169.  *    In the implementation of nested-dot queries such as
  170.  *    "retrieve (EMP.hobbies.all)", a single scan may return tuples
  171.  *    of many types, so now we return pointers to tuple descriptors
  172.  *    along with tuples returned via the tuple table.  -cim 1/18/90
  173.  * ----------------
  174.  */
  175. class (TupleTableSlot) public (LispValue) {
  176.       inherits2(LispValue);
  177.   /* private: */
  178.       bool        ttc_shouldFree;
  179.       bool        ttc_descIsNew;
  180.       TupleDescriptor    ttc_tupleDescriptor;
  181.       ExecTupDescriptor ttc_execTupDescriptor;
  182.       Buffer        ttc_buffer;
  183.       int        ttc_whichplan;
  184.   /* public: */
  185. };
  186.  
  187. /* ----------------
  188.  *    ExprContext
  189.  *
  190.  *      This class holds the "current context" information
  191.  *      needed to evaluate expressions for doing tuple qualifications
  192.  *    and tuple projections.  For example, if an expression refers
  193.  *    to an attribute in the current inner tuple then we need to know
  194.  *    what the current inner tuple is and so we look at the expression
  195.  *    context.
  196.  *
  197.  * old comments:
  198.  *    Most of this information was originally stored in global variables
  199.  *      in the Lisp system.
  200.  *
  201.  *      ExprContexts are stored in CommonState nodes and so
  202.  *      all executor state nodes which inherit from CommonState
  203.  *      have ExprContexts although not all of them need it.
  204.  *      
  205.  *  SOON: ExprContext will contain indexes of tuples in the tupleTable
  206.  *        stored in the EState, rather than pointers which it now stores.
  207.  *        It might still be used to store type/buffer information though.
  208.  *        (I haven't thought that out yet) -cim 6/20/90
  209.  * ----------------
  210.  */
  211. class (ExprContext) public (Node) {
  212. #define ExprContextDefs \
  213.         inherits0(Node); \
  214.         TupleTableSlot ecxt_scantuple; \
  215.         TupleTableSlot ecxt_innertuple; \
  216.         TupleTableSlot ecxt_outertuple; \
  217.         Relation       ecxt_relation; \
  218.         Index          ecxt_relid; \
  219.         ParamListInfo  ecxt_param_list_info; \
  220.         List           ecxt_range_table
  221.  /* private: */
  222.         ExprContextDefs;
  223.  /* public: */
  224. };
  225.  
  226. /* ----------------
  227.  *    ProjectionInfo node information
  228.  *
  229.  *    This is all the information needed to preform projections
  230.  *    on a tuple.  Nodes which need to do projections create one
  231.  *    of these.  In theory, when a node wants to preform a projection
  232.  *    it should just update this information as necessary and then
  233.  *    call ExecProject().  -cim 6/3/91
  234.  *
  235.  *    targetlist    target list for projection
  236.  *    len        length of target list
  237.  *    tupValue    array of pointers to projection results
  238.  *    exprContext    expression context for ExecTargetList
  239.  *    slot        slot to place projection result in
  240.  * ----------------
  241.  */
  242. class (ProjectionInfo) public (Node) {
  243.       inherits0(Node);
  244.   /* private: */
  245.       List          pi_targetlist;
  246.       int          pi_len;
  247.       Pointer             pi_tupValue;
  248.       ExprContext      pi_exprContext;
  249.       TupleTableSlot       pi_slot;
  250.   /* public: */
  251. };
  252.  
  253. /* ----------------
  254.  *    JunkFilter
  255.  *
  256.  *    this class is used to store information regarding junk attributes.
  257.  *    A junk attribute is an attribute in a tuple that is needed only for
  258.  *    storing intermediate information in the executor, and does not belong
  259.  *    in the tuple proper.  For example, when we do a delete or replace
  260.  *    query, the planner adds an entry to the targetlist so that the tuples
  261.  *    returned to ExecutePlan() contain an extra attribute: the t_ctid of
  262.  *    the tuple to be deleted/replaced.  This is needed for amdelete() and
  263.  *    amreplace().  In doing a delete this does not make much of a
  264.  *    difference, but in doing a replace we have to make sure we disgard
  265.  *    all the junk in a tuple before calling amreplace().  Otherwise the
  266.  *    inserted tuple will not have the correct schema.  This solves a
  267.  *    problem with hash-join and merge-sort replace plans.  -cim 10/10/90
  268.  *
  269.  *    targetList:    the original target list (including junk attributes).
  270.  *    length:        the length of 'targetList'.
  271.  *    tupType:        the tuple descriptor for the "original" tuple
  272.  *            (including the junk attributes).
  273.  *    cleanTargetList:    the "clean" target list (junk attributes removed).
  274.  *    cleanLength:    the length of 'cleanTargetList'
  275.  *    cleanTupTyp:    the tuple descriptor of the "clean" tuple (with
  276.  *            junk attributes removed).
  277.  *    cleanMap:        A map with the correspondance between the non junk
  278.  *            attributes of the "original" tuple and the 
  279.  *            attributes of the "clean" tuple.
  280.  * ----------------
  281.  */
  282. class (JunkFilter) public (JunkFilter) {
  283.       inherits0(Node);
  284.   /* private: */
  285.       List            jf_targetList;
  286.       int            jf_length;
  287.       TupleDescriptor        jf_tupType;
  288.       List            jf_cleanTargetList;
  289.       int            jf_cleanLength;
  290.       TupleDescriptor        jf_cleanTupType;
  291.       AttributeNumberPtr    jf_cleanMap;
  292.   /* public: */
  293. };
  294.  
  295. /* ----------------
  296.  *    EState information
  297.  *
  298.  *      direction                       direction of the scan
  299.  *      time                            ?
  300.  *      owner                           ?
  301.  *      locks                           ?
  302.  *      subplan_info                    ?
  303.  *      error_message                   ?
  304.  *
  305.  *      range_table                     array of scan relation information
  306.  *
  307.  *      qualification_tuple             tuple satisifying qualification
  308.  *                    (going away soon)
  309.  *
  310.  *      qualification_tuple_id          tid of qualification_tuple
  311.  *                    (going away soon)
  312.  *
  313.  *      qualification_tuple_buffer      buffer of qualification_tuple
  314.  *                    (going away soon)
  315.  *
  316.  *      raw_qualification_tuple         tuple satsifying qualification
  317.  *                                      but with no rules activated.
  318.  *                    (going away soon)
  319.  *
  320.  *      relation_relation_descriptor    as it says
  321.  *
  322.  *      into_relation_descriptor        relation being retrieved "into"
  323.  *
  324.  *      result_relation_information     for update queries
  325.  *
  326.  *      tuplecount                      summary of tuples processed
  327.  *
  328.  *      param_list_info                 information needed to transform
  329.  *                                      Param nodes into Const nodes
  330.  *
  331.  *      prs2_info                       Information used by the rule
  332.  *                                      manager (for loop detection
  333.  *                                      etc.). Must be initialized to NULL
  334.  *
  335.  *      explain_relation                The relation descriptor of the
  336.  *                                      result relation of an 'explain'
  337.  *                                      command. NULL if this is not
  338.  *                                      an explain command.
  339.  * 
  340.  *      BaseId                          during InitPlan(), each node is
  341.  *                                      given a number.  this is the next
  342.  *                                      number to be assigned.
  343.  *
  344.  *      tupleTable                      this is a pointer to an array
  345.  *                                      of pointers to tuples used by
  346.  *                                      the executor at any given moment.
  347.  *
  348.  *    junkFilter            contains information used to
  349.  *                    extract junk attributes from a tuple.
  350.  *                    (see JunkFilter above)
  351.  *
  352.  *    result_rel_scanstate        points to the scanstate for the
  353.  *                    result relation, if there is one.
  354.  *                    this should be a ScanState but it's
  355.  *                    a Pointer because of order conflicts.
  356.  *
  357.  *    result_rel_ruleinfo        general information
  358.  *                    for the result relation needed
  359.  *                    by the rule manager.
  360.  *    refcount            local buffer refcounts used in
  361.  *                    an ExecMain cycle.  this is introduced
  362.  *                    to avoid ExecMain's unpinning each
  363.  *                    other's buffers when called recursively
  364.  * ----------------    
  365.  */
  366.  
  367. class (EState) public (Node) {
  368.       inherits0(Node);
  369.       ScanDirection     es_direction;
  370.       abstime           es_time;
  371.       ObjectId          es_owner;
  372.       List              es_locks;
  373.       List              es_subplan_info;
  374.       Name              es_error_message;
  375.       List              es_range_table;
  376.       HeapTuple         es_qualification_tuple;
  377.       ItemPointer       es_qualification_tuple_id;
  378.       Buffer        es_qualification_tuple_buffer;
  379.       HeapTuple         es_raw_qualification_tuple;
  380.       Relation          es_relation_relation_descriptor;
  381.       Relation          es_into_relation_descriptor;
  382.       RelationInfo      es_result_relation_info;
  383.       TupleCount        es_tuplecount;
  384.       ParamListInfo     es_param_list_info;
  385.       Prs2EStateInfo    es_prs2_info;
  386.       Relation          es_explain_relation;
  387.       int               es_BaseId;
  388.       TupleTable        es_tupleTable;
  389.       JunkFilter    es_junkFilter;
  390.       Pointer        es_result_rel_scanstate;
  391.       int        es_whichplan;
  392.       List        es_result_relation_info_list;
  393.       List        es_junkFilter_list;
  394.       RelationRuleInfo  es_result_rel_ruleinfo;
  395.       intPtr         es_refcount;
  396. };
  397.  
  398. /* ----------------
  399.  *      Executor Type information needed by plannodes.h
  400.  *
  401.  *|     Note: the bogus classes CommonState and CommonScanState exist only
  402.  *|           because our inheritance system only allows single inheritance
  403.  *|           and we have to have unique slot names.  Hence two or more
  404.  *|           classes which want to have a common slot must ALL inherit
  405.  *|           the slot from some other class.  (This is a big hack to
  406.  *|           allow our classes to share slot names..)
  407.  *|
  408.  *|     Example:
  409.  *|           the class Result and the class NestLoop nodes both want
  410.  *|           a slot called "OuterTuple" so they both have to inherit
  411.  *|           it from some other class.  In this case they inherit
  412.  *|           it from CommonState.  "CommonState" and "CommonScanState" are
  413.  *|           the best names I could come up with for this sort of
  414.  *|           stuff.
  415.  *|
  416.  *|           As a result, many classes have extra slots which they
  417.  *|           don't use.  These slots are denoted (unused) in the
  418.  *|           comment preceeding the class definition.  If you
  419.  *|           comes up with a better idea of a way of doing things
  420.  *|           along these lines, then feel free to make your idea
  421.  *|           known to me.. -cim 10/15/89
  422.  * ----------------
  423.  */
  424.  
  425. /* ----------------
  426.  *   HookNode information
  427.  *
  428.  *      HookNodes are used to attach debugging routines to the plan
  429.  *      at runtime.  The hook functions are passed a pointer
  430.  *      to the node with which they are associated when they are
  431.  *      called.
  432.  *
  433.  *      at_initnode    function called in ExecInitNode when hook is assigned
  434.  *      pre_procnode    function called just before ExecProcNode
  435.  *      pre_endnode     function called just before ExecEndNode
  436.  *      post_initnode   function called just after ExecInitNode
  437.  *      post_procnode   function called just after ExecProcNode
  438.  *      post_endnode    function called just after ExecEndNode
  439.  *      data            pointer to user defined information
  440.  *
  441.  *      Note:  there cannot be a pre_initnode call as this node's
  442.  *              base node is assigned during the initnode processing.
  443.  * ----------------
  444.  */
  445. class (HookNode) public (Node) {
  446. #define HookNodeDefs \
  447.       inherits0(Node); \
  448.       HookFunction      hook_at_initnode; \
  449.       HookFunction      hook_pre_procnode; \
  450.       HookFunction      hook_pre_endnode; \
  451.       HookFunction      hook_post_initnode; \
  452.       HookFunction      hook_post_procnode; \
  453.       HookFunction      hook_post_endnode; \
  454.       Pointer           hook_data
  455.   /* private: */
  456.       HookNodeDefs;
  457.   /* public: */
  458. };
  459.  
  460. /* ----------------------------------------------------------------
  461.  *               Common Executor State Information
  462.  * ----------------------------------------------------------------
  463.  */
  464.  
  465. /* ----------------
  466.  *      BaseNode information
  467.  *
  468.  *      BaseNodes are the fundamental superclass for all the
  469.  *      remaining executor state nodes.  They contain the important
  470.  *      fields:
  471.  *
  472.  *      id              integer used to keep track of other information
  473.  *                      associated with a specific executor state node.
  474.  *
  475.  *    parent        backward pointer to this node's parent node.
  476.  *
  477.  *    parent_state    backward pointer to this node's parent node's
  478.  *            private state.
  479.  *
  480.  *      hook            pointer to this node's hook node, if it exists.  
  481.  *
  482.  *      The id is used to keep track of executor resources and
  483.  *      tuples during the query and the hook is used to attach
  484.  *      debugging information.
  485.  * ----------------
  486.  */
  487. class (BaseNode) public (Node) {
  488. #define BaseNodeDefs \
  489.       inherits0(Node); \
  490.       int               base_id; \
  491.       Pointer        base_parent; \
  492.       Pointer        base_parent_state; \
  493.       HookNode          base_hook
  494.   /* private: */
  495.       BaseNodeDefs;
  496.   /* public: */
  497. };
  498.  
  499. /* ----------------
  500.  *   CommonState information
  501.  *
  502.  *|     this is a bogus class used to hold slots so other
  503.  *|     nodes can inherit them...
  504.  *
  505.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  506.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  507.  *      ExprContext        node's current expression context
  508.  *    ProjInfo       info this node uses to form tuple projections
  509.  *      NumScanAttributes  size of ScanAttributes array
  510.  *      ScanAttributes     attribute numbers of interest in this tuple
  511.  *
  512.  * old comments
  513.  *
  514.  *|     ScanAttributes and NumScanAttributes are new -- they are
  515.  *|     used to keep track of the attribute numbers of attributes
  516.  *|     which are actually inspected by the query so the rule manager
  517.  *|     doesn't have to needlessluy check for rules on attributes
  518.  *|     that won't ever be inspected..
  519.  *|
  520.  *|     -cim 10/15/89
  521.  *|
  522.  *|     ExprContext contains the node's expression context which
  523.  *|     is created and initialized at ExecInit time.  Keeping these
  524.  *|     around reduces memory allocations and allows nodes to refer
  525.  *|     to tuples in other nodes (albeit in a gross fashion). -cim 10/30/89
  526.  *|
  527.  *| *  SOON: ExprContext will contain indexes of tuples in the tupleTable
  528.  *|       stored in the EState, rather than pointers which it now stores.
  529.  *|       -cim 6/20/90
  530.  * ----------------
  531.  */
  532.  
  533. class (CommonState) public (BaseNode) {
  534. #define CommonStateDefs \
  535.       inherits1(BaseNode); \
  536.       TupleTableSlot      cs_OuterTupleSlot; \
  537.       TupleTableSlot      cs_ResultTupleSlot; \
  538.       ExprContext         cs_ExprContext; \
  539.       ProjectionInfo      cs_ProjInfo; \
  540.       int                 cs_NumScanAttributes; \
  541.       AttributeNumberPtr  cs_ScanAttributes; \
  542.       bool                cs_TupFromTlist
  543.   /* private: */
  544.       CommonStateDefs;
  545.   /* public: */
  546. };
  547.  
  548.  
  549. /* ----------------------------------------------------------------
  550.  *               Control Node State Information
  551.  * ----------------------------------------------------------------
  552.  */
  553.  
  554. /* ----------------
  555.  *   ResultState information
  556.  *
  557.  *      Loop               flag which tells us to quit when we
  558.  *                         have already returned a constant tuple.
  559.  *
  560.  *   CommonState information
  561.  *
  562.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  563.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  564.  *      ExprContext        node's current expression context
  565.  *    ProjInfo       info this node uses to form tuple projections
  566.  *      NumScanAttributes  size of ScanAttributes array
  567.  *      ScanAttributes     attribute numbers of interest in this tuple
  568.  * ----------------
  569.  */
  570.  
  571. class (ResultState) public (CommonState) {
  572.    inherits2(CommonState);
  573.    int          rs_Loop;
  574. };
  575.  
  576. /* ----------------
  577.  *   AppendState information
  578.  *
  579.  *      append nodes have this field "unionplans" which is this
  580.  *      list of plans to execute in sequence..  these variables
  581.  *      keep track of things..
  582.  *
  583.  *      whichplan       which plan is being executed
  584.  *      nplans          how many plans are in the list
  585.  *      initialized     array of ExecInitNode() results
  586.  *      rtentries       range table for the current plan
  587.  *
  588.  *   CommonState information
  589.  *
  590.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  591.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  592.  *      ExprContext        node's current expression context
  593.  *    ProjInfo       info this node uses to form tuple projections
  594.  *      NumScanAttributes  size of ScanAttributes array
  595.  *      ScanAttributes     attribute numbers of interest in this tuple
  596.  * ----------------
  597.  */
  598.  
  599. class (AppendState) public (BaseNode) {
  600.     inherits2(CommonState);
  601.     int         as_whichplan;
  602.     int         as_nplans;
  603.     ListPtr     as_initialized;
  604.     List        as_rtentries;
  605. };
  606.  
  607. /* ----------------------------------------------------------------
  608.  *               Scan State Information
  609.  * ----------------------------------------------------------------
  610.  */
  611.  
  612. /* ----------------
  613.  *   CommonScanState information
  614.  *
  615.  *      CommonScanState is a class like CommonState, but is used more
  616.  *      by the nodes like SeqScan and Sort which want to
  617.  *      keep track of an underlying relation.
  618.  *
  619.  *      currentRelation    relation being scanned
  620.  *      currentScanDesc    current scan descriptor for scan
  621.  *      ruleInfo           information needed by the rule manager.
  622.  *      ScanTupleSlot      pointer to slot in tuple table holding scan tuple
  623.  *      RawTupleSlot       used by rule manager to hold original tuple
  624.  *                 before any rules are applied.
  625.  *
  626.  *   CommonState information
  627.  *
  628.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  629.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  630.  *      ExprContext        node's current expression context
  631.  *    ProjInfo       info this node uses to form tuple projections
  632.  *      NumScanAttributes  size of ScanAttributes array
  633.  *      ScanAttributes     attribute numbers of interest in this tuple
  634.  * ----------------
  635.  */
  636.  
  637. class (CommonScanState) public (CommonState) {
  638. #define CommonScanStateDefs \
  639.       inherits2(CommonState); \
  640.       Relation          css_currentRelation; \
  641.       HeapScanDesc      css_currentScanDesc; \
  642.       RelationRuleInfo    css_ruleInfo; \
  643.       TupleTableSlot    css_ScanTupleSlot; \
  644.       TupleTableSlot    css_RawTupleSlot
  645.   /* private: */
  646.       CommonScanStateDefs;
  647.   /* public: */
  648. };
  649.  
  650. /* ----------------
  651.  *   ScanState information
  652.  *
  653.  *      ProcOuterFlag      need to process outer subtree
  654.  *      OldRelId           need for compare for joins if result relid.
  655.  *
  656.  *   CommonScanState information
  657.  *
  658.  *      currentRelation    relation being scanned
  659.  *      currentScanDesc    current scan descriptor for scan
  660.  *      ScanTupleSlot      pointer to slot in tuple table holding scan tuple
  661.  *      ViewTupleSlot       ... holding the view tuple from the rmgr.
  662.  *
  663.  *   CommonState information
  664.  *
  665.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  666.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  667.  *      ExprContext        node's current expression context
  668.  *    ProjInfo       info this node uses to form tuple projections
  669.  *      NumScanAttributes  size of ScanAttributes array
  670.  *      ScanAttributes     attribute numbers of interest in this tuple
  671.  * ----------------
  672.  */
  673.  
  674. class (ScanState) public (CommonScanState) {
  675.       inherits3(CommonScanState);
  676.   /* private: */
  677.       bool                      ss_ProcOuterFlag;
  678.       Index                     ss_OldRelId;
  679.   /* public: */
  680. };
  681.  
  682. class (ScanTempState) public (CommonScanState) {
  683.     inherits3(CommonScanState);
  684. /* private: */
  685.         int         st_whichplan;
  686.         int         st_nplans;
  687. /* public: */
  688. };
  689.  
  690. /* ----------------
  691.  *   IndexScanState information
  692.  *
  693.  *|     index scans don't use CommonScanState because
  694.  *|     the underlying AM abstractions for heap scans and
  695.  *|     index scans are too different..  It would be nice
  696.  *|     if the current abstraction was more useful but ... -cim 10/15/89
  697.  *
  698.  *      IndexPtr           current index in use
  699.  *      NumIndices         number of indices in this scan
  700.  *      ScanKeys           Skey structures to scan index rels
  701.  *      NumScanKeys        array of no of keys in each Skey struct
  702.  *      RuntimeKeyInfo     array of array of flags for Skeys evaled at runtime
  703.  *      RelationDescs      ptr to array of relation descriptors
  704.  *      ScanDescs          ptr to array of scan descriptors
  705.  *
  706.  *   CommonState information
  707.  *
  708.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  709.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  710.  *      ExprContext        node's current expression context
  711.  *    ProjInfo       info this node uses to form tuple projections
  712.  *      NumScanAttributes  size of ScanAttributes array
  713.  *      ScanAttributes     attribute numbers of interest in this tuple
  714.  * ----------------
  715.  */
  716. class (IndexScanState) public (CommonState) {
  717.     inherits2(CommonState);
  718.     int                 iss_NumIndices;
  719.     int                 iss_IndexPtr;
  720.     ScanKeyPtr          iss_ScanKeys;
  721.     IntPtr              iss_NumScanKeys;
  722.     Pointer             iss_RuntimeKeyInfo;
  723.     RelationPtr         iss_RelationDescs;
  724.     IndexScanDescPtr    iss_ScanDescs;
  725. };
  726.  
  727.  
  728. /* ----------------------------------------------------------------
  729.  *               Join State Information
  730.  * ----------------------------------------------------------------
  731.  */
  732.  
  733. /* ----------------
  734.  *   JoinState information
  735.  *
  736.  *   CommonState information
  737.  *
  738.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  739.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  740.  *      ExprContext        node's current expression context
  741.  *    ProjInfo       info this node uses to form tuple projections
  742.  *      NumScanAttributes  size of ScanAttributes array
  743.  *      ScanAttributes     attribute numbers of interest in this tuple
  744.  * ----------------
  745.  */
  746. class (JoinState) public (CommonState) {
  747. #define JoinStateDefs \
  748.     inherits2(CommonState)
  749.   /* private: */
  750.     JoinStateDefs;
  751.   /* public: */
  752. };
  753.  
  754. /* ----------------
  755.  *   NestLoopState information
  756.  *
  757.  *      PortalFlag         Set to enable portals to work.
  758.  *
  759.  *   JoinState information
  760.  *
  761.  *   CommonState information
  762.  *
  763.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  764.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  765.  *      ExprContext        node's current expression context
  766.  *    ProjInfo       info this node uses to form tuple projections
  767.  *      NumScanAttributes  size of ScanAttributes array
  768.  *      ScanAttributes     attribute numbers of interest in this tuple
  769.  * ----------------
  770.  */
  771.  
  772. class (NestLoopState) public (JoinState) {
  773.       inherits3(JoinState);
  774.   /* private: */
  775.       bool         nl_PortalFlag;
  776.   /* public: */
  777. };
  778.  
  779. /* ----------------
  780.  *   MergeJoinState information
  781.  *
  782.  *      OSortopI           outerKey1 sortOp innerKey1 ...
  783.  *      ISortopO           innerkey1 sortOp outerkey1 ...
  784.  *      JoinState          current "state" of join. see executor.h
  785.  *      MarkedTupleSlot    pointer to slot in tuple table for marked tuple
  786.  *
  787.  *   JoinState information
  788.  *
  789.  *   CommonState information
  790.  *
  791.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  792.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  793.  *      ExprContext        node's current expression context
  794.  *    ProjInfo       info this node uses to form tuple projections
  795.  *      NumScanAttributes  size of ScanAttributes array
  796.  *      ScanAttributes     attribute numbers of interest in this tuple
  797.  * ----------------
  798.  */
  799.  
  800. class (MergeJoinState) public (JoinState) {
  801.       inherits3(JoinState);
  802.   /* private: */
  803.       List           mj_OSortopI;
  804.       List           mj_ISortopO;
  805.       int            mj_JoinState;
  806.       TupleTableSlot mj_MarkedTupleSlot;
  807.   /* public: */
  808. };
  809.  
  810. typedef File    *FileP;
  811. typedef char    *charP;
  812.  
  813. /* ----------------
  814.  *   HashJoinState information
  815.  *
  816.  *      hj_HashTable               address of the hash table for the hashjoin
  817.  *    hj_HashTableShmId    shared memory id of hash table
  818.  *      hj_CurBucket               the current hash bucket that we are searching
  819.  *                for matches of the current outer tuple
  820.  *      hj_CurTuple                the current matching inner tuple in the
  821.  *                current hash bucket
  822.  *    hj_CurOTuple        the current matching inner tuple in the
  823.  *                current hash overflow chain
  824.  *      hj_InnerHashKey         the inner hash key in the hashjoin condition
  825.  *    hj_OuterBatches        file descriptors for outer batches
  826.  *    hj_InnerBatches        file descriptors for inner batches
  827.  *    hj_OuterReadPos        current read position of outer batch
  828.  *    hj_OuterReadBlk        current read block of outer batch
  829.  *    hj_OuterTupleSlot       tuple slot for outer tuples
  830.  *      hj_HashTupleSlot        tuple slot for hashed tuples
  831.  *
  832.  *    
  833.  *
  834.  *   JoinState information
  835.  *
  836.  *   CommonState information
  837.  *
  838.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  839.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  840.  *      ExprContext        node's current expression context
  841.  *    ProjInfo       info this node uses to form tuple projections
  842.  *      NumScanAttributes  size of ScanAttributes array
  843.  *      ScanAttributes     attribute numbers of interest in this tuple
  844.  * ----------------
  845.  */
  846.  
  847. class (HashJoinState) public (JoinState) {
  848.       inherits3(JoinState);
  849.   /* private: */
  850.       HashJoinTable     hj_HashTable;
  851.       IpcMemoryId    hj_HashTableShmId;
  852.       HashBucket        hj_CurBucket;
  853.       HeapTuple         hj_CurTuple;
  854.       OverflowTuple    hj_CurOTuple;
  855.       Var               hj_InnerHashKey;
  856.       FileP        hj_OuterBatches;
  857.       FileP        hj_InnerBatches;
  858.       charP        hj_OuterReadPos;
  859.       int        hj_OuterReadBlk;
  860.       Pointer       hj_OuterTupleSlot;
  861.       Pointer       hj_HashTupleSlot;
  862.   /* public: */
  863. };
  864.  
  865.  
  866. /* ----------------------------------------------------------------
  867.  *               Materialization State Information
  868.  * ----------------------------------------------------------------
  869.  */
  870.  
  871. /* ----------------
  872.  *   MaterialState information
  873.  *
  874.  *      materialize nodes are used to materialize the results
  875.  *      of a subplan into a temporary relation.
  876.  *
  877.  *      Flag            indicated whether subplan has been materialized
  878.  *      TempRelation    temporary relation containing result of executing
  879.  *                      the subplan.
  880.  *
  881.  *   CommonScanState information
  882.  *
  883.  *      currentRelation    relation descriptor of sorted relation
  884.  *      currentScanDesc    current scan descriptor for scan
  885.  *      ScanTupleSlot      pointer to slot in tuple table holding scan tuple
  886.  *      ViewTupleSlot       ... holding the view tuple from the rmgr.
  887.  *
  888.  *   CommonState information
  889.  *
  890.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  891.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  892.  *      ExprContext        node's current expression context
  893.  *    ProjInfo       info this node uses to form tuple projections
  894.  *      NumScanAttributes  size of ScanAttributes array
  895.  *      ScanAttributes     attribute numbers of interest in this tuple
  896.  * ----------------
  897.  */
  898.  
  899. class (MaterialState) public (CommonScanState) {
  900.       inherits3(CommonScanState);
  901.   /* private: */
  902.       bool      mat_Flag;
  903.       Relation  mat_TempRelation;
  904.   /* public: */
  905. };
  906.  
  907. /* ---------------------
  908.  *  AggregateState information
  909.  *
  910.  *      aggregate nodes are used to modify and materialize the results
  911.  *      of a subplan into a temporary relation.  Instead of just placing
  912.  *      the tuples in the temp relation, the Agg node retrieves a tuple
  913.  *      from the temp relation using the "by" index if there is one, and
  914.  *      modifies the returned tuple to reflect the changes caused by
  915.  *      aggregation.  When the subplan returns no more tuples, the final
  916.  *      state function is performed, and the temp relation contains the
  917.  *      computed aggregate(s).
  918.  *
  919.  *      Flag            indicated whether aggregate has been materialized
  920.  *      TempRelation    temporary relation containing result of aggregating
  921.  *                      the subplan.
  922.  *      *clause*        *not used until aggregate functions are supported*
  923.  *
  924.  *  CommonScanState information
  925.  *
  926.  *      currentRelation    relation descriptor of sorted relation
  927.  *      currentScanDesc    current scan descriptor for scan
  928.  *      ScanTupleSlot      pointer to slot in tuple table holding scan tuple
  929.  *      ViewTupleSlot       ... holding the view tuple from the rmgr.
  930.  *
  931.  *   CommonState information
  932.  *
  933.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  934.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  935.  *      ExprContext        node's current expression context
  936.  *      ProjInfo           info this node ues to form tuple projections
  937.  *      NumScanAttributes  size of ScanAttributes array
  938.  *      ScanAttributes     attribute numbers of interest in this tuple
  939.  * -------------------------
  940.  */
  941.  
  942. class (AggState) public (CommonScanState) {
  943.     inherits3(CommonScanState);
  944.     /* private: */
  945.      bool      agg_Flag;
  946.      Relation  agg_TempRelation;
  947.     /*public: */
  948. };
  949.  
  950.  
  951. /* ----------------
  952.  *   SortState information
  953.  *
  954.  *|     sort nodes are really just a kind of a scan since
  955.  *|     we implement sorts by retrieveing the entire subplan
  956.  *|     into a temp relation, sorting the temp relation into
  957.  *|     another sorted relation, and then preforming a simple
  958.  *|     unqualified sequential scan on the sorted relation..
  959.  *|     -cim 10/15/89
  960.  *
  961.  *      Flag            indicated whether relation has been sorted
  962.  *      Keys            scan key structures used to keep info on sort keys
  963.  *      TempRelation    temporary relation containing result of executing
  964.  *                      the subplan.
  965.  *
  966.  *   CommonScanState information
  967.  *
  968.  *      currentRelation    relation descriptor of sorted relation
  969.  *      currentScanDesc    current scan descriptor for scan
  970.  *      ScanTupleSlot      pointer to slot in tuple table holding scan tuple
  971.  *      ViewTupleSlot       ... holding the view tuple from the rmgr.
  972.  *
  973.  *   CommonState information
  974.  *
  975.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  976.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  977.  *      ExprContext        node's current expression context
  978.  *    ProjInfo       info this node uses to form tuple projections
  979.  *      NumScanAttributes  size of ScanAttributes array
  980.  *      ScanAttributes     attribute numbers of interest in this tuple
  981.  * ----------------
  982.  */
  983.  
  984. class (SortState) public (CommonScanState) {
  985. #define SortStateDefs \
  986.       inherits3(CommonScanState); \
  987.       bool      sort_Flag; \
  988.       Pointer   sort_Keys; \
  989.       Relation  sort_TempRelation
  990.   /* private: */
  991.       SortStateDefs;
  992.   /* public: */
  993. };
  994.  
  995. /* ----------------
  996.  *   UniqueState information
  997.  *
  998.  *      Unique nodes are used "on top of" sort nodes to discard
  999.  *      duplicate tuples returned from the sort phase.  Basically
  1000.  *      all it does is compare the current tuple from the subplan
  1001.  *      with the previously fetched tuple stored in OuterTuple and
  1002.  *      if the two are identical, then we just fetch another tuple
  1003.  *      from the sort and try again.
  1004.  *
  1005.  *   CommonState information
  1006.  *
  1007.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  1008.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  1009.  *      ExprContext        node's current expression context
  1010.  *    ProjInfo       info this node uses to form tuple projections
  1011.  *      NumScanAttributes  size of ScanAttributes array
  1012.  *      ScanAttributes     attribute numbers of interest in this tuple
  1013.  * ----------------
  1014.  */
  1015.  
  1016. class (UniqueState) public (CommonState) {
  1017.       inherits2(CommonState);
  1018.   /* private: */
  1019.   /* public: */
  1020. };
  1021.  
  1022. /* ----------------
  1023.  *   HashState information
  1024.  *
  1025.  *    hashBatches       file descriptors for the batches
  1026.  *
  1027.  *   CommonState information
  1028.  *
  1029.  *      OuterTupleSlot     pointer to slot containing current "outer" tuple
  1030.  *      ResultTupleSlot    pointer to slot in tuple table for projected tuple
  1031.  *      ExprContext        node's current expression context
  1032.  *    ProjInfo       info this node uses to form tuple projections
  1033.  *      NumScanAttributes  size of ScanAttributes array
  1034.  *      ScanAttributes     attribute numbers of interest in this tuple
  1035.  * ----------------
  1036.  */
  1037.  
  1038. class (HashState) public (CommonState) {
  1039.       inherits2(CommonState);
  1040.   /* private: */
  1041.       FileP        hashBatches;
  1042.   /* public: */
  1043. };
  1044.  
  1045. #endif /* ExecNodesIncluded */
  1046.