← Back to team overview

maria-developers team mailing list archive

Rev 2728: - Better comments in file:///home/psergey/dev/maria-5.1-table-elim-r10/

 

At file:///home/psergey/dev/maria-5.1-table-elim-r10/

------------------------------------------------------------
revno: 2728
revision-id: psergey@xxxxxxxxxxxx-20090816124331-gd53m2alc0jb3ws4
parent: psergey@xxxxxxxxxxxx-20090816121708-v42h3mehvoy4c7yu
committer: Sergey Petrunya <psergey@xxxxxxxxxxxx>
branch nick: maria-5.1-table-elim-r10
timestamp: Sun 2009-08-16 15:43:31 +0300
message:
  - Better comments
  - Add OOM error checking
=== modified file 'sql/opt_table_elimination.cc'
--- a/sql/opt_table_elimination.cc	2009-08-16 12:17:08 +0000
+++ b/sql/opt_table_elimination.cc	2009-08-16 12:43:31 +0000
@@ -184,18 +184,11 @@
     unknown_args= n_children;
   }
   /* 
-    Outer join we're representing. This can be a join nest or a one table that
+    Outer join we're representing. This can be a join nest or one table that
     is outer join'ed.
   */
   TABLE_LIST *table_list;
   
-  /* 
-    Tables within this outer join (and its descendants) that are not yet known
-    to be functionally dependent.
-  */
-  table_map missing_tables; //psergey-todo: remove 
-  /* All tables within this outer join and its descendants */ 
-  table_map all_tables; //psergey-todo: remove 
   /* Parent eliminable outer join, if any */
   Outer_join_module *parent;
 };
@@ -229,11 +222,11 @@
 };
 
 static 
-void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps, 
+bool build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps, 
                             uint *and_level, Item *cond, 
                             table_map usable_tables);
 static 
