Bug #40161 Parser allows useless/erroneous syntax for ALTER TABLE's DROP FOREIGN KEY clause
Submitted: 20 Oct 2008 6:22 Modified: 12 Sep 2012 12:11
Reporter: Dmitry Lenev Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:4.1, 5.0, 5,1, 6.0 bzr OS:Any
Assigned to: CPU Architecture:Any

[20 Oct 2008 6:22] Dmitry Lenev
Description:
Parser allows to omit foreign key name in DROP FOREIGN KEY clause of ALTER TABLE. Specifying this clause without foreign key name does not make any sense and leads to InnoDB emitting error during statement execution.
Note that such permissive rule for DROP FOREIGN KEY clause is responsible for at least two shift/reduce conflicts in grammar.

How to repeat:
create table t1 (pk int primary key) engine=innodb;
create table t2 (fk int, constraint foreign key (fk) references t1 (pk)) engine=innodb;

# Emits error
alter table t2 drop foreign key;
# ERROR HY000: Can't create table 'test.#sql-7a84_1' (errno: 150)

# Shows that error was caused by InnoDB's built-in parser not accepting
# such a construct.
show engine innodb status;
#Type   Name    Status
#InnoDB
#...
#------------------------
#LATEST FOREIGN KEY ERROR
#------------------------
#081020  8:56:53 Error in foreign key constraint of table test/#sql-7a84_1:
#foreign key:
#Syntax error close to:
#

Suggested fix:
Fix grammar to always require foreign key name in this clause.
[20 Oct 2008 7:03] Sveta Smirnova
Thank you for the report.

Verified as described.