Skip to content

Commit 4227dd2

Browse files
committed
continue DROP TEMPORARY TABLE t1, t2, t3 after error.
normal DROP TABLE with many tables continues after an error, trying to drop as many tables as possible. But DROP TEMPORARY TABLE was aborting on the first error. Change it to behave as DROP TABLE does.
1 parent 6c52931 commit 4227dd2

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

mysql-test/main/temp_table.result

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
drop table if exists t1,t2;
2-
drop view if exists v1;
31
#
42
# test basic creation of temporary tables together with normal table
53
#
@@ -602,3 +600,22 @@ DROP TEMPORARY TABLE t1;
602600
#
603601
# End of 10.2 tests
604602
#
603+
create function f1() returns int
604+
begin
605+
drop temporary table t1, t2;
606+
return 1;
607+
end;
608+
$$
609+
create temporary table t1 (a int);
610+
create temporary table t2 (a int);
611+
insert t1 values (2);
612+
insert t2 values (3);
613+
select a,f1() from t1;
614+
ERROR HY000: Can't reopen table: 't1'
615+
drop function f1;
616+
drop temporary table t1;
617+
drop temporary table t2;
618+
ERROR 42S02: Unknown table 'test.t2'
619+
#
620+
# End of 10.5 tests
621+
#

mysql-test/main/temp_table.test

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
# Test of temporary tables
77
#
88

9-
--disable_warnings
10-
drop table if exists t1,t2;
11-
drop view if exists v1;
12-
--enable_warnings
13-
149
--echo #
1510
--echo # test basic creation of temporary tables together with normal table
1611
--echo #
@@ -658,3 +653,31 @@ DROP TEMPORARY TABLE t1;
658653
--echo #
659654
--echo # End of 10.2 tests
660655
--echo #
656+
657+
#
658+
# DROP TEMPORARY TABLE fails in the middle
659+
#
660+
delimiter $$;
661+
create function f1() returns int
662+
begin
663+
drop temporary table t1, t2;
664+
return 1;
665+
end;
666+
$$
667+
delimiter ;$$
668+
669+
create temporary table t1 (a int);
670+
create temporary table t2 (a int);
671+
insert t1 values (2);
672+
insert t2 values (3);
673+
--error ER_CANT_REOPEN_TABLE
674+
select a,f1() from t1;
675+
drop function f1;
676+
drop temporary table t1;
677+
--error ER_BAD_TABLE_ERROR
678+
drop temporary table t2;
679+
680+
--echo #
681+
--echo # End of 10.5 tests
682+
--echo #
683+

sql/sql_table.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,17 +2338,12 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
23382338
{
23392339
table_creation_was_logged= table->table->s->table_creation_was_logged;
23402340
if (thd->drop_temporary_table(table->table, &is_trans, true))
2341-
{
2342-
/*
2343-
This is a very unlikely scenaro as dropping a temporary table
2344-
should always work. Would be better if we tried to drop all
2345-
temporary tables before giving the error.
2346-
*/
23472341
error= 1;
2348-
goto err;
2342+
else
2343+
{
2344+
table->table= 0;
2345+
temporary_table_was_dropped= 1;
23492346
}
2350-
table->table= 0;
2351-
temporary_table_was_dropped= 1;
23522347
}
23532348

23542349
if ((drop_temporary && if_exists) || temporary_table_was_dropped)

0 commit comments

Comments
 (0)