Changeset: 7d1285b15988 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7d1285b15988
Modified Files:
        pathfinder/compiler/algebra/opt/opt_reqval.c
Branch: default
Log Message:

Split up required value rewrites to ensure that we don't get inconsistent 
column types.


diffs (97 lines):

diff -r 51719a0961b8 -r 7d1285b15988 
pathfinder/compiler/algebra/opt/opt_reqval.c
--- a/pathfinder/compiler/algebra/opt/opt_reqval.c      Wed Jul 14 21:33:36 
2010 +0200
+++ b/pathfinder/compiler/algebra/opt/opt_reqval.c      Thu Jul 22 14:09:05 
2010 +0200
@@ -97,23 +97,6 @@
     if (p->bit_dag)
         return;
 
-    /* Using the required values property as well as the constant
-       property we can replace every expression, where at least one
-       column has a constant value that differs its required value,
-       by an empty table. */
-    for (unsigned int i = 0; i < p->schema.count; i++) {
-        PFalg_col_t cur_col = p->schema.items[i].name;
-
-        if (PFprop_req_bool_val (p->prop, cur_col) &&
-            PFprop_const (p->prop, cur_col) &&
-            (PFprop_const_val (p->prop, cur_col)).val.bln !=
-             PFprop_req_bool_val_val (p->prop, cur_col)) {
-            /* create an empty table instead */
-            *p = *PFla_empty_tbl_ (p->schema);
-            return;
-        }
-    }
-
     /* Replace rowrank operators whose real values
        are not needed by rank operators.
        Note that we do not need to check for the order
@@ -185,6 +168,41 @@
     p->bit_dag = true;
 }
 
+/* worker for PFalgopt_reqval */
+static void
+opt_req_bool_vals (PFla_op_t *p)
+{
+    assert (p);
+
+    /* nothing to do if we already visited that node */
+    if (p->bit_dag)
+        return;
+
+    /* Using the required values property as well as the constant
+       property we can replace every expression, where at least one
+       column has a constant value that differs its required value,
+       by an empty table. */
+    for (unsigned int i = 0; i < p->schema.count; i++) {
+        PFalg_col_t cur_col = p->schema.items[i].name;
+
+        if (PFprop_req_bool_val (p->prop, cur_col) &&
+            PFprop_const (p->prop, cur_col) &&
+            (PFprop_const_val (p->prop, cur_col)).val.bln !=
+             PFprop_req_bool_val_val (p->prop, cur_col)) {
+            /* create an empty table instead */
+            *p = *PFla_empty_tbl_ (p->schema);
+            return;
+        }
+    }
+
+    /* infer properties for children */
+    for (unsigned int i = 0; i < PFLA_OP_MAXCHILD && p->child[i]; i++)
+        opt_req_bool_vals (p->child[i]);
+
+    /* mark node as visited */
+    p->bit_dag = true;
+}
+
 /**
  * Invoke algebra optimization.
  */
@@ -202,7 +220,10 @@
 
     schema_dirty = false;
 
-    /* Optimize algebra tree */
+    /* Optimize algebra tree. 
+       Note: the rewrites modifying the column types have to be performed
+       before empty tables are introduced in opt_req_bool_vals() to avoid
+       inconsistent types. */
     opt_reqvals (root);
     PFla_dag_reset (root);
 
@@ -212,6 +233,15 @@
     if (schema_dirty)
         PFprop_infer_ocol (root);
 
+    schema_dirty = false;
+
+    /* Get rid of superfluous branches.
+       Make sure to take the rewrites that might have changed column types
+       into account. */
+    opt_req_bool_vals (root);
+    PFla_dag_reset (root);
+    assert (!schema_dirty);
+
     return root;
 }
 
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to