diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index f0539559dc7..f714e6646de 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -1907,3 +1907,15 @@ t1 CREATE TABLE `t1` ( `b` bigint(20) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; +create table t1 (i int); +alter table t1 add unique index if not exists idx(i); +alter table t1 add unique index if not exists idx(i); +Warnings: +Note 1061 Duplicate key name 'idx' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) DEFAULT NULL, + UNIQUE KEY `idx` (`i`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 247a79e2bda..2053e2d9d59 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -1651,3 +1651,12 @@ alter table t1 change column if exists a b bigint; show create table t1; DROP TABLE t1; +# +# MDEV-4437 ALTER TABLE .. ADD UNIQUE INDEX IF NOT EXISTS causes syntax error. +# + +create table t1 (i int); +alter table t1 add unique index if not exists idx(i); +alter table t1 add unique index if not exists idx(i); +show create table t1; +DROP TABLE t1; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 52f54687266..7f39720ab56 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -955,10 +955,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %parse-param { THD *thd } %lex-param { THD *thd } /* - Currently there are 164 shift/reduce conflicts. + Currently there are 163 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 164 +%expect 163 /* Comments for TOKENS. @@ -5900,7 +5900,7 @@ key_def: if (add_create_index (Lex, $1, $3)) MYSQL_YYABORT; } - | opt_constraint constraint_key_type opt_ident key_alg + | opt_constraint constraint_key_type opt_if_not_exists_ident key_alg '(' key_list ')' { Lex->option_list= NULL; } normal_key_options