home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / planner / util / internal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.9 KB  |  221 lines

  1.  
  2. /*     
  3.  *      FILE
  4.  *         internal
  5.  *     
  6.  *      DESCRIPTION
  7.  *         Definitions required throughout the query optimizer.
  8.  *     
  9.  */
  10. /* RcsId ("$Header: /private/postgres/src/planner/util/RCS/internal.c,v 1.16 1992/08/10 21:46:25 mer Exp $"); */
  11.  
  12. /*     
  13.  */
  14.  
  15. /*    
  16.  *        ---------- SHARED MACROS
  17.  *    
  18.  *         Macros common to modules for creating, accessing, and modifying
  19.  *        query tree and query plan components.
  20.  *        Shared with the executor.
  21.  *    
  22.  */
  23.  
  24. #include "planner/internal.h"
  25. #include "nodes/relation.h"
  26. #include "nodes/plannodes.h"
  27. #include "nodes/primnodes.h"
  28. #include "utils/log.h"
  29.  
  30. /*    
  31.  *        ---------- GLOBAL VARIABLES
  32.  *    
  33.  *        These *should* disappear eventually...shouldn't they?
  34.  *    
  35.  */
  36.  
  37. /* from the parse tree: */
  38.  
  39. LispValue _query_result_relation_;
  40.                     /*   relid of the result relation */
  41. int  _query_command_type_ = 0;    /*   command type as a symbol */
  42. int  _query_max_level_ = 0;      /*   max query nesting level */
  43. LispValue  _query_range_table_;     /*   relations to be scanned */
  44.  
  45. /*     internal to planner:  */
  46. List _base_relation_list_;    /*   base relation list */
  47. List _join_relation_list_;  /* list of relations generated by joins */
  48. bool _query_is_archival_;       /*   archival query flag */
  49.  
  50.  
  51. /* (defmacro with_saved_globals (&rest,body)  XXX fix me */
  52.  
  53. typedef struct {
  54.     LispValue qrr;
  55.     int       qct;
  56.     int       qml;
  57.     LispValue qrt;
  58.     LispValue brl;
  59.     LispValue jrl;
  60.     int       qia;
  61. } planner_globals_hack;
  62.  
  63. char *
  64. save_globals ()
  65. {
  66.     planner_globals_hack *pghP;
  67.  
  68.     pghP = (planner_globals_hack *)palloc(sizeof(planner_globals_hack));
  69.     pghP->qrr = _query_result_relation_;
  70.     pghP->qct =    _query_command_type_;
  71.     pghP->qml = _query_max_level_;
  72.     pghP->qrt = _query_range_table_;
  73.     pghP->brl = _base_relation_list_;
  74.     pghP->jrl = _join_relation_list_;
  75.     pghP->qia = _query_is_archival_;
  76.     return (char *)pghP;
  77. }
  78.  
  79. void
  80. restore_globals(pgh)
  81.     char *pgh;
  82. {
  83.     planner_globals_hack *pghP = (planner_globals_hack *)pgh;
  84.  
  85.     _query_result_relation_ = pghP->qrr;
  86.     _query_command_type_   = pghP->qct;
  87.     _query_max_level_ = pghP->qml;
  88.     _query_range_table_ = pghP->qrt;
  89.     _base_relation_list_ = pghP->brl;
  90.     _join_relation_list_ = pghP->jrl;
  91.     _query_is_archival_ = pghP->qia;
  92.     pfree(pgh);
  93.     return;
  94. }
  95.  
  96. List
  97. joinmethod_clauses(method)
  98.      JoinMethod method;
  99. {
  100.   return(method->clauses);
  101. }
  102.  
  103. List
  104. joinmethod_keys(method)
  105.      JoinMethod method;
  106. {
  107.     return(method->jmkeys);
  108. }
  109.      
  110. /* XXX - these should go away once spyros turns in some code */
  111.  
  112. Node
  113. rule_lock_plan()
  114. {
  115.     return((Node)NULL);
  116. }
  117.  
  118. Node 
  119. make_rule_lock()
  120. {
  121.     return((Node)NULL);
  122. }
  123.  
  124. Node
  125. rule_lock_type()
  126. {
  127.     return((Node)NULL);
  128. }
  129.  
  130. Node 
  131. rule_lock_attribute()
  132. {
  133.     return((Node)NULL);
  134. }
  135.  
  136. Node
  137. rule_lock_relation()
  138. {
  139.     return((Node)NULL);
  140. }
  141.  
  142. Node
  143. rule_lock_var()
  144. {
  145.     return((Node)NULL);
  146. }
  147.  
  148. int _rule_lock_type_alist_ = 0;
  149. int _rule_type_alist_ = 0;
  150.  
  151. TLE
  152. MakeTLE(foo,bar)
  153.      Resdom foo;
  154.      Expr bar;
  155. {
  156.     return(lispCons((LispValue)foo,lispCons((LispValue)bar,LispNil)));
  157. }
  158.  
  159. void
  160. set_joinlist(foo,bar)
  161.      TL foo;
  162.      List bar;
  163. {
  164.     CDR(foo) = bar;
  165. }
  166.  
  167. Var
  168. get_expr (foo)
  169.      TLE foo;
  170. {
  171.     Assert(!null(foo));
  172.     Assert(!null(CDR(foo)));
  173.     /* Assert(IsA(foo,LispValue)); */
  174.     return((Var)CADR(foo));
  175. }
  176.  
  177. Resdom
  178. get_resdom (foo)
  179.      TLE foo;
  180. {
  181.     /* Assert(IsA(foo,LispValue)); */
  182.     return((Resdom)CAR(foo));
  183. }
  184.  
  185. TLE
  186. get_entry(foo)
  187.      TL foo;
  188. {
  189.     /* Assert(IsA(foo,LispValue)); */
  190.  
  191.     return(CAR(foo));
  192. }
  193. void
  194. set_entry(node,foo)
  195.      TL node;
  196.      TLE foo;
  197. {
  198.     CAR(node) = foo;
  199. }
  200.  
  201. List
  202. get_joinlist(foo)
  203.      TL foo;
  204. {
  205.     /* Assert(IsA(foo,LispValue)); */
  206.  
  207.     return (CDR(foo));
  208. }
  209.  
  210. void
  211. init_planner()
  212. {
  213.     _query_result_relation_ = LispNil;
  214.     _query_command_type_ = 0;
  215.     _query_max_level_ = 1;
  216.     _query_range_table_ = LispNil;
  217.     _base_relation_list_ = LispNil;
  218.     _join_relation_list_ = LispNil;
  219.     _query_is_archival_ = false;
  220. }
  221.