List:Commits« Previous MessageNext Message »
From:Jon Olav Hauglid Date:June 24 2010 9:35am
Subject:bzr push into mysql-trunk-runtime branch (jon.hauglid:3060 to 3061) Bug#48067
View as plain text  
 3061 Jon Olav Hauglid	2010-06-23
      Backport from mysql-6.0-codebase of:
      ------------------------------------------------------------
      revno: 3672
      committer: lars-erik.bjork@stripped
      branch nick: 48067-mysql-6.0-codebase-bugfixing
      timestamp: Mon 2009-10-26 13:51:43 +0100
      message:
        This is a patch for bug#48067
        "A temp table with the same name as an existing table, makes drop
        database fail"
              
        When dropping the database, mysql_rm_known_files() reads the contents
        of the database directory, and creates a TABLE_LIST object, for each
        .frm file encountered. Temporary tables, however, are not associated 
        with any .frm file.
              
        The list of tables to drop are passed to mysql_rm_table_part2().
        This method prefers temporary tables over regular tables, so if
        there is a temporary table with the same name as a regular, the
        temporary is removed, leaving the regular table intact.
        Regular tables are only deleted if there are no temporary tables
        with the same name.
              
        This fix ensures, that for all TABLE_LIST objects that are created
        by mysql_rm_known_files(), 'open_type' is set to 'OT_BASE_ONLY', to
        indicate that this is a regular table. In all cases in
        mysql_rm_table_part2() where we prefer a temporary table to a
        non-temporary table, we chek if 'open_type' equals 'OT_BASE_ONLY'.
     @ mysql-test/r/temp_table.result
        The expected result of the test.
     @ mysql-test/t/temp_table.test
        Test based on the bug report.
     @ sql/sql_db.cc
        For all TABLE_LIST objects that are created by mysql_rm_known_files(),
        'open_type' is set to 'OT_BASE_ONLY', to indicate that these are
        regular tables.
     @ sql/sql_table.cc
        Check if 'open_type' is set to 'OT_BASE_ONLY, every place a temporary table is
        preferred to a non-temporary table.

    modified:
      mysql-test/r/temp_table.result
      mysql-test/t/temp_table.test
      sql/sql_db.cc
      sql/sql_table.cc
 3060 Konstantin Osipov	2010-06-18
      A new implementation for the TABLE_SHARE cache in MDL
      subsystem. Fix a number of caveates that the previous
      implementation suffered from, including unprotected
      access to shared data and lax resource accounting
      (share->ref_count) that could lead to deadlocks.
      
      The new implementation still suffers from a number
      of potential deadlocks in some edge cases, and this is 
      still not enabled by default. Especially since performance
      testing has shown that it gives only marginable (not even 
      exceeding measuring accuracy) improvements.
      
      @todo: 
      - Remove calls to close_cached_tables() with REFRESH_FAST,
      and have_lock, because they break the MDL cache. 
      - rework FLUSH TABLES <list> to not use close_cached_tables()
      - make sure that whenever we set TABLE_SHARE::version to
      0 we free MDL cache references to it.
     @ sql/mdl.cc
        We may cache references to TABLE_SHARE objects in 
        MDL_lock objects for tables. Create a separate
        MDL_lock class to represent a table.
     @ sql/mdl.h
        Adjust the MDL caching API to avoid races.
     @ sql/sql_base.cc
        Move all caching functionality close together.
        Implement a solution for deadlocks caused by 
        close_cached_tables() when MDL cache is enabled (incomplete).
     @ sql/sql_yacc.yy
        Adjust FLUSH rule to do the necessary initialization of
        TABLE_LIST elements used in for FLUSH TABLES <list>, and thus
        work OK with flush_mdl_cache() function.

    modified:
      sql/mdl.cc
      sql/mdl.h
      sql/sql_base.cc
      sql/sql_yacc.yy
