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

Create table accepts redundant UNIQUE and PRIMARY KEY syntax

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Trivial
    • Resolution: Unresolved
    • 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
    • 10.4, 10.5, 10.6
    • None
    • None

    Description

      MariaDB syntax allows any combination of UNIQUE and primary key.
      And if both are present in that column definition, then only primary key index is created:

      MariaDB [test]> CREATE or replace TABLE t1 ( i INT primary key UNIQUE UNIQUE  UNIQUE primary key unique );
      Query OK, 0 rows affected (0.09 sec)
       
      MariaDB [test]> show create table t1;
      +-------+--------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                           |
      +-------+--------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `i` int(11) NOT NULL,
        PRIMARY KEY (`i`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+--------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> CREATE or replace TABLE t1 ( i INT UNIQUE UNIQUE  UNIQUE);
      Query OK, 0 rows affected (0.10 sec)
       
      MariaDB [test]> show create table t1;
      +-------+---------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                  |
      +-------+---------------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `i` int(11) DEFAULT NULL,
        UNIQUE KEY `i` (`i`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+---------------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)
      

      mysql 5.6-8.0 creates in such case both unique + primary indexes:

      CREATE TABLE `t1` ( `i` int(11) NOT NULL, PRIMARY KEY (`i`), UNIQUE KEY `i` (`i`) ) ENGINE=InnoDB
      

      Attachments

        Activity

          People

            bar Alexander Barkov
            alice Alice Sherepa
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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