← Back to team overview

maria-developers team mailing list archive

bzr commit into Mariadb 5.2, with Maria 2.0:maria/5.2 branch (igor:2789)

 

#At lp:maria/5.2 based on revid:igor@xxxxxxxxxxxx-20100429211039-rp1mza3xjeqd4t1w

 2789 Igor Babaev	2010-05-11
      Fixed several bugs in the backport code (mwl#106).
      modified:
        mysql-test/r/innodb_lock_wait_timeout_1.result
        mysql-test/r/lock_multi_bug38499.result
        mysql-test/r/ps_ddl.result
        mysql-test/t/lock_multi_bug38499.test
        sql/sql_base.cc
        sql/sql_delete.cc
        sql/sql_derived.cc
        sql/sql_select.cc
        sql/sql_union.cc
        sql/table.cc

=== modified file 'mysql-test/r/innodb_lock_wait_timeout_1.result'
--- a/mysql-test/r/innodb_lock_wait_timeout_1.result	2009-11-12 11:43:33 +0000
+++ b/mysql-test/r/innodb_lock_wait_timeout_1.result	2010-05-12 04:09:58 +0000
@@ -104,7 +104,7 @@ id	1
 select_type	PRIMARY
 table	<derived2>
 type	ALL
-possible_keys	NULL
+possible_keys	key0
 key	NULL
 key_len	NULL
 ref	NULL
@@ -308,7 +308,7 @@ id	1
 select_type	PRIMARY
 table	<derived2>
 type	ALL
-possible_keys	NULL
+possible_keys	key0
 key	NULL
 key_len	NULL
 ref	NULL

=== modified file 'mysql-test/r/lock_multi_bug38499.result'
--- a/mysql-test/r/lock_multi_bug38499.result	2009-08-28 21:49:16 +0000
+++ b/mysql-test/r/lock_multi_bug38499.result	2010-05-12 04:09:58 +0000
@@ -2,7 +2,9 @@ SET @odl_sync_frm = @@global.sync_frm;
 SET @@global.sync_frm = OFF;
 DROP TABLE IF EXISTS t1;
 CREATE TABLE t1( a INT, b INT );
+CREATE TABLE t2( a INT, b INT );
 INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4);
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4);
 # 1. test regular tables
 # 1.1. test altering of columns that multiupdate doesn't use
 # 1.1.1. normal mode
@@ -18,5 +20,5 @@ ALTER TABLE t1 ADD COLUMN a INT;
 # 2.2. test altering of columns that multiupdate uses
 # 2.2.1. normal mode
 # 2.2.2. PS mode
-DROP TABLE t1;
+DROP TABLE t1,t2;
 SET @@global.sync_frm = @odl_sync_frm;

=== modified file 'mysql-test/r/ps_ddl.result'
--- a/mysql-test/r/ps_ddl.result	2010-01-16 07:44:24 +0000
+++ b/mysql-test/r/ps_ddl.result	2010-05-12 04:09:58 +0000
@@ -1507,12 +1507,12 @@ create view v_27690_1 as select A.a, A.b
 execute stmt;
 a	b	a	b
 1	1	1	1
-2	2	1	1
-1	1	1	1
-2	2	1	1
 1	1	2	2
+2	2	1	1
 2	2	2	2
+1	1	1	1
 1	1	2	2
+2	2	1	1
 2	2	2	2
 call p_verify_reprepare_count(1);
 SUCCESS
@@ -1520,12 +1520,12 @@ SUCCESS
 execute stmt;
 a	b	a	b
 1	1	1	1
-2	2	1	1
-1	1	1	1
-2	2	1	1
 1	1	2	2
+2	2	1	1
 2	2	2	2
+1	1	1	1
 1	1	2	2
+2	2	1	1
 2	2	2	2
 call p_verify_reprepare_count(0);
 SUCCESS

=== modified file 'mysql-test/t/lock_multi_bug38499.test'
--- a/mysql-test/t/lock_multi_bug38499.test	2009-08-28 21:49:16 +0000
+++ b/mysql-test/t/lock_multi_bug38499.test	2010-05-12 04:09:58 +0000
@@ -16,7 +16,9 @@ connect (writer,localhost,root,,);
 DROP TABLE IF EXISTS t1;
 --enable_warnings
 CREATE TABLE t1( a INT, b INT );
+CREATE TABLE t2( a INT, b INT );
 INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4);
+INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4);
 
 --echo # 1. test regular tables
 --echo # 1.1. test altering of columns that multiupdate doesn't use
