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

  1.  
  2. /*     
  3.  *      FILE
  4.  *         joininfo
  5.  *     
  6.  *      DESCRIPTION
  7.  *         JoinInfo node manipulation routines
  8.  *     
  9.  *      EXPORTS
  10.  *             find-joininfo-node
  11.  *             joininfo-member
  12.  *             other-join-clause-var
  13.  *    $Header: /private/postgres/src/planner/util/RCS/joininfo.c,v 1.15 1992/07/04 04:03:50 mao Exp $
  14.  */
  15.  
  16. #include "planner/internal.h"
  17. #include "nodes/relation.h"
  18. #include "nodes/relation.a.h"
  19. #include "planner/clauses.h"
  20.  
  21. /*    
  22.  *        joininfo-member
  23.  *    
  24.  *        Determines whether a node has already been created for a join
  25.  *        between a set of join relations and the relation described by
  26.  *        'joininfo-list'.
  27.  *    
  28.  *        'join-relids' is a list of relids corresponding to the join relation
  29.  *        'joininfo-list' is the list of joininfo nodes against which this is 
  30.  *            checked
  31.  *    
  32.  *        Returns the corresponding node in 'joininfo-list' if such a node
  33.  *        exists.
  34.  *    
  35.  */
  36.  
  37. /*  .. find-joininfo-node, new-joininfo-list
  38.  */
  39. JInfo
  40. joininfo_member(join_relids,joininfo_list)
  41.      LispValue join_relids,joininfo_list ;
  42. {
  43.     LispValue i = LispNil;
  44.     List other_rels = LispNil;
  45.     foreach(i,joininfo_list) {
  46.     other_rels = CAR(i);
  47.     if(same(join_relids,get_otherrels((JInfo)other_rels)))
  48.       return((JInfo)other_rels);
  49.     }
  50.     return((JInfo)NULL);
  51. }
  52.  
  53.  
  54. /*    
  55.  *        find-joininfo-node
  56.  *    
  57.  *        Find the joininfo node within a relation entry corresponding
  58.  *        to a join between 'this_rel' and the relations in 'join-relids'.  A
  59.  *        new node is created and added to the relation entry's joininfo
  60.  *        field if the desired one can't be found.
  61.  *    
  62.  *        Returns a joininfo node.
  63.  *    
  64.  */
  65.  
  66. /*  .. add-join-clause-info-to-rels
  67.  */
  68.  
  69. JInfo
  70. find_joininfo_node(this_rel,join_relids)
  71.      Rel this_rel;
  72.      List join_relids ;
  73. {
  74.     JInfo joininfo = joininfo_member(join_relids,
  75.                      get_joininfo(this_rel));
  76.     if( joininfo == NULL ) {
  77.     joininfo = RMakeJInfo();
  78.     set_otherrels(joininfo,join_relids);
  79.     set_jinfoclauseinfo(joininfo,LispNil);
  80.     set_mergesortable(joininfo,false);
  81.     set_hashjoinable(joininfo,false);
  82.     set_inactive(joininfo,false);
  83.     set_joininfo(this_rel, lispCons((LispValue)joininfo,
  84.                     get_joininfo(this_rel)));
  85.  
  86.     }
  87.     return(joininfo);
  88. }
  89.  
  90. /*    
  91.  *        other-join-clause-var
  92.  *    
  93.  *        Determines whether a var node is contained within a joinclause
  94.  *        of the form(op var var).
  95.  *    
  96.  *        Returns the other var node in the joinclause if it is, nil if not.
  97.  *    
  98.  */
  99.  
  100. /*  .. new-matching-subkeys
  101.  */
  102. Var
  103. other_join_clause_var(var,clause)
  104.      Var var;
  105.      LispValue clause ;
  106. {
  107.      Var retval;
  108.      Var l, r;
  109.  
  110.      retval = (Var) NULL;
  111.  
  112.      if( var != NULL  && join_clause_p(clause)) {
  113.  
  114.       l = (Var) get_leftop(clause);
  115.       r = (Var) get_rightop(clause);
  116.  
  117.       if(var_equal((LispValue)var, (LispValue)l)) {
  118.            retval = r;
  119.       } else if(var_equal((LispValue)var, (LispValue)r)) {
  120.            retval = l;
  121.       }
  122.      }
  123.  
  124.      return(retval);
  125. }
  126.