Skip to content

Commit 5977362

Browse files
committed
Manual merge from mysql-5.5 to mysql-5.6
2 parents 2f2e59b + e7d8f19 commit 5977362

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

sql/sql_rename.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -292,7 +292,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
292292
(void) mysql_rename_table(ha_resolve_by_legacy_type(thd,
293293
table_type),
294294
new_db, new_alias,
295-
ren_table->db, old_alias, 0);
295+
ren_table->db, old_alias, NO_FK_CHECKS);
296296
}
297297
}
298298
}

sql/sql_table.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5063,6 +5063,7 @@ make_unique_key_name(const char *field_name,KEY *start,KEY *end)
50635063
NO_FRM_RENAME Don't rename the FRM file
50645064
but only the table in the storage engine.
50655065
NO_HA_TABLE Don't rename table in engine.
5066+
NO_FK_CHECKS Don't check FK constraints during rename.
50665067
50675068
@return false OK
50685069
@return true Error
@@ -5080,12 +5081,17 @@ mysql_rename_table(handlerton *base, const char *old_db,
50805081
char tmp_name[NAME_LEN+1];
50815082
handler *file;
50825083
int error=0;
5084+
ulonglong save_bits= thd->variables.option_bits;
50835085
int length;
50845086
bool was_truncated;
50855087
DBUG_ENTER("mysql_rename_table");
50865088
DBUG_PRINT("enter", ("old: '%s'.'%s' new: '%s'.'%s'",
50875089
old_db, old_name, new_db, new_name));
50885090

5091+
// Temporarily disable foreign key checks
5092+
if (flags & NO_FK_CHECKS)
5093+
thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS;
5094+
50895095
file= (base == NULL ? 0 :
50905096
get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base));
50915097

@@ -5160,6 +5166,8 @@ mysql_rename_table(handlerton *base, const char *old_db,
51605166
}
51615167
#endif
51625168

5169+
// Restore options bits to the original value
5170+
thd->variables.option_bits= save_bits;
51635171

51645172
DBUG_RETURN(error != 0);
51655173
}
@@ -6572,7 +6580,7 @@ static bool mysql_inplace_alter_table(THD *thd,
65726580
*/
65736581
(void) mysql_rename_table(db_type,
65746582
alter_ctx->new_db, alter_ctx->new_alias,
6575-
alter_ctx->db, alter_ctx->alias, 0);
6583+
alter_ctx->db, alter_ctx->alias, NO_FK_CHECKS);
65766584
DBUG_RETURN(true);
65776585
}
65786586
}
@@ -7522,7 +7530,8 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list,
75227530
{
75237531
(void) mysql_rename_table(old_db_type,
75247532
alter_ctx->new_db, alter_ctx->new_alias,
7525-
alter_ctx->db, alter_ctx->table_name, 0);
7533+
alter_ctx->db, alter_ctx->table_name,
7534+
NO_FK_CHECKS);
75267535
error= -1;
75277536
}
75287537
}
@@ -8397,9 +8406,12 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
83978406
// Rename failed, delete the temporary table.
83988407
(void) quick_rm_table(thd, new_db_type, alter_ctx.new_db,
83998408
alter_ctx.tmp_name, FN_IS_TMP);
8409+
84008410
// Restore the backup of the original table to the old name.
84018411
(void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name,
8402-
alter_ctx.db, alter_ctx.alias, FN_FROM_IS_TMP);
8412+
alter_ctx.db, alter_ctx.alias,
8413+
FN_FROM_IS_TMP | NO_FK_CHECKS);
8414+
84038415
goto err_with_mdl;
84048416
}
84058417

@@ -8417,7 +8429,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
84178429
alter_ctx.new_db, alter_ctx.new_alias, 0);
84188430
// Restore the backup of the original table to the old name.
84198431
(void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name,
8420-
alter_ctx.db, alter_ctx.alias, FN_FROM_IS_TMP);
8432+
alter_ctx.db, alter_ctx.alias,
8433+
FN_FROM_IS_TMP | NO_FK_CHECKS);
84218434
goto err_with_mdl;
84228435
}
84238436

sql/sql_table.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -138,6 +138,8 @@ static const uint FRM_ONLY= 1 << 3;
138138
static const uint NO_HA_TABLE= 1 << 4;
139139
/** Don't resolve MySQL's fake "foo.sym" symbolic directory names. */
140140
static const uint SKIP_SYMDIR_ACCESS= 1 << 5;
141+
/** Don't check foreign key constraints while renaming table */
142+
static const uint NO_FK_CHECKS= 1 << 6;
141143

142144
uint filename_to_tablename(const char *from, char *to, uint to_length
143145
#ifndef DBUG_OFF

0 commit comments

Comments
 (0)