diff options
author | Annamalai Gurusami <annamalai.gurusami@oracle.com> | 2013-07-25 14:53:23 +0530 |
---|---|---|
committer | Annamalai Gurusami <annamalai.gurusami@oracle.com> | 2013-07-25 14:53:23 +0530 |
commit | 0c1ca4f0dbd5ade21c227026248a154ab2009dec (patch) | |
tree | d212a9d10fa2b40c09b1d1636cd44c3515879c17 /storage | |
parent | b06894217843f38d886c4f1a6d1e152961cfde99 (diff) | |
download | mariadb-git-0c1ca4f0dbd5ade21c227026248a154ab2009dec.tar.gz |
Bug #17076737 DUPLICATE CONSTRAINTS DISPLAYED WHEN NAME INCLUDES "_IBFK_"
Problem:
When the user specified foreign key name contains "_ibfk_", InnoDB wrongly
tries to rename it.
Solution:
When a table is renamed, all its associated foreign keys will also be renamed,
only if the foreign key names are automatically generated. If the foreign key
names are given by the user, even if it has _ibfk_ in it, it must not be
renamed.
rb#2935 approved by Jimmy, Krunal and Satya
Diffstat (limited to 'storage')
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 28 | ||||
-rw-r--r-- | storage/innobase/row/row0mysql.c | 20 | ||||
-rw-r--r-- | storage/innodb_plugin/handler/ha_innodb.cc | 6 | ||||
-rw-r--r-- | storage/innodb_plugin/row/row0mysql.c | 22 |
4 files changed, 49 insertions, 27 deletions
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4ac4a6d200e..9f5ba543a47 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -943,7 +943,8 @@ innobase_convert_from_id( } /********************************************************************** -Converts an identifier from my_charset_filename to UTF-8 charset. */ +Converts an identifier from my_charset_filename to UTF-8 charset. +@return result string length, as returned by strconvert() */ extern "C" uint innobase_convert_to_system_charset( @@ -953,23 +954,15 @@ innobase_convert_to_system_charset( ulint len, /* in: length of 'to', in bytes */ uint* errors) /* out: error return */ { - uint rlen; CHARSET_INFO* cs1 = &my_charset_filename; CHARSET_INFO* cs2 = system_charset_info; - rlen = strconvert(cs1, from, cs2, to, len, errors); - - if (*errors) { - fprintf(stderr, "InnoDB: There was a problem in converting" - "'%s' in charset %s to charset %s", from, cs1->name, - cs2->name); - } - - return(rlen); + return(strconvert(cs1, from, cs2, to, len, errors)); } /********************************************************************** -Converts an identifier from my_charset_filename to UTF-8 charset. */ +Converts an identifier from my_charset_filename to UTF-8 charset. +@return result string length, as returned by strconvert() */ extern "C" uint innobase_convert_to_filename_charset( @@ -979,19 +972,10 @@ innobase_convert_to_filename_charset( ulint len) /* in: length of 'to', in bytes */ { uint errors; - uint rlen; CHARSET_INFO* cs_to = &my_charset_filename; CHARSET_INFO* cs_from = system_charset_info; - rlen = strconvert(cs_from, from, cs_to, to, len, &errors); - - if (errors) { - fprintf(stderr, "InnoDB: There was a problem in converting" - "'%s' in charset %s to charset %s", from, cs_from->name, - cs_to->name); - } - - return(rlen); + return(strconvert(cs_from, from, cs_to, to, len, &errors)); } diff --git a/storage/innobase/row/row0mysql.c b/storage/innobase/row/row0mysql.c index e513dd6f2a8..037fb576a48 100644 --- a/storage/innobase/row/row0mysql.c +++ b/storage/innobase/row/row0mysql.c @@ -3802,12 +3802,28 @@ row_rename_table_for_mysql( if (!new_is_tmp) { /* Rename all constraints. */ char new_table_name[MAX_TABLE_NAME_LEN] = ""; + char old_table_utf8[MAX_TABLE_NAME_LEN] = ""; uint errors = 0; + strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); + innobase_convert_to_system_charset( + strchr(old_table_utf8, '/') + 1, + strchr(old_name, '/') +1, + MAX_TABLE_NAME_LEN, &errors); + + if (errors) { + /* Table name could not be converted from charset + my_charset_filename to UTF-8. This means that the + table name is already in UTF-8 (#mysql#50). */ + strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); + } + info = pars_info_create(); pars_info_add_str_literal(info, "new_table_name", new_name); pars_info_add_str_literal(info, "old_table_name", old_name); + pars_info_add_str_literal(info, "old_table_name_utf8", + old_table_utf8); strncpy(new_table_name, new_name, MAX_TABLE_NAME_LEN); innobase_convert_to_system_charset( @@ -3844,6 +3860,8 @@ row_rename_table_for_mysql( "new_db_name := SUBSTR(:new_table_name, 0,\n" " new_db_name_len);\n" "old_t_name_len := LENGTH(:old_table_name);\n" + "gen_constr_prefix := CONCAT(:old_table_name_utf8,\n" + " '_ibfk_');\n" "WHILE found = 1 LOOP\n" " SELECT ID INTO foreign_id\n" " FROM SYS_FOREIGN\n" @@ -3860,7 +3878,7 @@ row_rename_table_for_mysql( " id_len := LENGTH(foreign_id);\n" " IF (INSTR(foreign_id, '/') > 0) THEN\n" " IF (INSTR(foreign_id,\n" - " '_ibfk_') > 0)\n" + " gen_constr_prefix) > 0)\n" " THEN\n" " offset := INSTR(foreign_id, '_ibfk_') - 1;\n" " new_foreign_id :=\n" diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index adf7e1fb82c..971c55a623c 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -1052,7 +1052,8 @@ innobase_convert_from_id( } /********************************************************************** -Converts an identifier from my_charset_filename to UTF-8 charset. */ +Converts an identifier from my_charset_filename to UTF-8 charset. +@return result string length, as returned by strconvert() */ extern "C" uint innobase_convert_to_system_charset( @@ -11624,7 +11625,8 @@ test_innobase_convert_name() #endif /* UNIV_COMPILE_TEST_FUNCS */ /********************************************************************** -Converts an identifier from my_charset_filename to UTF-8 charset. */ +Converts an identifier from my_charset_filename to UTF-8 charset. +@return result string length, as returned by strconvert() */ extern "C" uint innobase_convert_to_filename_charset( diff --git a/storage/innodb_plugin/row/row0mysql.c b/storage/innodb_plugin/row/row0mysql.c index 05f5d7ab68c..57121448d11 100644 --- a/storage/innodb_plugin/row/row0mysql.c +++ b/storage/innodb_plugin/row/row0mysql.c @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 2000, 2012, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2000, 2013, Oracle and/or its affiliates. All Rights Reserved. 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 the Free Software @@ -3904,12 +3904,28 @@ row_rename_table_for_mysql( } else if (!new_is_tmp) { /* Rename all constraints. */ char new_table_name[MAX_TABLE_NAME_LEN] = ""; + char old_table_utf8[MAX_TABLE_NAME_LEN] = ""; uint errors = 0; + strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); + innobase_convert_to_system_charset( + strchr(old_table_utf8, '/') + 1, + strchr(old_name, '/') +1, + MAX_TABLE_NAME_LEN, &errors); + + if (errors) { + /* Table name could not be converted from charset + my_charset_filename to UTF-8. This means that the + table name is already in UTF-8 (#mysql#50). */ + strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); + } + info = pars_info_create(); pars_info_add_str_literal(info, "new_table_name", new_name); pars_info_add_str_literal(info, "old_table_name", old_name); + pars_info_add_str_literal(info, "old_table_name_utf8", + old_table_utf8); strncpy(new_table_name, new_name, MAX_TABLE_NAME_LEN); innobase_convert_to_system_charset( @@ -3946,6 +3962,8 @@ row_rename_table_for_mysql( "new_db_name := SUBSTR(:new_table_name, 0,\n" " new_db_name_len);\n" "old_t_name_len := LENGTH(:old_table_name);\n" + "gen_constr_prefix := CONCAT(:old_table_name_utf8,\n" + " '_ibfk_');\n" "WHILE found = 1 LOOP\n" " SELECT ID INTO foreign_id\n" " FROM SYS_FOREIGN\n" @@ -3962,7 +3980,7 @@ row_rename_table_for_mysql( " id_len := LENGTH(foreign_id);\n" " IF (INSTR(foreign_id, '/') > 0) THEN\n" " IF (INSTR(foreign_id,\n" - " '_ibfk_') > 0)\n" + " gen_constr_prefix) > 0)\n" " THEN\n" " offset := INSTR(foreign_id, '_ibfk_') - 1;\n" " new_foreign_id :=\n" |