Skip to content

Commit 1aaaa84

Browse files
committed
Bug#11763795 ORPHAN FILES LEFT AFTER RENAME OR DROP ON A
PARTITIONED TABLE Problem: The problem is that RENAME TABLE and DROP TABLE command succeeds on tables with partition even when mysqld is started with --skip-partition option. Analysis: do_rename() and mysql_rm_table_no_locks() invoke function ha_resolve_by_legacy_type() to get the handlerton* based on FRM's legacy_db_type. These functions continue to process even when the handlerton returned is NULL. The consequence is that, RENAME and DROP commands succeeds removing only FRM files and leaving *.par files related to partitions. There are side-effects on these files not being removed. Ex: CREATE TABLE fail if mysqld is started without --skip-partition, and if the table name is same as RENAME'ed or DROP'ed table name. Fix: Check for handlerton returned by ha_resolve_by_legacy_type() call during execution of RENAME, DROP TABLE and TRUNCATE table command's and throw error if handlerton is NULL, because such plugin is not installed.
1 parent dd41f0d commit 1aaaa84

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

mysql-test/r/partition_disabled.result

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FLUSH TABLES;
33
SELECT * FROM t1;
44
ERROR HY000: The MySQL server is running with the --skip-partition option so it cannot execute this statement
55
TRUNCATE TABLE t1;
6-
ERROR 42S02: Table 'test.t1' doesn't exist
6+
ERROR HY000: Storage engine for table 'test'.'t1' is not loaded.
77
ANALYZE TABLE t1;
88
Table Op Msg_type Msg_text
99
test.t1 analyze Error The MySQL server is running with the --skip-partition option so it cannot execute this statement
@@ -42,7 +42,6 @@ ALTER TABLE t1 ENGINE Memory;
4242
ERROR HY000: The MySQL server is running with the --skip-partition option so it cannot execute this statement
4343
ALTER TABLE t1 ADD (new INT);
4444
ERROR HY000: The MySQL server is running with the --skip-partition option so it cannot execute this statement
45-
DROP TABLE t1;
4645
CREATE TABLE t1 (
4746
firstname VARCHAR(25) NOT NULL,
4847
lastname VARCHAR(25) NOT NULL,

mysql-test/t/partition_disabled.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ALTER TABLE t1 ANALYZE PARTITION ALL;
2929
ALTER TABLE t1 REBUILD PARTITION ALL;
3030
ALTER TABLE t1 ENGINE Memory;
3131
ALTER TABLE t1 ADD (new INT);
32-
DROP TABLE t1;
32+
--remove_file $MYSQLD_DATADIR/test/t1.frm
3333

3434
--error ER_OPTION_PREVENTS_STATEMENT
3535
CREATE TABLE t1 (

sql/datadict.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,16 @@ bool dd_frm_storage_engine(THD *thd, const char *db, const char *table_name,
112112
dd_frm_type(thd, path, &db_type);
113113

114114
/* Type is unknown if the object is not found or is not a table. */
115-
if (db_type == DB_TYPE_UNKNOWN ||
116-
!(*table_type= ha_resolve_by_legacy_type(thd, db_type)))
115+
if (db_type == DB_TYPE_UNKNOWN)
117116
{
118117
my_error(ER_NO_SUCH_TABLE, MYF(0), db, table_name);
119118
return TRUE;
120119
}
120+
else if (!(*table_type= ha_resolve_by_legacy_type(thd, db_type)))
121+
{
122+
my_error(ER_STORAGE_ENGINE_NOT_LOADED, MYF(0), db, table_name);
123+
return TRUE;
124+
}
121125

122126
return FALSE;
123127
}

sql/share/errmsg-utf8.txt

+2
Original file line numberDiff line numberDiff line change
@@ -6950,6 +6950,8 @@ ER_INCONSISTENT_ERROR
69506950
ER_READ_ONLY_MODE
69516951
eng "Running in read-only mode"
69526952

6953+
ER_STORAGE_ENGINE_NOT_LOADED
6954+
eng "Storage engine for table '%s'.'%s' is not loaded."
69536955
#
69546956
# End of 5.7 error messages.
69556957
#

sql/sql_rename.cc

+8-6
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,13 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
272272
{
273273
case FRMTYPE_TABLE:
274274
{
275-
if (!(rc= mysql_rename_table(ha_resolve_by_legacy_type(thd,
276-
table_type),
277-
ren_table->db, old_alias,
275+
handlerton *hton= ha_resolve_by_legacy_type(thd, table_type);
276+
if (table_type != DB_TYPE_UNKNOWN && !hton)
277+
{
278+
my_error(ER_STORAGE_ENGINE_NOT_LOADED, MYF(0), ren_table->db, old_alias);
279+
DBUG_RETURN(1);
280+
}
281+
if (!(rc= mysql_rename_table(hton, ren_table->db, old_alias,
278282
new_db, new_alias, 0)))
279283
{
280284
if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
@@ -289,9 +293,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
289293
triggers appropriately. So let us revert operations on .frm
290294
and handler's data and report about failure to rename table.
291295
*/
292-
(void) mysql_rename_table(ha_resolve_by_legacy_type(thd,
293-
table_type),
294-
new_db, new_alias,
296+
(void) mysql_rename_table(hton, new_db, new_alias,
295297
ren_table->db, old_alias, 0);
296298
}
297299
}

sql/sql_table.cc

+7
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,13 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
24202420
DBUG_PRINT("info", ("frm_db_type %d from %s", frm_db_type, path));
24212421
}
24222422
table_type= ha_resolve_by_legacy_type(thd, frm_db_type);
2423+
if (frm_db_type != DB_TYPE_UNKNOWN && !table_type)
2424+
{
2425+
my_error(ER_STORAGE_ENGINE_NOT_LOADED, MYF(0), db, table->table_name);
2426+
wrong_tables.free();
2427+
error= 1;
2428+
goto err;
2429+
}
24232430
// Remove extension for delete
24242431
*(end= path + path_length - reg_ext_length)= '\0';
24252432
DBUG_PRINT("info", ("deleting table of type %d",

0 commit comments

Comments
 (0)