Skip to content

Commit 89da203

Browse files
committed
Manual merge from mysql-5.6 to mysql-trunk
2 parents 90b825f + 5977362 commit 89da203

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

sql/sql_rename.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
292292
and handler's data and report about failure to rename table.
293293
*/
294294
(void) mysql_rename_table(hton, 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
@@ -5042,6 +5042,7 @@ make_unique_key_name(const char *field_name,KEY *start,KEY *end)
50425042
NO_FRM_RENAME Don't rename the FRM file
50435043
but only the table in the storage engine.
50445044
NO_HA_TABLE Don't rename table in engine.
5045+
NO_FK_CHECKS Don't check FK constraints during rename.
50455046
50465047
@return false OK
50475048
@return true Error
@@ -5059,12 +5060,17 @@ mysql_rename_table(handlerton *base, const char *old_db,
50595060
char tmp_name[NAME_LEN+1];
50605061
handler *file;
50615062
int error=0;
5063+
ulonglong save_bits= thd->variables.option_bits;
50625064
int length;
50635065
bool was_truncated;
50645066
DBUG_ENTER("mysql_rename_table");
50655067
DBUG_PRINT("enter", ("old: '%s'.'%s' new: '%s'.'%s'",
50665068
old_db, old_name, new_db, new_name));
50675069

5070+
// Temporarily disable foreign key checks
5071+
if (flags & NO_FK_CHECKS)
5072+
thd->variables.option_bits|= OPTION_NO_FOREIGN_KEY_CHECKS;
5073+
50685074
file= (base == NULL ? 0 :
50695075
get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base));
50705076

@@ -5139,6 +5145,8 @@ mysql_rename_table(handlerton *base, const char *old_db,
51395145
}
51405146
#endif
51415147

5148+
// Restore options bits to the original value
5149+
thd->variables.option_bits= save_bits;
51425150

51435151
DBUG_RETURN(error != 0);
51445152
}
@@ -6653,7 +6661,7 @@ static bool mysql_inplace_alter_table(THD *thd,
66536661
*/
66546662
(void) mysql_rename_table(db_type,
66556663
alter_ctx->new_db, alter_ctx->new_alias,
6656-
alter_ctx->db, alter_ctx->alias, 0);
6664+
alter_ctx->db, alter_ctx->alias, NO_FK_CHECKS);
66576665
DBUG_RETURN(true);
66586666
}
66596667
}
@@ -7638,7 +7646,8 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list,
76387646
{
76397647
(void) mysql_rename_table(old_db_type,
76407648
alter_ctx->new_db, alter_ctx->new_alias,
7641-
alter_ctx->db, alter_ctx->table_name, 0);
7649+
alter_ctx->db, alter_ctx->table_name,
7650+
NO_FK_CHECKS);
76427651
error= -1;
76437652
}
76447653
}
@@ -8512,9 +8521,12 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
85128521
// Rename failed, delete the temporary table.
85138522
(void) quick_rm_table(thd, new_db_type, alter_ctx.new_db,
85148523
alter_ctx.tmp_name, FN_IS_TMP);
8524+
85158525
// Restore the backup of the original table to the old name.
85168526
(void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name,
8517-
alter_ctx.db, alter_ctx.alias, FN_FROM_IS_TMP);
8527+
alter_ctx.db, alter_ctx.alias,
8528+
FN_FROM_IS_TMP | NO_FK_CHECKS);
8529+
85188530
goto err_with_mdl;
85198531
}
85208532

@@ -8532,7 +8544,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
85328544
alter_ctx.new_db, alter_ctx.new_alias, 0);
85338545
// Restore the backup of the original table to the old name.
85348546
(void) mysql_rename_table(old_db_type, alter_ctx.db, backup_name,
8535-
alter_ctx.db, alter_ctx.alias, FN_FROM_IS_TMP);
8547+
alter_ctx.db, alter_ctx.alias,
8548+
FN_FROM_IS_TMP | NO_FK_CHECKS);
85368549
goto err_with_mdl;
85378550
}
85388551

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
@@ -136,6 +136,8 @@ static const uint NO_FRM_RENAME= 1 << 2;
136136
static const uint FRM_ONLY= 1 << 3;
137137
/** Don't remove table in engine. Remove only .FRM and maybe .PAR files. */
138138
static const uint NO_HA_TABLE= 1 << 4;
139+
/** Don't check foreign key constraints while renaming table */
140+
static const uint NO_FK_CHECKS= 1 << 5;
139141

140142
uint filename_to_tablename(const char *from, char *to, uint to_length
141143
#ifndef DBUG_OFF

0 commit comments

Comments
 (0)