@@ -28,7 +30,7 @@ while ($i) {
 --dec $i
 
 --connection writer
-  send UPDATE t1, (SELECT 1 FROM t1 t1i) d SET a = 0 WHERE 1=0;
+  send UPDATE t1, (SELECT 1 FROM t2 t1i) d SET a = 0 WHERE 1=0;
 
 --connection locker
   ALTER TABLE t1 ADD COLUMN (c INT);
@@ -41,7 +43,7 @@ while ($i) {
 --echo # 1.1.2. PS mode
 
 --connection writer
-PREPARE stmt FROM 'UPDATE t1, (SELECT 1 FROM t1 t1i) d SET a = 0 WHERE 1=0';
+PREPARE stmt FROM 'UPDATE t1, (SELECT 1 FROM t2 t1i) d SET a = 0 WHERE 1=0';
 
 let $i = 100;
 while ($i) {
@@ -75,7 +77,7 @@ while ($i) {
   UPDATE t1 SET a=b;
 
 --connection writer
---send UPDATE t1, (SELECT 1 FROM t1 t1i) d SET a = 0 WHERE 1=0;
+--send UPDATE t1, (SELECT 1 FROM t2 t1i) d SET a = 0 WHERE 1=0;
 
 --connection locker
 --error 0,ER_CANT_DROP_FIELD_OR_KEY
@@ -100,7 +102,7 @@ while ($i) {
   UPDATE t1 SET a=b;
 
 --connection writer
-  PREPARE stmt FROM 'UPDATE t1, (SELECT 1 FROM t1 t1i) d SET a = 0 WHERE 1=0';
+  PREPARE stmt FROM 'UPDATE t1, (SELECT 1 FROM t2 t1i) d SET a = 0 WHERE 1=0';
 --send EXECUTE stmt
 
 --connection locker
@@ -210,7 +212,7 @@ while ($i) {
 }
 --enable_query_log
 --connection default
-DROP TABLE t1;
+DROP TABLE t1,t2;
 
 
 # Close connections

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2010-04-29 21:10:39 +0000
+++ b/sql/sql_base.cc	2010-05-12 04:09:58 +0000
@@ -7642,7 +7642,8 @@ bool setup_tables(THD *thd, Name_resolut
   TABLE_LIST *first_select_table= (select_insert ?
                                    tables->next_local:
                                    0);
-  SELECT_LEX *select_lex= thd->lex->current_select;
+  SELECT_LEX *select_lex= select_insert ? &thd->lex->select_lex :
+                                          thd->lex->current_select;
   if (select_lex->first_cond_optimization)
   {
     leaves.empty();

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2010-04-29 21:10:39 +0000
+++ b/sql/sql_delete.cc	2010-05-12 04:09:58 +0000
@@ -397,6 +397,12 @@ cleanup:
     query_cache_invalidate3(thd, table_list, 1);
   }
 
+  if (thd->lex->current_select->first_cond_optimization)
+  {
+    thd->lex->current_select->save_leaf_tables(thd);
+    thd->lex->current_select->first_cond_optimization= 0;
+  }
+
   delete select;
   transactional_table= table->file->has_transactions();
 

=== modified file 'sql/sql_derived.cc'
--- a/sql/sql_derived.cc	2010-04-29 21:10:39 +0000
+++ b/sql/sql_derived.cc	2010-05-12 04:09:58 +0000
@@ -159,8 +159,12 @@ mysql_handle_single_derived(LEX *lex, TA
     uint phase_flag= DT_INIT << phase;
     if (phase_flag > phases)
       break;
+#if 0
     if (!(phases & phase_flag) ||
         derived->merged_for_insert && phase_flag != DT_REINIT)
+#else
+    if (!(phases & phase_flag))
+#endif
       continue;
     /* Skip derived tables to which the phase isn't applicable.  */
     if (phase_flag != DT_PREPARE &&
@@ -476,11 +480,27 @@ bool mysql_derived_merge_for_insert(THD 
     derived->table= table;
     derived->schema_table=
       ((TABLE_LIST*)dt_select->table_list.first)->schema_table;
-    derived->select_lex->leaf_tables.push_back(tl);    
+    if (!derived->merged)
+    {
+      Query_arena *arena, backup;
+      arena= thd->activate_stmt_arena_if_needed(&backup);  // For easier test
+      derived->select_lex->leaf_tables.push_back(tl);
+      derived->nested_join= (NESTED_JOIN*) thd->calloc(sizeof(NESTED_JOIN));
+      if (derived->nested_join)
+      {
+        derived->wrap_into_nested_join(tl->select_lex->top_join_list);
+        derived->get_unit()->exclude_level(); 
+      }
+      if (arena)
+        thd->restore_active_arena(arena, &backup);
+      derived->merged= TRUE;
+      if (!derived->nested_join)
+        return TRUE;
+    }      
   }
   else
   {
-    if (mysql_derived_merge(thd, lex, derived))
+    if (!derived->merged_for_insert && mysql_derived_merge(thd, lex, derived))
       return TRUE;
   }
   derived->merged_for_insert= TRUE;
@@ -585,11 +605,19 @@ bool mysql_derived_prepare(THD *thd, LEX
   bool res= FALSE;
 
   // Skip already prepared views/DT
+#if 0
   if (!unit || unit->prepared || derived->merged_for_insert)
+#else
+  if (!unit || unit->prepared)
+#endif
     DBUG_RETURN(FALSE);
 
   /* It's a target view for an INSERT, create field translation only. */
+#if 0
   if (derived->skip_prepare_derived && !derived->is_multitable())
+#else
+  if (derived->merged_for_insert)
+#endif
   {
     res= derived->create_field_translation(thd);
     DBUG_RETURN(res);

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2010-04-29 21:10:39 +0000
+++ b/sql/sql_select.cc	2010-05-12 04:09:58 +0000
@@ -7836,7 +7836,7 @@ void JOIN_TAB::cleanup()
 bool JOIN_TAB::preread_init()
 {
   TABLE_LIST *derived= table->pos_in_table_list;
-  if (!derived->is_materialized_derived())
+  if (!derived || !derived->is_materialized_derived())
   {
     preread_init_done= TRUE;
     return FALSE;
@@ -9923,12 +9923,14 @@ simplify_joins(JOIN *join, List<TABLE_LI
     {
       TABLE_LIST *tbl;
       List_iterator<TABLE_LIST> it(nested_join->join_list);
+      List<TABLE_LIST> repl_list;  
       while ((tbl= it++))
       {
         tbl->embedding= table->embedding;
         tbl->join_list= table->join_list;
+        repl_list.push_back(tbl);
       }
-      li.replace(nested_join->join_list);
+      li.replace(repl_list);
       /* Need to update the name resolution table chain when flattening joins */
       fix_name_res= TRUE;
       table= *li.ref();

=== modified file 'sql/sql_union.cc'
--- a/sql/sql_union.cc	2010-04-29 21:10:39 +0000
+++ b/sql/sql_union.cc	2010-05-12 04:09:58 +0000
@@ -394,7 +394,7 @@ bool st_select_lex_unit::prepare(THD *th
     if (union_result->create_result_table(thd, &types, test(union_distinct),
                                           create_options, "", FALSE, TRUE))
       goto err;
-    if (!lex_select_save->first_cond_optimization)
+    if (fake_select_lex && !fake_select_lex->first_cond_optimization)
     {
       save_tablenr= result_table_list.tablenr_exec;
       save_map= result_table_list.map_exec;
@@ -403,7 +403,7 @@ bool st_select_lex_unit::prepare(THD *th
     result_table_list.db= (char*) "";
     result_table_list.table_name= result_table_list.alias= (char*) "union";
     result_table_list.table= table= union_result->table;
-    if (!lex_select_save->first_cond_optimization)
+    if (fake_select_lex && !fake_select_lex->first_cond_optimization)
     {
       result_table_list.tablenr_exec= save_tablenr;
       result_table_list.map_exec= save_map;

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2010-04-29 21:10:39 +0000
+++ b/sql/table.cc	2010-05-12 04:09:58 +0000
@@ -5638,7 +5638,7 @@ bool TABLE_LIST::handle_derived(struct s
   @return 0                    when it's not a derived table/view.
 */
 
-inline st_select_lex_unit *TABLE_LIST::get_unit()
+st_select_lex_unit *TABLE_LIST::get_unit()
 {
   return (view ? &view->unit : derived);
 }
@@ -5652,7 +5652,7 @@ inline st_select_lex_unit *TABLE_LIST::g
   @return 0          when it's not a derived table.
 */
 
-inline st_select_lex *TABLE_LIST::get_single_select()
+st_select_lex *TABLE_LIST::get_single_select()
 {
   SELECT_LEX_UNIT *unit= get_unit();
   return (unit ? unit->first_select() : 0);