Skip to content

Commit

Permalink
MDEV-11548 Reproducible server crash after the 2nd ALTER TABLE ADD FO…
Browse files Browse the repository at this point in the history
…REIGN KEY IF NOT EXISTS.

        Have to use 'keyname' to check the name uniqueness.
  • Loading branch information
Alexey Botchkov committed Jan 9, 2017
1 parent eed319b commit 171e59e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
15 changes: 15 additions & 0 deletions mysql-test/r/alter_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -2076,3 +2076,18 @@ tab1 CREATE TABLE `tab1` (
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE `tab1`;
#
# MDEV-11548 Reproducible server crash after the 2nd ALTER TABLE ADD FOREIGN KEY IF NOT EXISTS
#
CREATE TABLE t1 (id INT UNSIGNED NOT NULL PRIMARY KEY);
CREATE TABLE t2 (id1 INT UNSIGNED NOT NULL);
ALTER TABLE t2
ADD FOREIGN KEY IF NOT EXISTS (id1)
REFERENCES t1 (id);
ALTER TABLE t2
ADD FOREIGN KEY IF NOT EXISTS (id1)
REFERENCES t1 (id);
Warnings:
Note 1061 Duplicate key name 'id1'
DROP TABLE t2;
DROP TABLE t1;
19 changes: 19 additions & 0 deletions mysql-test/t/alter_table.test
Original file line number Diff line number Diff line change
Expand Up @@ -1737,3 +1737,22 @@ SHOW CREATE TABLE `tab1`;
ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT;
SHOW CREATE TABLE `tab1`;
DROP TABLE `tab1`;

--echo #
--echo # MDEV-11548 Reproducible server crash after the 2nd ALTER TABLE ADD FOREIGN KEY IF NOT EXISTS
--echo #

CREATE TABLE t1 (id INT UNSIGNED NOT NULL PRIMARY KEY);
CREATE TABLE t2 (id1 INT UNSIGNED NOT NULL);

ALTER TABLE t2
ADD FOREIGN KEY IF NOT EXISTS (id1)
REFERENCES t1 (id);

ALTER TABLE t2
ADD FOREIGN KEY IF NOT EXISTS (id1)
REFERENCES t1 (id);

DROP TABLE t2;
DROP TABLE t1;

2 changes: 1 addition & 1 deletion sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5943,7 +5943,7 @@ handle_if_exists_options(THD *thd, TABLE *table, Alter_info *alter_info)
while ((f_key= fk_key_it++))
{
if (my_strcasecmp(system_charset_info, f_key->foreign_id->str,
key->name.str) == 0)
keyname) == 0)
goto remove_key;
}
}
Expand Down

0 comments on commit 171e59e

Please sign in to comment.