[MDEV-18463] Don't allow multiple table CONSTRAINTs with the same name. Created: 2019-02-04  Updated: 2019-12-08  Resolved: 2019-12-08

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Create Table
Affects Version/s: 10.2
Fix Version/s: 10.2.30

Type: Bug Priority: Major
Reporter: Alexey Botchkov Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

MariaDB [test]> create table tfk (id INT, c1 INT, c2 INT NOT NULL, CONSTRAINT sid FOREIGN KEY (`c1`) REFERENCES tpk (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT sid check (c2>15));
Query OK, 0 rows affected (0.23 sec)
 
MariaDB [test]> show create table tfk;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                                                   |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tfk   | CREATE TABLE `tfk` (
  `id` int(11) DEFAULT NULL,
  `c1` int(11) DEFAULT NULL,
  `c2` int(11) NOT NULL,
  KEY `sid` (`c1`),
  CONSTRAINT `sid` FOREIGN KEY (`c1`) REFERENCES `tpk` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `sid` CHECK (`c2` > 15)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+-------------------------------------------------------------------------------------------

So two constraints with the same name 'sid' were created.



 Comments   
Comment by Anel Husakovic [ 2019-02-04 ]

I think this MDEV should be related to this one MDEV-16630 right ?
holyfoot I would like to work on this.
Regarding the MDEV-16630 what should be the strategy about ?

Comment by Federico Razzoli [ 2019-10-19 ]

Same bug is in MySQL 8. I couldn't find the bug in their bug tracker, but it could be worded in many ways...

mysql> create table tpk (id int primary key);                                                                                             Query OK, 0 rows affected (0.03 sec)
 
mysql> create table tfk (id INT, c1 INT, c2 INT NOT NULL, CONSTRAINT sid FOREIGN KEY (`c1`) REFERENCES tpk (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT sid check (c2>15));
Query OK, 0 rows affected (0.04 sec)
 
mysql> show create table tfk \G
*************************** 1. row ***************************
       Table: tfk
Create Table: CREATE TABLE `tfk` (
  `id` int(11) DEFAULT NULL,
  `c1` int(11) DEFAULT NULL,
  `c2` int(11) NOT NULL,
  KEY `sid` (`c1`),
  CONSTRAINT `sid` FOREIGN KEY (`c1`) REFERENCES `tpk` (`id`),
  CONSTRAINT `sid` CHECK ((`c2` > 15))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)

Comment by Alexey Botchkov [ 2019-12-08 ]

https://github.com/MariaDB/server/commit/fd1979bc9a535735ed3f3a7dbb67d09568dd8417

Generated at Thu Feb 08 08:44:17 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.