mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-24532 Table corruption ER_NO_SUCH_TABLE_IN_ENGINE .. on table with foreign key
When doing a truncate on an Innodb under lock tables, InnoDB would rename the old table to #sql-... and recreate a new 't1' table. The table lock would still be on the #sql-table. When doing ALTER TABLE, Innodb would do the changes on the #sql table (which would disappear on close). When the SQL layer, as part of inline alter table, would close the original t1 table (#sql in InnoDB) and then reopen the t1 table, Innodb would notice that this does not match it's own (old) t1 table and generate an error. Fixed by adding code in truncate table that if we are under lock tables and truncating an InnoDB table, we would close, reopen and lock the table after truncate. This will remove the #sql table and ensure that lock tables is using the new empty table. Reviewer: Marko Mäkelä
This commit is contained in:
@ -439,6 +439,15 @@ bool Sql_cmd_truncate_table::truncate_table(THD *thd, TABLE_LIST *table_ref)
|
||||
*/
|
||||
error= handler_truncate(thd, table_ref, FALSE);
|
||||
|
||||
if (error == TRUNCATE_OK && thd->locked_tables_mode &&
|
||||
(table_ref->table->file->ht->flags &
|
||||
HTON_REQUIRES_CLOSE_AFTER_TRUNCATE))
|
||||
{
|
||||
thd->locked_tables_list.mark_table_for_reopen(thd, table_ref->table);
|
||||
if (unlikely(thd->locked_tables_list.reopen_tables(thd, true)))
|
||||
thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
All effects of a TRUNCATE TABLE operation are committed even if
|
||||
truncation fails in the case of non transactional tables. Thus, the
|
||||
|
Reference in New Issue
Block a user