← Back to team overview

maria-developers team mailing list archive

Rev 2740: MWL#17: Table elimination in file:///home/psergey/dev/maria-5.1-table-elim-r11/

 

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

------------------------------------------------------------
revno: 2740
revision-id: psergey@xxxxxxxxxxxx-20090821074822-6x2gv01r9ltt2bhc
parent: psergey@xxxxxxxxxxxx-20090820155102-5zvm1m6idmie9mmv
committer: Sergey Petrunya <psergey@xxxxxxxxxxxx>
branch nick: maria-5.1-table-elim-r11
timestamp: Fri 2009-08-21 09:48:22 +0200
message:
  MWL#17: Table elimination
  - More testcases
  - Set correct dependencies for non-bound multi-equalities.
=== modified file 'mysql-test/r/table_elim.result'
--- a/mysql-test/r/table_elim.result	2009-08-17 16:07:24 +0000
+++ b/mysql-test/r/table_elim.result	2009-08-21 07:48:22 +0000
@@ -218,6 +218,21 @@
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
 1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.col	1	
+explain select t1.* 
+from 
+t1 left join ( t2 left join t3 on t3.pk=t2.col or t3.pk=t2.col) 
+on t2.col=t1.col or t2.col=t1.col;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	
+explain select t1.*, t2.* 
+from 
+t1 left join 
+(t2 left join t3 on t3.pk=t2.col or t3.pk=t2.col) 
+on t2.pk=t1.col or t2.pk=t1.col;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.col	1	
 drop table t1, t2, t3;
 # 
 # Check things that look like functional dependencies but really are not

=== modified file 'mysql-test/t/table_elim.test'
--- a/mysql-test/t/table_elim.test	2009-08-17 16:07:24 +0000
+++ b/mysql-test/t/table_elim.test	2009-08-21 07:48:22 +0000
@@ -175,6 +175,17 @@
 explain 
 select t1.*, t2.* from t1 left join (t2 left join t3 on t3.pk=t2.col) on t2.pk=t1.col;
 
+explain select t1.* 
+from 
+  t1 left join ( t2 left join t3 on t3.pk=t2.col or t3.pk=t2.col) 
+  on t2.col=t1.col or t2.col=t1.col;
+
+explain select t1.*, t2.* 
+from 
+  t1 left join 
+  (t2 left join t3 on t3.pk=t2.col or t3.pk=t2.col) 
+  on t2.pk=t1.col or t2.pk=t1.col;
+
 drop table t1, t2, t3;
 
 --echo # 

=== modified file 'sql/opt_table_elimination.cc'
--- a/sql/opt_table_elimination.cc	2009-08-20 15:51:02 +0000
+++ b/sql/opt_table_elimination.cc	2009-08-21 07:48:22 +0000
@@ -454,8 +454,6 @@
   case Item_func::MULT_EQUAL_FUNC:
   {
     Item_equal *item_equal= (Item_equal*)cond;
-    // const item is 'item', field -> NULL. mult_equal_fields <-- an ordered
-    // list of 
     List<Field_value> *fvl;
     if (!(fvl= new List<Field_value>))
       break;
@@ -1001,17 +999,24 @@
     deps_recorder.expr_offset= eq_mod - fda->equality_mods;
     deps_recorder.saw_other_tbl= FALSE;
     eq_mod->unknown_args= 0;
-
+    
+    if (eq_mod->field)
+    {
     /* Regular tbl.col=expr(tblX1.col1, tblY1.col2, ...) */
-    eq_mod->expression->walk(&Item::check_column_usage_processor, FALSE, 
-                             (uchar*)&deps_recorder);
-
-    if (!eq_mod->field)
+      eq_mod->expression->walk(&Item::check_column_usage_processor, FALSE, 
+                               (uchar*)&deps_recorder);
+    }
+    else 
     {
-      if (eq_mod->unknown_args)
-        eq_mod->unknown_args= 1;
-      if (deps_recorder.saw_other_tbl)
-        eq_mod->unknown_args= 0;
+      /* It's a multi-equality*/
+      eq_mod->unknown_args= !test(eq_mod->expression);
+      List_iterator<Field_value> it(*eq_mod->mult_equal_fields);
+      Field_value* field_val;
+      while ((field_val= it++))
+      {
+        uint offs= field_val->bitmap_offset + eq_mod - fda->equality_mods;
+        bitmap_set_bit(&fda->expr_deps, offs);
+      }
     }
 
     if (!eq_mod->unknown_args)