summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-09-06 22:31:30 +0200
committerSergei Golubchik <sergii@pisem.net>2013-09-06 22:31:30 +0200
commitb838d081ad346e52787753b1799c627922c4a6c7 (patch)
treedc8f1e21e6b40d5b72668571c570c9a3214fbf32 /sql/sql_table.cc
parent824db55ce53963a64fcf648b54500df22c57e9b2 (diff)
parent72c36f4415815d55ddb82b23682f3c549906c00e (diff)
downloadmariadb-git-b838d081ad346e52787753b1799c627922c4a6c7.tar.gz
mysql-5.5.33 merge
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 97a2ef03757..d7102c0e3f6 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -4655,6 +4655,8 @@ make_unique_key_name(const char *field_name,KEY *start,KEY *end)
FN_TO_IS_TMP new_name is temporary.
NO_FRM_RENAME Don't rename the FRM file
but only the table in the storage engine.
+ NO_FK_CHECKS Don't check FK constraints
+ during rename.
RETURN
FALSE OK
@@ -4673,9 +4675,14 @@ mysql_rename_table(handlerton *base, const char *old_db,
char tmp_name[SAFE_NAME_LEN+1];
handler *file;
int error=0;
+ ulonglong save_bits= thd->variables.option_bits;
DBUG_ENTER("mysql_rename_table");
DBUG_PRINT("enter", ("old: '%s'.'%s' new: '%s'.'%s'",
old_db, old_name, new_db, new_name));
+
+ // Temporarily disable foreign key checks
+ if (flags & NO_FK_CHECKS)
+ thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS;
file= (base == NULL ? 0 :
get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base));
@@ -4723,6 +4730,10 @@ mysql_rename_table(handlerton *base, const char *old_db,
my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error);
else if (!(flags & FN_IS_TMP))
mysql_audit_rename_table(thd, old_db, old_name, new_db, new_name);
+
+ // Restore options bits to the original value
+ thd->variables.option_bits= save_bits;
+
DBUG_RETURN(error != 0);
}
@@ -6327,7 +6338,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
new_db, new_alias))
{
(void) mysql_rename_table(old_db_type, new_db, new_alias, db,
- table_name, 0);
+ table_name, NO_FK_CHECKS);
error= -1;
}
}
@@ -7102,7 +7113,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
error= 1;
(void) quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
(void) mysql_rename_table(old_db_type, db, old_name, db, alias,
- FN_FROM_IS_TMP);
+ FN_FROM_IS_TMP | NO_FK_CHECKS);
}
else if (new_name != table_name || new_db != db)
{
@@ -7114,7 +7125,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
error= 1;
(void) quick_rm_table(new_db_type, new_db, new_alias, 0);
(void) mysql_rename_table(old_db_type, db, old_name, db, alias,
- FN_FROM_IS_TMP);
+ FN_FROM_IS_TMP | NO_FK_CHECKS);
}
else if (Table_triggers_list::change_table_name(thd, db, alias,
table_name, new_db,
@@ -7124,7 +7135,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
error= 1;
(void) quick_rm_table(new_db_type, new_db, new_alias, 0);
(void) mysql_rename_table(old_db_type, db, old_name, db,
- alias, FN_FROM_IS_TMP);
+ alias, FN_FROM_IS_TMP | NO_FK_CHECKS);
/*
If we were performing "fast"/in-place ALTER TABLE we also need
to restore old name of table in storage engine as a separate
@@ -7133,7 +7144,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (need_copy_table == ALTER_TABLE_METADATA_ONLY)
{
(void) mysql_rename_table(save_old_db_type, new_db, new_alias,
- db, table_name, NO_FRM_RENAME);
+ db, table_name,
+ NO_FRM_RENAME | NO_FK_CHECKS);
}
}
}