-void add_eq_dep(Table_elimination *te, Equality_module **eq_dep, 
+bool add_eq_dep(Table_elimination *te, Equality_module **eq_dep, 
                 uint and_level,
                 Item_func *cond, Item *left, Item *right, 
                 table_map usable_tables);
@@ -270,7 +263,7 @@
 */
 
 static 
-void build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps, 
+bool build_eq_deps_for_cond(Table_elimination *te, Equality_module **fdeps, 
                             uint *and_level, Item *cond, 
                             table_map usable_tables)
 {
@@ -285,7 +278,8 @@
       Item *item;
       while ((item=li++))
       {
-        build_eq_deps_for_cond(te, fdeps, and_level, item, usable_tables);
+        if (build_eq_deps_for_cond(te, fdeps, and_level, item, usable_tables))
+          return TRUE;
       }
       /* 
         TODO: inject here a "if we have {t.col=const AND t.col=smth_else}, then
@@ -297,47 +291,52 @@
     else
     {
       (*and_level)++;
-      build_eq_deps_for_cond(te, fdeps, and_level, li++, usable_tables);
+      if (build_eq_deps_for_cond(te, fdeps, and_level, li++, usable_tables))
+        return TRUE;
       Item *item;
       while ((item=li++))
       {
         Equality_module *start_key_fields= *fdeps;
         (*and_level)++;
-        build_eq_deps_for_cond(te, fdeps, and_level, item, usable_tables);
+        if (build_eq_deps_for_cond(te, fdeps, and_level, item, usable_tables))
+          return TRUE;
         *fdeps= merge_func_deps(org_key_fields, start_key_fields, *fdeps,
                                 ++(*and_level));
       }
     }
-    return;
+    return FALSE;
   }
 
   if (cond->type() != Item::FUNC_ITEM)
-    return;
+    return FALSE;
 
   Item_func *cond_func= (Item_func*) cond;
   Item **args= cond_func->arguments();
-  Item *fld;
 
   switch (cond_func->functype()) {
   case Item_func::IN_FUNC:
   {
     if (cond_func->argument_count() == 2)
     {
-      add_eq_dep(te, fdeps, *and_level, cond_func, args[0], args[1], 
-                 usable_tables);
-      add_eq_dep(te, fdeps, *and_level, cond_func, args[1], args[0], 
-                 usable_tables);
+      if (add_eq_dep(te, fdeps, *and_level, cond_func, args[0], args[1], 
+                     usable_tables) || 
+          add_eq_dep(te, fdeps, *and_level, cond_func, args[1], args[0], 
+                 usable_tables))
+        return TRUE;
     }
   }
   case Item_func::BETWEEN:
   {
+    Item *fld;
     if (!((Item_func_between*)cond)->negated &&
+        (fld= args[0]->real_item())->type() == Item::FIELD_ITEM &&
         args[1]->eq(args[2], ((Item_field*)fld)->field->binary()))
     {
-      add_eq_dep(te, fdeps, *and_level, cond_func, args[0], args[1],
-                 usable_tables);
-      add_eq_dep(te, fdeps, *and_level, cond_func, args[1], args[0],
-                 usable_tables);
+      if (add_eq_dep(te, fdeps, *and_level, cond_func, args[0], args[1],
+                     usable_tables) || 
+          add_eq_dep(te, fdeps, *and_level, cond_func, args[1], args[0],
+                     usable_tables))
+        return TRUE;
     }
     break;
   }
@@ -353,10 +352,9 @@
   case Item_func::ISNULL_FUNC:
   {
     Item *tmp=new Item_null;
-    if (unlikely(!tmp))                       // Should never be true
-      return;
-    add_eq_dep(te, fdeps, *and_level, cond_func, args[0], args[1], 
-               usable_tables);
+    if (!tmp || add_eq_dep(te, fdeps, *and_level, cond_func, args[0], args[1],
+                           usable_tables))
+      return TRUE;
     break;
   }
   case Item_func::MULT_EQUAL_FUNC:
@@ -374,8 +372,9 @@
       */   
       while ((item= it++))
       {
-        add_eq_dep(te, fdeps, *and_level, cond_func, item, const_item, 
-                   usable_tables);
+        if (add_eq_dep(te, fdeps, *and_level, cond_func, item, const_item, 
+                       usable_tables))
+          return TRUE;
       }
     }
     else 
@@ -395,8 +394,9 @@
         {
           if (!field->eq(item2->field))
           {
-            add_eq_dep(te, fdeps, *and_level, cond_func, item, item2, 
-                       usable_tables);
+            if (add_eq_dep(te, fdeps, *and_level, cond_func, item, item2, 
+                           usable_tables))
+              return TRUE;
           }
         }
         it.rewind();
@@ -407,6 +407,7 @@
   default:
     break;
   }
+  return FALSE;
 }
 
 
@@ -536,7 +537,7 @@
 */
 
 static 
-void add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
+bool add_eq_dep(Table_elimination *te, Equality_module **eq_dep,
                 uint and_level, Item_func *cond, 
                 Item *left, Item *right, table_map usable_tables)
 {
@@ -550,7 +551,7 @@
       if (right->result_type() != STRING_RESULT)
       {
         if (field->cmp_type() != right->result_type())
-          return;
+          return FALSE;
       }
       else
       {
@@ -560,17 +561,19 @@
         */
         if (field->cmp_type() == STRING_RESULT &&
             ((Field_str*)field)->charset() != cond->compare_collation())
-          return;
+          return FALSE;
       }
     }
 
     /* Store possible eq field */
     (*eq_dep)->type=  Module_dep::MODULE_EXPRESSION; //psergey-todo;
-    (*eq_dep)->field= get_field_value(te, field); 
+    if (!((*eq_dep)->field= get_field_value(te, field)))
+      return TRUE;
     (*eq_dep)->expression= right;
     (*eq_dep)->level= and_level;
     (*eq_dep)++;
   }
+  return FALSE;
 }