mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-25642 InnoDB rename table copy DDL fails while dropping the table
When doing a ALTER TABLE ... RENAME, MariaDB doesn't rename original table to #sql-backup, which it does in other cases, but insteads drops the original table directly. However this optimization doesn't work in case of InnoDB table with a foreign key constraint. During copy algorithm, InnoDB fails to rename the foreign key constraint(MDEV-25855). With this optimisation, InnoDB also fails to drop the original table because the table has FOREIGN Key constraint exist in INNODB_SYS_FOREIGN table. This leads to orphan .ibd file in InnoDB dictionary. so disabling this optimization when FK is involved. Reviewer: monty@mariadb.org
This commit is contained in:
@ -11009,7 +11009,12 @@ do_continue:;
|
||||
DBUG_PRINT("info", ("is_table_renamed: %d engine_changed: %d",
|
||||
alter_ctx.is_table_renamed(), engine_changed));
|
||||
|
||||
if (!alter_ctx.is_table_renamed())
|
||||
/*
|
||||
InnoDB cannot use the rename optimization when foreign key
|
||||
constraint is involved because InnoDB fails to drop the
|
||||
parent table due to foreign key constraint
|
||||
*/
|
||||
if (!alter_ctx.is_table_renamed() || alter_ctx.fk_error_if_delete_row)
|
||||
{
|
||||
backup_name.length= my_snprintf(backup_name_buff, sizeof(backup_name_buff),
|
||||
"%s-backup-%lx-%llx", tmp_file_prefix,
|
||||
@ -11044,7 +11049,7 @@ do_continue:;
|
||||
(void) quick_rm_table(thd, new_db_type, &alter_ctx.new_db,
|
||||
&alter_ctx.tmp_name, FN_IS_TMP);
|
||||
|
||||
if (!alter_ctx.is_table_renamed())
|
||||
if (!alter_ctx.is_table_renamed() || alter_ctx.fk_error_if_delete_row)
|
||||
{
|
||||
// Restore the backup of the original table to the old name.
|
||||
(void) mysql_rename_table(old_db_type, &alter_ctx.db, &backup_name,
|
||||
|
Reference in New Issue
Block a user