Bug #6340 Constraint name of foreign key not stored
Submitted: 31 Oct 2004 0:05 Modified: 3 Nov 2004 14:02
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1.8-debug OS:Linux (SuSE 8.2)
Assigned to: Marko Mäkelä CPU Architecture:Any

[31 Oct 2004 0:05] Peter Gulutzan
Description:
I should not need to use spaces around a delimited constraint name. But If I say 
"CONSTRAINT`name-x`FOREIGN KEY ..." instead of 
"CONSTRAINT `name-x` FOREIGN KEY ..." 
the name is not stored as the constraint name. 
According to SHOW CREATE TABLE, it has a default name like `t3_ibfk_1`. 

How to repeat:
mysql> create table t1(s1 int,primary key(s1)) engine=innodb; 
Query OK, 0 rows affected (2.58 sec) 
 
mysql> create table t2(s1 int,constraint `a1` foreign key (s1) references t1(s1)) 
engine=innodb; 
Query OK, 0 rows affected (0.34 sec) 
 
mysql> show create table t2; 
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Table | Create Table                                                                                                                                                           
| 
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| t2    | CREATE TABLE `t2` ( 
  `s1` int(11) default NULL, 
  KEY `a1` (`s1`), 
  CONSTRAINT `a1` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 | 
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.00 sec) 
 
mysql> create table t3(s1 int,constraint`a2`foreign key (s1) references t1(s1)) 
engine=innodb; 
Query OK, 0 rows affected (0.73 sec) 
 
mysql> show create table t3; 
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Table | Create Table                                                                                                                                                                  
| 
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| t3    | CREATE TABLE `t3` ( 
  `s1` int(11) default NULL, 
  KEY `a2` (`s1`), 
  CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 | 
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.00 sec)
[1 Nov 2004 7:12] Heikki Tuuri
Marko,

please tweak the FOREIGN KEY parser of InnoDB.

Thank you,

Heikki
[3 Nov 2004 9:45] Marko Mäkelä
The bug is also in the 4.0 series. While looking at this bug, I noticed another problem:
create table `constraint foo foreign key(a)references bar(a)`(...)
will trick InnoDB into creating a constraint. The reserved words should not be searched for inside quotes. I'll fix both bugs in 4.0.
[3 Nov 2004 13:24] Marko Mäkelä
ChangeSet@1.2058, 2004-11-03 14:56:48+02:00, marko@hundin.mysql.fi
  InnoDB: fix bugs in the FOREIGN KEY parser (Bug #6340)
[3 Nov 2004 14:02] Marko Mäkelä
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

I pushed the change to the 4.0 source tree. It will be merged to the 4.1 and 5.0 source trees later.