Skip to content

Commit 2bb5981

Browse files
committed
MDEV-11412 Ensure that table is truly dropped when using DROP TABLE
minor post-review fixes * remove duplicate tests * first file indicates table existance even with discovery * don't duplicate trigger dropping code
1 parent b014720 commit 2bb5981

File tree

4 files changed

+13
-75
lines changed

4 files changed

+13
-75
lines changed

mysql-test/main/drop_table_force.result

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ db.opt
88
# Test droping table without frm without super privilege
99
create table t1(a int) engine=innodb;
1010
create user test identified by '123456';
11-
grant all privileges on test.t1 to 'test'@'%'identified by '123456' with grant option;
11+
grant all privileges on test.t1 to 'test'@'%'identified by '123456';
1212
connect con_test, localhost, test,'123456', ;
1313
connection con_test;
1414
drop table t1;
@@ -18,10 +18,6 @@ connection default;
1818
disconnect con_test;
1919
drop user test;
2020
db.opt
21-
#Test4: drop table can drop consistent table as well
22-
create table t1(a int) engine=innodb;
23-
drop table t1;
24-
db.opt
2521
#Test5: drop table with triger, and with missing frm
2622
create table t1(a int)engine=innodb;
2723
create trigger t1_trg before insert on t1 for each row begin end;
@@ -45,13 +41,6 @@ drop table if exists t1;
4541
Warnings:
4642
Note 1051 Unknown table 'test.t1'
4743
db.opt
48-
#Test8: check compatibility with if exists
49-
create table t1(a int)engine=innodb;
50-
drop table t1;
51-
db.opt
52-
drop table if exists t1;
53-
Warnings:
54-
Note 1051 Unknown table 'test.t1'
5544
#Test9: check compatibility with restrict/cascade
5645
CREATE TABLE parent (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
5746
CREATE TABLE child (id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE) ENGINE=INNODB;

mysql-test/main/drop_table_force.test

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ create table t1(a int) engine=innodb;
3232

3333
# create test user
3434
create user test identified by '123456';
35-
grant all privileges on test.t1 to 'test'@'%'identified by '123456' with grant option;
35+
grant all privileges on test.t1 to 'test'@'%'identified by '123456';
3636

3737
# connect as test
3838
connect (con_test, localhost, test,'123456', );
@@ -52,13 +52,6 @@ drop user test;
5252
# check files in datadir about t1
5353
--list_files $DATADIR/test/
5454

55-
--echo #Test4: drop table can drop consistent table as well
56-
create table t1(a int) engine=innodb;
57-
drop table t1;
58-
59-
# check files in datadir about t1
60-
--list_files $DATADIR/test/
61-
6255
--echo #Test5: drop table with triger, and with missing frm
6356
# create table t1 with triger and rm frm
6457
create table t1(a int)engine=innodb;
@@ -107,19 +100,6 @@ drop table if exists t1;
107100
# check files in datadir about t1
108101
--list_files $DATADIR/test/
109102

110-
--echo #Test8: check compatibility with if exists
111-
create table t1(a int)engine=innodb;
112-
--remove_file $DATADIR/test/t1.frm
113-
114-
# first drop will success
115-
drop table t1;
116-
117-
# check files in datadir about t1
118-
--list_files $DATADIR/test/
119-
120-
# second drop with if exists will success
121-
drop table if exists t1;
122-
123103
--echo #Test9: check compatibility with restrict/cascade
124104
# create table with foreign key reference and rm frm
125105
CREATE TABLE parent (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;

sql/handler.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,21 +4457,12 @@ int handler::delete_table(const char *name)
44574457

44584458
// For discovery tables, it's ok if first file doesn't exists
44594459
if (ht->discover_table)
4460-
{
4461-
abort_if_first_file_error= 0;
44624460
saved_error= 0;
4463-
if (!bas_ext())
4464-
{
4465-
DBUG_ASSERT(ht->flags & HTON_AUTOMATIC_DELETE_TABLE);
4466-
DBUG_RETURN(0); // Drop succeded
4467-
}
4468-
}
44694461

44704462
for (const char **ext= bas_ext(); *ext ; ext++)
44714463
{
4472-
int error;
4473-
if ((error= mysql_file_delete_with_symlink(key_file_misc, name, *ext,
4474-
MYF(0))))
4464+
int err= mysql_file_delete_with_symlink(key_file_misc, name, *ext, MYF(0));
4465+
if (err)
44754466
{
44764467
if (my_errno != ENOENT)
44774468
{

sql/sql_table.cc

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
23082308
for (table= tables; table; table= table->next_local)
23092309
{
23102310
bool is_trans= 0, frm_was_deleted= 0, temporary_table_was_dropped= 0;
2311-
bool table_creation_was_logged= 0, trigger_drop_executed= 0;
2311+
bool table_creation_was_logged= 0;
23122312
bool local_non_tmp_error= 0, frm_exists= 0, wrong_drop_sequence= 0;
23132313
bool table_dropped= 0;
23142314
LEX_CSTRING db= table->db;
@@ -2363,14 +2363,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
23632363
*/
23642364
if (!dont_log_query && table_creation_was_logged)
23652365
{
2366-
/*
2367-
DROP TEMPORARY succeded. For the moment when we only come
2368-
here on success (error == 0)
2369-
2370-
If there is an error, we don't know the type of the engine
2371-
at this point. So, we keep it in the trx-cache.
2372-
*/
2373-
is_trans= error ? TRUE : is_trans;
23742366
if (is_trans)
23752367
trans_tmp_table_deleted= TRUE;
23762368
else
@@ -2416,7 +2408,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
24162408
}
24172409

24182410
DEBUG_SYNC(thd, "rm_table_no_locks_before_delete_table");
2419-
error= 0;
24202411
if (drop_temporary)
24212412
{
24222413
/* "DROP TEMPORARY" but a temporary table was not found */
@@ -2551,31 +2542,16 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
25512542
table_dropped= 1;
25522543
}
25532544
}
2554-
if (likely(!error) || non_existing_table_error(error))
2555-
{
2556-
trigger_drop_executed= 1;
2557-
2558-
if (Table_triggers_list::drop_all_triggers(thd, &db,
2559-
&table->table_name,
2560-
MYF(MY_WME |
2561-
MY_IGNORE_ENOENT)))
2562-
error= error ? error : -1;
2563-
}
25642545
local_non_tmp_error|= MY_TEST(error);
25652546
}
25662547

25672548
/*
25682549
If there was no .frm file and the table is not temporary,
25692550
scan all engines try to drop the table from there.
25702551
This is to ensure we don't have any partial table files left.
2571-
2572-
We check for trigger_drop_executed to ensure we don't again try
2573-
to drop triggers when it failed above (after sucecssfully dropping
2574-
the table).
25752552
*/
25762553
if (non_existing_table_error(error) && !drop_temporary &&
2577-
table_type != view_pseudo_hton && !trigger_drop_executed &&
2578-
!wrong_drop_sequence)
2554+
table_type != view_pseudo_hton && !wrong_drop_sequence)
25792555
{
25802556
int ferror= 0;
25812557

@@ -2601,16 +2577,18 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
26012577
MYF(MY_WME | MY_IGNORE_ENOENT)))
26022578
ferror= my_errno;
26032579
}
2604-
if (Table_triggers_list::drop_all_triggers(thd, &db,
2605-
&table->table_name,
2606-
MYF(MY_WME |
2607-
MY_IGNORE_ENOENT)))
2608-
ferror= -1;
26092580
}
26102581
if (!error)
26112582
error= ferror;
26122583
}
26132584

2585+
if (likely(!error) || non_existing_table_error(error))
2586+
{
2587+
if (Table_triggers_list::drop_all_triggers(thd, &db, &table->table_name,
2588+
MYF(MY_WME | MY_IGNORE_ENOENT)))
2589+
error= error ? error : -1;
2590+
}
2591+
26142592
if (error)
26152593
{
26162594
char buff[FN_REFLEN];

0 commit comments

Comments
 (0)