Bug #46124 Foreign keys: crash if alter table drop foreign key
Submitted: 10 Jul 2009 23:07 Modified: 29 Jul 2009 10:24
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:6.1.0-alpha-debug-log OS:Linux (SUSE 11.1 64-bit)
Assigned to: Dmitry Lenev CPU Architecture:Any

[10 Jul 2009 23:07] Peter Gulutzan
Description:
I'm using mysql-6.1-fk-stage.
I start the server with mysqld --foreign-key-all-engines=1.

I try to drop the foreign key of a table.
It doesn't matter whether the table exists or not.
Crash.

How to repeat:
alter table txx drop foreign key;
[12 Jul 2009 0:51] MySQL Verification Team
Thank you for the bug report.

miguel@lara:~/dbs/6.1fk-stage$ bi/mysql -uroot --port=3307
bash: bi/mysql: No such file or directory
miguel@lara:~/dbs/6.1fk-stage$ bin/mysql -uroot --port=3307
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 6.1.0-alpha-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> alter table txx drop foreign key;
ERROR 2013 (HY000): Lost connection to MySQL server during query
[13 Jul 2009 19:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/78579

2737 Dmitry Lenev	2009-07-13
      Fix for bug #46124 "Foreign keys: crash if alter table drop foreign key".
      
      In --foreign-key-all-engines=1 mode ALTER TABLE with DROP FOREIGN KEY
      clause without foreign key name specified crashed server even if table
      didn't exist.
      
      This crash occured because code handling metadata locking for names of
      foreign keys were not ready to handle NULL pointer name produced by such
      clause.
      
      This fix simply changes grammar to make name in DROP FOREIGN KEY clause
      mandatory. It is OK to do so because omitting name in such clause is
      non-standard and leads to error for native InnoDB keys. For other engines
      in --foreign-key-all-engines=0 mode DROP FOREIGN KEY clause is simply
      ignored but even for them omitting name from it does not make any sense.
      
      As a bonus we reduce number of shift/reduce conflicts in the parser.
      
      QQ: Should this patch to be back-ported to 5.4?
     @ mysql-test/r/foreign_key.result
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ mysql-test/r/foreign_key_all_engines.result
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ mysql-test/t/foreign_key.test
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ mysql-test/t/foreign_key_all_engines.test
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ sql/sql_yacc.yy
        Changed grammar to make foreign key name in DROP FOREIGN KEY
        clause mandatory. Allowing to omit it does not make any sense
        and requires additional check during later stages of ALTER
        TABLE execution.
[29 Jul 2009 10:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/79512

2761 Dmitry Lenev	2009-07-29
      Fix for bug #46124 "Foreign keys: crash if alter table drop foreign key".
      
      In --foreign-key-all-engines=1 mode ALTER TABLE with DROP FOREIGN KEY
      clause without foreign key name specified crashed server even if table
      didn't exist.
      
      This crash occured because code handling metadata locking for names of
      foreign keys were not ready to handle NULL pointer name produced by such
      clause.
      
      This fix simply changes grammar to make name in DROP FOREIGN KEY clause
      mandatory. It is OK to do so because omitting name in such clause is
      non-standard and leads to error for native InnoDB keys. For other engines
      in --foreign-key-all-engines=0 mode DROP FOREIGN KEY clause is simply
      ignored but even for them omitting name from it does not make any sense.
      
      As a bonus we reduce number of shift/reduce conflicts in the parser.
     @ mysql-test/r/foreign_key.result
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ mysql-test/r/foreign_key_all_engines.result
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ mysql-test/t/foreign_key.test
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ mysql-test/t/foreign_key_all_engines.test
        Added test for bug #46124 "Foreign keys: crash if alter table drop foreign key".
     @ sql/sql_yacc.yy
        Changed grammar to make foreign key name in DROP FOREIGN KEY
        clause mandatory. Allowing to omit it does not make any sense
        and requires additional check during later stages of ALTER
        TABLE execution.
[29 Jul 2009 10:24] Dmitry Lenev
Fix for this bug was pushed into mysql-6.1-fk-stage tree. Since this problem was reported against tree which is not publicly available yet I am simply closing this bug report.