diff options
author | Monty <monty@mariadb.org> | 2021-03-22 16:05:08 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-05-19 22:54:13 +0200 |
commit | 3c578b0a960ce3f625b8e24c4c7605cec74e0154 (patch) | |
tree | 340b602150396509eabd2571439105823db58c14 /sql/sql_rename.cc | |
parent | c844a76b0aa79f763e87b50663e97a2a135be457 (diff) | |
download | mariadb-git-3c578b0a960ce3f625b8e24c4c7605cec74e0154.tar.gz |
Check if we can rename triggers before doing an ALTER TABLE ... RENAME
ALTER TABLE .. RENAME, when used with the inplace algorithm, does:
- Do an inplace or online alter to the new definition
- Rename to new name
- Update triggers.
If update triggers would fail, we would rename the table back.
The problem with this approach is that the table would have the new
definition but the rename would fail. The binary log would also not be
updated.
The solution to this is to very early check if we can rename triggers
and give an error if this would fail.
Both ALTER TABLE ... RENAME and RENAME TABLE is fixed.
This was implemented by moving the pre-check of rename table in triggers
from Table_triggers_list::change_table_name() to
Table_triggers_list::prepare_for_rename().
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r-- | sql/sql_rename.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 2b2f32cf126..ec782792f30 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -1,6 +1,6 @@ /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. - Copyright (c) 2011, 2013, Monty Program Ab. + Copyright (c) 2011, 2021, Monty Program Ab. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -339,6 +339,7 @@ do_rename(THD *thd, rename_param *param, DDL_LOG_STATE *ddl_log_state, int rc= 1; handlerton *hton; LEX_CSTRING *old_alias, *new_alias; + TRIGGER_RENAME_PARAM rename_param; DBUG_ENTER("do_rename"); DBUG_PRINT("enter", ("skip_error: %d", (int) skip_error)); @@ -361,6 +362,15 @@ do_rename(THD *thd, rename_param *param, DDL_LOG_STATE *ddl_log_state, if (hton->flags & HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE) *force_if_exists= 1; + /* Check if we can rename triggers */ + if (Table_triggers_list::prepare_for_rename(thd, &rename_param, + &ren_table->db, + old_alias, + &ren_table->table_name, + new_db, + new_alias)) + DBUG_RETURN(!skip_error); + thd->replication_flags= 0; if (ddl_log_rename_table(thd, ddl_log_state, hton, @@ -379,7 +389,9 @@ do_rename(THD *thd, rename_param *param, DDL_LOG_STATE *ddl_log_state, debug_crash_here("ddl_log_rename_before_rename_trigger"); - if (!(rc= Table_triggers_list::change_table_name(thd, &ren_table->db, + if (!(rc= Table_triggers_list::change_table_name(thd, + &rename_param, + &ren_table->db, old_alias, &ren_table->table_name, new_db, |