Update of /cvsroot/monetdb/pathfinder/compiler/algebra/opt
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv5053/algebra/opt

Modified Files:
        opt_complex.c 
Log Message:
-- Add rewrites for thetajoins:
   * remove thetajoin with a one-row literal table and
   * replace thetajoin by eqjoin if the join behaves like a mapping join.


U opt_complex.c
Index: opt_complex.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/opt/opt_complex.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- opt_complex.c       6 Feb 2009 13:01:07 -0000       1.70
+++ opt_complex.c       9 Mar 2009 14:48:13 -0000       1.71
@@ -72,6 +72,69 @@
 }
 
 /**
+ * Replace a thetajoin with a one-row literal table by a selection.
+ */
+static PFla_op_t *
+replace_thetajoin (PFla_op_t *p, bool replace_left)
+{
+    PFla_op_t *lp  = replace_left ? L(p) : R(p),
+              *res = replace_left ? R(p) : L(p);
+
+    assert (p->kind == la_thetajoin &&
+            PFprop_card (lp->prop) &&
+            (lp->kind == la_lit_tbl ||
+             (lp->kind == la_project && L(lp)->kind == la_lit_tbl)));
+        
+    /* attach all columns of the to-be-replaced side
+       to the other side */
+    for (unsigned int i = 0; i < lp->schema.count; i++) {
+        assert (PFprop_const (p->prop,
+                              lp->schema.items[i].name));
+        res = attach (res,
+                      lp->schema.items[i].name,
+                      PFprop_const_val (
+                          p->prop,
+                          lp->schema.items[i].name));
+    }
+
+    /* evaluate selections on the relation */
+    for (unsigned int i = 0; i < p->sem.thetajoin.count; i++) {
+        PFalg_col_t col1 = p->sem.thetajoin.pred[i].left,
+                    col2 = p->sem.thetajoin.pred[i].right,
+                    new  = PFcol_new (col1),
+                    tmp;
+        switch (p->sem.thetajoin.pred[0].comp) {
+            case alg_comp_eq:
+                res = eq (res, new, col1, col2);
+                break;
+            case alg_comp_gt:
+                res = gt (res, new, col1, col2);
+                break;
+            case alg_comp_ge:
+                tmp = PFcol_new (col1);
+                res = not (gt (res, tmp, col2, col1), new, tmp);
+                break;
+            case alg_comp_lt:
+                res = gt (res, new, col2, col1);
+                break;
+            case alg_comp_le:
+                tmp = PFcol_new (col1);
+                res = not (gt (res, tmp, col1, col2), new, tmp);
+                break;
+            case alg_comp_ne:
+                tmp = PFcol_new (col1);
+                res = not (eq (res, tmp, col1, col2), new, tmp);
+                break;
+        }
+        res = select_ (res, new);
+    }
+    /* remove additional columns */
+    return PFla_project_ (res,
+                          p->schema.count,
+                          PFalg_proj_create (p->schema));
+}
+
+/**
  * This function checks for the following bigger pattern:
  *
  *                    |
@@ -1300,6 +1363,45 @@
             }
             break;
 
+        case la_thetajoin:
+            /* rewrite thetajoin into equi-join if it seems to be a mapping 
join */
+            if (p->sem.thetajoin.count == 1 &&
+                p->sem.thetajoin.pred[0].comp == alg_comp_eq &&
+                ((PFprop_key_left (p->prop, p->sem.thetajoin.pred[0].left) &&
+                  PFprop_subdom (p->prop,
+                                 PFprop_dom_right (p->prop,
+                                                   
p->sem.thetajoin.pred[0].right),
+                                 PFprop_dom_left (p->prop,
+                                                  
p->sem.thetajoin.pred[0].left))) ||
+                 (PFprop_key_right (p->prop, p->sem.thetajoin.pred[0].right) &&
+                  PFprop_subdom (p->prop,
+                                 PFprop_dom_left (p->prop,
+                                                   
p->sem.thetajoin.pred[0].left),
+                                 PFprop_dom_right (p->prop,
+                                                  
p->sem.thetajoin.pred[0].right))))) {
+                *p = *PFla_eqjoin (L(p), R(p),
+                                   p->sem.thetajoin.pred[0].left,
+                                   p->sem.thetajoin.pred[0].right);
+                modified = true;
+            }
+            /* unfold a thetajoin with a one-row literal table */
+            else if (PFprop_card (L(p)->prop) == 1 &&
+                     (L(p)->kind == la_lit_tbl ||
+                      (L(p)->kind == la_project &&
+                       LL(p)->kind == la_lit_tbl))) {
+                *p = *replace_thetajoin (p, true);
+                modified = true;
+            }
+            /* unfold a thetajoin with a one-row literal table */
+            else if (PFprop_card (R(p)->prop) == 1 &&
+                     (R(p)->kind == la_lit_tbl ||
+                      (R(p)->kind == la_project &&
+                       RL(p)->kind == la_lit_tbl))) {
+                *p = *replace_thetajoin (p, false);
+                modified = true;
+            }
+            break;
+
         case la_cross:
             /* PFprop_icols_count () == 0 is also true
                for nodes without inferred properties
@@ -2445,11 +2547,13 @@
     split_rowid_for_side_effects (root);
 
     while (modified) {
-        /* Infer key, icols, domain, reqval,
+        /* Infer key, const, icols, domain, reqval,
            and refctr properties first */
         PFprop_infer_lineage (root);
         PFprop_infer_functional_dependencies (root);
+        /* card property inferred by key */
         PFprop_infer_key (root);
+        PFprop_infer_const (root);
         PFprop_infer_level (root);
         PFprop_infer_composite_key (root);
         PFprop_infer_icol (root);


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to