=== modified file 'mysql-test/r/temp_table.result'
--- a/mysql-test/r/temp_table.result	2009-01-07 12:11:37 +0000
+++ b/mysql-test/r/temp_table.result	2010-06-23 11:34:40 +0000
@@ -210,4 +210,16 @@ UPDATE t1,t2 SET t1.a = t2.a;
 INSERT INTO t2 SELECT f1();
 DROP TABLE t1,t2,t3;
 DROP FUNCTION f1;
+#
+# Bug #48067: A temp table with the same name as an existing table, 
+#             makes drop database fail.
+#
+DROP TEMPORARY TABLE IF EXISTS bug48067.t1;
+DROP DATABASE IF EXISTS bug48067;
+CREATE DATABASE bug48067;
+CREATE TABLE bug48067.t1 (c1 int);
+INSERT INTO bug48067.t1 values (1);
+CREATE TEMPORARY TABLE bug48067.t1 (c1 int);
+DROP DATABASE bug48067;
+DROP TEMPORARY table bug48067.t1;
 End of 5.1 tests

=== modified file 'mysql-test/t/temp_table.test'
--- a/mysql-test/t/temp_table.test	2009-01-07 12:11:37 +0000
+++ b/mysql-test/t/temp_table.test	2010-06-23 11:34:40 +0000
@@ -235,4 +235,19 @@ INSERT INTO t2 SELECT f1();
 DROP TABLE t1,t2,t3;
 DROP FUNCTION f1;
 
+--echo #
+--echo # Bug #48067: A temp table with the same name as an existing table, 
+--echo #             makes drop database fail.
+--echo #
+--disable_warnings
+DROP TEMPORARY TABLE IF EXISTS bug48067.t1;
+DROP DATABASE IF EXISTS bug48067;
+--enable_warnings
+CREATE DATABASE bug48067;
+CREATE TABLE bug48067.t1 (c1 int);
+INSERT INTO bug48067.t1 values (1);
+CREATE TEMPORARY TABLE bug48067.t1 (c1 int);
+DROP DATABASE bug48067;
+DROP TEMPORARY table bug48067.t1;
+
 --echo End of 5.1 tests

=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc	2010-05-25 12:35:01 +0000
+++ b/sql/sql_db.cc	2010-06-23 11:34:40 +0000
@@ -1196,6 +1196,7 @@ static long mysql_rm_known_files(THD *th
       (void) filename_to_tablename(file->name, table_list->table_name,
                                  MYSQL50_TABLE_NAME_PREFIX_LENGTH +
                                  strlen(file->name) + 1);
+      table_list->open_type= OT_BASE_ONLY;
 
       /* To be able to correctly look up the table in the table cache. */
       if (lower_case_table_names)

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-06-17 13:31:51 +0000
+++ b/sql/sql_table.cc	2010-06-23 11:34:40 +0000
@@ -1964,7 +1964,8 @@ int mysql_rm_table_part2(THD *thd, TABLE
     else
     {
       for (table= tables; table; table= table->next_local)
-        if (find_temporary_table(thd, table->db, table->table_name))
+        if (table->open_type != OT_BASE_ONLY &&
+	    find_temporary_table(thd, table->db, table->table_name))
         {
           /*
             A temporary table.
@@ -2009,8 +2010,11 @@ int mysql_rm_table_part2(THD *thd, TABLE
                          table->db, table->table_name, (long) table->table,
                          table->table ? (long) table->table->s : (long) -1));
 
-    error= drop_temporary_table(thd, table);
-
+    if (table->open_type == OT_BASE_ONLY)
+      error= 1;
+    else
+      error= drop_temporary_table(thd, table);
+ 
     switch (error) {
     case  0:
       // removed temporary table


Attachment: [text/bzr-bundle] bzr/jon.hauglid@sun.com-20100623113440-msro7g2e8kb9allj.bundle
Thread
bzr push into mysql-trunk-runtime branch (jon.hauglid:3060 to 3061) Bug#48067Jon Olav Hauglid24 Jun