diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result index ba6b9f81a2d..33f5c6b5165 100644 --- a/mysql-test/r/temp_table.result +++ b/mysql-test/r/temp_table.result @@ -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 diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 2bfa4936c91..92c22242cdb 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -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 diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 2e48475f298..5e992d2391c 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1196,6 +1196,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, (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) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 902e7fa7b5f..e0e32b81e03 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1964,7 +1964,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, 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_LIST *tables, bool if_exists, 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