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

  1. /***********************************************************************
  2.  ** *   Recursion Planner Header (recurplanner.h)                   * **
  3.  ** *           Jimmy Bell                                          * **
  4.  ** *                                                               * **
  5.  ***********************************************************************
  6.  *
  7.  */
  8.  
  9. /* RcsId ("$Header: /private/postgres/src/lib/H/planner/RCS/recurplanner.h,v 1.4 1990/08/18 15:21:57 cimarron Exp $"); */
  10.  
  11. #ifndef RecurPlannerIncluded
  12. #define RecurPlannerIncluded
  13.  
  14. #include "tmp/c.h"                /* for String */
  15.  
  16. #include "executor/recursion_a.h"
  17. #include "nodes/pg_lisp.h"
  18. #include "parser/parse.h"
  19. #include "utils/rel.h"
  20.  
  21. #include "nodes/relation.h"
  22. #include "nodes/relation.a.h"
  23. #include "nodes/plannodes.h"
  24. #include "nodes/plannodes.a.h"
  25. #include "nodes/primnodes.a.h"
  26. #include "executor/execdefs.h"
  27. #include "executor/execmisc.h"
  28.  
  29. #include "planner/planner.h"
  30. #include "planner/clauses.h"
  31. #include "planner/var.h"
  32. #include "planner/prepqual.h"
  33. #include "planner/preptlist.h"
  34.  
  35. #include "executor/recursion.h"
  36.  
  37. /* *** JJJ - remove ? */
  38. /* #include "xcxt.h"  --  for CID in executor */
  39.  
  40. /* extern Plan        planner();        /* in planner.c */
  41. /* extern bool        null();            /* found in pg_lisp.h */
  42. /* extern is_clause();
  43. /* extern and_clause();
  44. /* extern or_clause();
  45. /* extern not_clause();
  46. /* extern member();        /* for atom clause */
  47.  
  48. /* elsewhere ... JJJ - shouldn't need to be here */
  49. extern
  50. LispValue
  51. append1 ARGS((
  52.     LispValue    list,
  53.     LispValue    lispObject
  54. ));
  55.  
  56. typedef List    Qualification;
  57. typedef List    TargetList;
  58. typedef List    QueryDescriptor;
  59. typedef List    ParseTree;
  60. typedef List    RangeTable;
  61. typedef Relid    RelationId;        /* from relation.h */
  62.  
  63. #define ParseTreeGetRoot(parseTree) (List) parse_tree_root(parseTree)
  64. #define ParseTreeGetNumLevels(parseTree) (List) \
  65.     parse_tree_root_num_levels(parse_tree_root(parseTree))
  66. #define ParseTreeGetCommandType(parseTree) (LispValue) \
  67.     parse_tree_root_command_type(parse_tree_root(parseTree))
  68. #define ParseTreeGetTargetList(parseTree) (TargetList) \
  69.     parse_tree_target_list(parseTree)
  70. #define ParseTreeGetQualification(parseTree) (Qualification) \
  71.     parse_tree_qualification(parseTree)
  72. #define ParseTreeGetResultRelation(parseTree) (List) \
  73.     parse_tree_result_relation(parseTree)
  74. #define ParseTreeGetRangeTable(parseTree) (List) \
  75.     parse_tree_range_table(parseTree)
  76.  
  77.  
  78.  
  79. /* used to properly allocate space for a query string */
  80. #define RELATION_NAME_LENGTH 16
  81.  
  82.  
  83. /* Recursive Node containing query plan */
  84.  
  85. extern
  86. Recursive
  87. make_recursive ARGS((
  88.     RecursiveMethod    recursiveMethod,
  89.     Command        command,
  90.     List        initPlans,
  91.     List        loopPlans,
  92.     List        cleanupPlans,
  93.     List        checkpoints
  94. ));
  95.  
  96. /****
  97.  *    functions to facilitate conversions between the internal
  98.  *    form of plans and utility requests (like create FOO) and
  99.  *    their list equivalents.
  100.  */
  101.  
  102. /* either a utility request or a plan */
  103.  
  104. extern
  105. GeneralPlan
  106. PlanOrUtilityToGeneralPlan ARGS((
  107.     bool        isUtility,
  108.     PlanOrUtility    planOrUtility
  109. ));
  110.  
  111. /* List form of General Plan */
  112. extern
  113. List
  114. GeneralPlanToList ARGS((
  115.     GeneralPlan    generalPlan
  116. ));
  117.  
  118. /* General Plan extracted from List form */
  119. extern
  120. GeneralPlan
  121. ListToGeneralPlan ARGS((
  122.     List    list
  123. ));
  124.  
  125. /* containing utility request from string */
  126. extern
  127. GeneralPlan
  128. StringToGeneralPlan ARGS((
  129.     String        str
  130. ));
  131.  
  132. #define PlanToGeneralPlan(plan) PlanOrUtilityToGeneralPlan(false,plan)
  133. #define UtilityToGeneralPlan(utilityRequest) \
  134.     PlanOrUtilityToGeneralPlan(true,utilityRequest)
  135.  
  136. #define PlanToList(Plan) \
  137.         GeneralPlanToList(PlanToGeneralPlan(Plan))
  138. #define UtilityToList(utilityRequest) \
  139.         GeneralPlanToList(UtilityToGeneralPlan(utilityRequest))
  140. #define StringToList(utilityRequest) \
  141.         GeneralPlanToList(StringToGeneralPlan(utilityRequest))
  142.  
  143. /*
  144.  *    end of conversion functions
  145.  *******
  146.  */
  147.  
  148. /*******
  149.  *    functions for checking linearity and verifying recursion
  150.  */
  151.  
  152. /* name of result  relation */
  153. extern
  154. String
  155. ParseTreeGetResultRelationName ARGS((
  156.         ParseTree       parseTree
  157. ));
  158.  
  159. /*
  160.  *    ParseTreeGetVariablesOnResultRelation --
  161.  *        Take short-cut to approximate the number of tuple
  162.  *        var's used to refer to result relation.  I count
  163.  *        occurrences of result's name string in range table.
  164.  */
  165.  
  166. /* number of tuple variables on result relation */
  167. extern
  168. int
  169. ParseTreeGetVariablesOnResultRelation ARGS((
  170.     ParseTree    parseTree
  171. ));
  172.  
  173. /*
  174.  *    RecursiveQueryGetLinearity --
  175.  *        Returns the number of distinct tuple variables in the
  176.  *        query which reference the result relation.  If the user
  177.  *        has not wasted tuple variables, this will be the level
  178.  *        of recursion.  In delete and replace, a tuple variable
  179.  *        is automatically declared for the result relation.
  180.  *        Additional ones for any command are declared with the
  181.  *        "from" clause.
  182.  *
  183.  *    Append* is only recursive if an assignment in the target list or
  184.  *        part of the qualification is based a tuple variable of
  185.  *        the result relation.  If the user references the result
  186.  *        by name or declares tuple variables on it, assume recursive.
  187.  *
  188.  *    Retrieve* is similar.  We assume that the user has referenced
  189.  *        the result relation by name, so if any additional
  190.  *        tuple var's are declared for the result, we assume
  191.  *        non-linearity.
  192.  *
  193.  *    Delete* is recursive only if an aggregate function or rule is
  194.  *        used which is sensitive either to a decrease in the
  195.  *        number of tuples, or to the absence of particular tuples.
  196.  *        The not-in operator is also hole-sensitive.  If one of
  197.  *        these 3 references the result relation, it should be
  198.  *        assumed to be recursive (linear if exactly one tuple var).
  199.  *        We assume that since one provided it is used this way.
  200.  *        In the absence of not-in, this is not supported.
  201.  *
  202.  *    Replace* is assumed to be recursive since mere assignment from
  203.  *        other relations based on a tuples field values can
  204.  *        cause tuples to requalify on the nexxt iteration.  If
  205.  *        additional tuple var's are declared, assumed nonlinear.
  206.  *
  207.  *    Execute* not supported at all.
  208.  */
  209.  
  210. /* 0 if non-recursive, 1 if linear, 2+ if nonlinear */
  211. extern
  212. int
  213. RecursiveQueryGetLinearity ARGS((
  214.     ParseTree    parseTree
  215. ));
  216.  
  217. /*
  218.  *    RecursiveMethodChoose -
  219.  *        Determines which evaluation method to use on a recursive
  220.  *        query.  Chooses between Naive and Seminaive based on a
  221.  *        simplified linearity check.  Signals that the query is
  222.  *        not recursive at all by returning RecursiveMethodNone,
  223.  *        in which case the standard planner will take over.
  224.  */
  225.  
  226. /* the optimal evaluation method to use */
  227. extern
  228. RecursiveMethod
  229. RecursiveMethodChoose ARGS((
  230.     ParseTree    parseTree
  231. ));
  232.  
  233. /* plan for recursive query, with recursion node at root */
  234. extern
  235. Plan
  236. RecursiveQueryPlan ARGS((
  237.     ParseTree    parseTree
  238. ));
  239.  
  240. #endif
  241.  
  242.