mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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().
This commit is contained in:
@ -79,6 +79,30 @@ struct st_trg_execution_order
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Parameter to change_table_name_in_triggers()
|
||||
*/
|
||||
|
||||
class TRIGGER_RENAME_PARAM
|
||||
{
|
||||
public:
|
||||
TABLE table;
|
||||
bool upgrading50to51;
|
||||
bool got_error;
|
||||
|
||||
TRIGGER_RENAME_PARAM()
|
||||
{
|
||||
upgrading50to51= got_error= 0;
|
||||
table.reset();
|
||||
}
|
||||
~TRIGGER_RENAME_PARAM()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
||||
class Table_triggers_list;
|
||||
|
||||
/**
|
||||
@ -237,7 +261,14 @@ public:
|
||||
TABLE *table, bool names_only);
|
||||
static bool drop_all_triggers(THD *thd, const LEX_CSTRING *db,
|
||||
const LEX_CSTRING *table_name, myf MyFlags);
|
||||
static bool change_table_name(THD *thd, const LEX_CSTRING *db,
|
||||
static bool prepare_for_rename(THD *thd, TRIGGER_RENAME_PARAM *param,
|
||||
const LEX_CSTRING *db,
|
||||
const LEX_CSTRING *old_alias,
|
||||
const LEX_CSTRING *old_table,
|
||||
const LEX_CSTRING *new_db,
|
||||
const LEX_CSTRING *new_table);
|
||||
static bool change_table_name(THD *thd, TRIGGER_RENAME_PARAM *param,
|
||||
const LEX_CSTRING *db,
|
||||
const LEX_CSTRING *old_alias,
|
||||
const LEX_CSTRING *old_table,
|
||||
const LEX_CSTRING *new_db,
|
||||
@ -315,6 +346,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
bool add_table_for_trigger(THD *thd,
|
||||
const sp_name *trg_name,
|
||||
bool continue_if_not_exist,
|
||||
|
Reference in New Issue
Block a user