Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-18463

Don't allow multiple table CONSTRAINTs with the same name.

Details

    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.

      Attachments

        Activity

          anel Anel Husakovic added a comment - - edited

          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 ?

          anel Anel Husakovic added a comment - - edited 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 ?

          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)
          

          f_razzoli Federico Razzoli added a comment - 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)
          holyfoot Alexey Botchkov added a comment - https://github.com/MariaDB/server/commit/fd1979bc9a535735ed3f3a7dbb67d09568dd8417

          People

            holyfoot Alexey Botchkov
            holyfoot Alexey Botchkov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.