diff --git a/mysql-test/suite/innodb/r/innodb_information_schema.result b/mysql-test/suite/innodb/r/innodb_information_schema.result index 6f97fdcc0a0..1b83bc29493 100644 --- a/mysql-test/suite/innodb/r/innodb_information_schema.result +++ b/mysql-test/suite/innodb/r/innodb_information_schema.result @@ -51,4 +51,4 @@ RUNNING 4 0 0 7 1 0 REPEATABLE READ 1 1 trx_isolation_level trx_unique_checks trx_foreign_key_checks SERIALIZABLE 0 0 trx_state trx_isolation_level trx_last_foreign_key_error -RUNNING REPEATABLE READ `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c02`) REFERENCES `t1` (`c01`) +RUNNING REPEATABLE READ `test`.`t2`, CONSTRAINT `fk1` FOREIGN KEY (`c02`) REFERENCES `t1` (`c01`) diff --git a/mysql-test/suite/rpl/r/rpl_mdev382.result b/mysql-test/suite/rpl/r/rpl_mdev382.result index 6cd6aa09ede..bc245a073cd 100644 --- a/mysql-test/suite/rpl/r/rpl_mdev382.result +++ b/mysql-test/suite/rpl/r/rpl_mdev382.result @@ -315,7 +315,7 @@ CREATE TABLE `t``1` ( `a``` INT PRIMARY KEY) ENGINE=innodb; CREATE TABLE `t``2` ( `b``` INT PRIMARY KEY, `c``` INT NOT NULL, FOREIGN KEY fk (`c```) REFERENCES `t``1`(`a```)) ENGINE=innodb; TRUNCATE `t``1`; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`db1``; select 'oops!'`.`t``2`, CONSTRAINT `t``2_ibfk_1` FOREIGN KEY (`c```) REFERENCES `db1``; select 'oops!'`.`t``1` (`a```)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`db1``; select 'oops!'`.`t``2`, CONSTRAINT `fk` FOREIGN KEY (`c```) REFERENCES `db1``; select 'oops!'`.`t``1` (`a```)) DROP TABLE `t``2`; DROP TABLE `t``1`; *** Test correct quoting of DELETE FROM statement binlogged for HEAP table that is emptied due to server restart diff --git a/sql/sql_table.cc b/sql/sql_table.cc index bd43dfff478..68c890d41da 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5476,7 +5476,7 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info) if (remove_key) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_DUP_KEYNAME, ER(ER_DUP_KEYNAME), key->name.str); + ER_DUP_KEYNAME, ER(ER_DUP_KEYNAME), keyname); key_it.remove(); if (key->type == Key::FOREIGN_KEY) { diff --git a/storage/xtradb/dict/dict0dict.cc b/storage/xtradb/dict/dict0dict.cc index a20456fe3cf..0aaec42cd2f 100644 --- a/storage/xtradb/dict/dict0dict.cc +++ b/storage/xtradb/dict/dict0dict.cc @@ -4242,18 +4242,45 @@ loop: goto loop; } + if (my_isspace(cs, *ptr)) { + ptr1 = dict_accept(cs, ptr, "IF", &success); + + if (success) { + if (!my_isspace(cs, *ptr1)) { + goto loop; + } + ptr1 = dict_accept(cs, ptr1, "NOT", &success); + if (!success) { + goto loop; + } + ptr1 = dict_accept(cs, ptr1, "EXISTS", &success); + if (!success) { + goto loop; + } + ptr = ptr1; + } + } + ptr = dict_accept(cs, ptr, "(", &success); if (!success) { - /* MySQL allows also an index id before the '('; we - skip it */ - ptr = dict_skip_word(cs, ptr, &success); + if (constraint_name) { + /* MySQL allows also an index id before the '('; we + skip it */ + ptr = dict_skip_word(cs, ptr, &success); + if (!success) { + dict_foreign_report_syntax_err( + name, start_of_latest_foreign, ptr); + return(DB_CANNOT_ADD_CONSTRAINT); + } + } + else { + while (my_isspace(cs, *ptr)) { + ptr++; + } - if (!success) { - dict_foreign_report_syntax_err( - name, start_of_latest_foreign, ptr); - - return(DB_CANNOT_ADD_CONSTRAINT); + ptr = dict_scan_id(cs, ptr, heap, + &constraint_name, FALSE, FALSE); } ptr = dict_accept(cs, ptr, "(", &success); @@ -4727,6 +4754,7 @@ dict_foreign_parse_drop_constraints( char* str; size_t len; const char* ptr; + const char* ptr1; const char* id; struct charset_info_st* cs; @@ -4777,6 +4805,16 @@ loop: goto syntax_error; } + ptr1 = dict_accept(cs, ptr, "IF", &success); + + if (success && my_isspace(cs, *ptr1)) { + ptr1 = dict_accept(cs, ptr1, "EXISTS", &success); + if (success) { + + ptr = ptr1; + } + } + ptr = dict_scan_id(cs, ptr, heap, &id, FALSE, TRUE); if (id == NULL) {