From 0e8cda613094523583f4b97923dab12bcdca5626 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 25 Jan 2024 22:39:29 +0100 Subject: [PATCH] MDEV-33313 Incorrect error message for "ALTER TABLE ... DROP CONSTRAINT ..., DROP col, DROP col" --- mysql-test/main/alter_table.result | 8 ++++++++ mysql-test/main/alter_table.test | 9 +++++++++ sql/sql_table.cc | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 38fe52348c5..c3d364b8edb 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -3124,5 +3124,13 @@ CREATE TEMPORARY TABLE t2 LIKE t1; DROP TEMPORARY TABLE t2; DROP TABLE t1; # +# MDEV-33313 Incorrect error message for "ALTER TABLE ... DROP CONSTRAINT ..., DROP col, DROP col" +# +create table t2(id int primary key) engine=innodb; +create table t1(id int primary key, t2_id int, constraint t1_fk_t2_id foreign key(t2_id) references t2(id)) engine=innodb; +alter table t1 drop constraint t1_fk_t2_id, drop t2_id, drop t2_id; +ERROR 42000: Can't DROP COLUMN `t2_id`; check that it exists +drop table t1, t2; +# # End of 10.6 tests # diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test index 051a0b9fd08..053ce29bdee 100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@ -2406,6 +2406,15 @@ CREATE TEMPORARY TABLE t2 LIKE t1; DROP TEMPORARY TABLE t2; DROP TABLE t1; +--echo # +--echo # MDEV-33313 Incorrect error message for "ALTER TABLE ... DROP CONSTRAINT ..., DROP col, DROP col" +--echo # +create table t2(id int primary key) engine=innodb; +create table t1(id int primary key, t2_id int, constraint t1_fk_t2_id foreign key(t2_id) references t2(id)) engine=innodb; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop constraint t1_fk_t2_id, drop t2_id, drop t2_id; +drop table t1, t2; + --echo # --echo # End of 10.6 tests --echo # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 8a918db5542..cfef41b1ab8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -8804,7 +8804,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, case Alter_drop::CHECK_CONSTRAINT: case Alter_drop::PERIOD: my_error(ER_CANT_DROP_FIELD_OR_KEY, MYF(0), drop->type_name(), - alter_info->drop_list.head()->name); + drop->name); goto err; case Alter_drop::FOREIGN_KEY: // Leave the DROP FOREIGN KEY names in the alter_info->drop_list.