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

No warning when trying to name a primary key constraint

Details

    Description

      Our documentation says:

      "For UNIQUE keys, PRIMARY KEYs and FOREIGN KEYs, you can specify a name for the constraint, using the CONSTRAINT keyword. That name will be used in error messages."

      <https://mariadb.com/kb/en/library/create-table/>

      But for primary keys this is not true, the constraint name is just silently ignored:

      This CREATE succeeds without warning:

      CREATE TABLE t1 (
        id1 INT,
        id2 INT,
        CONSTRAINT `foo` PRIMARY KEY (id1),
        CONSTRAINT `bar` UNIQUE KEY(id2)
      );
      

      When verifying with SHOW CREATE TABLE the constraint name
      for the UNIQUE key is shown, but not that of the PRIMARY key:

      MariaDB [test]> show create table t1\G
      *************************** 1. row ***************************
             Table: t1
      Create Table: CREATE TABLE `t1` (
        `id1` int(11) NOT NULL,
        `id2` int(11) DEFAULT NULL,
        PRIMARY KEY (`id1`),
        UNIQUE KEY `bar` (`id2`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1
      

      INFORMATION_SCHEMA.TABLE_CONSTRAINTS also does not show the
      chosen name `foo` for the primary key:

      +--------------------+-------------------+-----------------+--------------+------------+-----------------+
      | CONSTRAINT_CATALOG | CONSTRAINT_SCHEMA | CONSTRAINT_NAME | TABLE_SCHEMA | TABLE_NAME | CONSTRAINT_TYPE |
      +--------------------+-------------------+-----------------+--------------+------------+-----------------+
      | def                | test              | PRIMARY         | test         | t1         | PRIMARY KEY     |
      | def                | test              | bar             | test         | t1         | UNIQUE          |
      +--------------------+-------------------+-----------------+--------------+------------+-----------------+
      

      And the name is not shown in primary key related error messages either, contrary to what the knowledge base claims:

      MariaDB [test]> insert into t1 values(1,1);
      Query OK, 1 row affected (0.004 sec)
       
      MariaDB [test]> insert into t1 values(2,1);
      ERROR 1062 (23000): Duplicate entry '1' for key 'bar'
       
      MariaDB [test]> insert into t1 values(1,2);
      ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
      

      My main concern though is that there is no warning on CREATE about an unsupported feature being used and the chosen name being discarded in favour of the hardcoded "PRIMARY" name string.

      Attachments

        Activity

          hholzgra Hartmut Holzgraefe created issue -

          I edited the CREATE TABLE page in the documentation to clarify that for PRIMARY KEY the name is accepted but ignored. This should be also explained at CONSTRAINT page https://mariadb.com/kb/en/library/constraint/ where the syntax does not even mention index_name can be specified for PRIMARY KEY

          The server definitely should return warning so it is not documentation only problem.

          salle Alexander Keremidarski added a comment - I edited the CREATE TABLE page in the documentation to clarify that for PRIMARY KEY the name is accepted but ignored. This should be also explained at CONSTRAINT page https://mariadb.com/kb/en/library/constraint/ where the syntax does not even mention index_name can be specified for PRIMARY KEY The server definitely should return warning so it is not documentation only problem.
          greenman Ian Gilfillan made changes -
          Field Original Value New Value
          Assignee Ian Gilfillan [ greenman ]
          elenst Elena Stepanova made changes -
          Status Open [ 1 ] Confirmed [ 10101 ]

          Assigning to serg for re-distribution.

          elenst Elena Stepanova added a comment - Assigning to serg for re-distribution.
          elenst Elena Stepanova made changes -
          Fix Version/s 10.3 [ 22126 ]
          Fix Version/s 10.4 [ 22408 ]
          Affects Version/s 5.5 [ 15800 ]
          Affects Version/s 10.0 [ 16000 ]
          Affects Version/s 10.1 [ 16100 ]
          Affects Version/s 10.2 [ 14601 ]
          Affects Version/s 10.3 [ 22126 ]
          Affects Version/s 10.4 [ 22408 ]
          Assignee Sergei Golubchik [ serg ]
          Labels upstream
          serg Sergei Golubchik made changes -
          Priority Major [ 3 ] Minor [ 4 ]
          serg Sergei Golubchik made changes -
          Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
          julien.fritsch Julien Fritsch made changes -
          Priority Minor [ 4 ] Major [ 3 ]
          julien.fritsch Julien Fritsch made changes -
          Comment [ customer issues needs this to be fixed since 4 months, hence moving the priority to critical to ensure we fix it sooner now. ]
          julien.fritsch Julien Fritsch made changes -
          Priority Major [ 3 ] Critical [ 2 ]
          holyfoot Alexey Botchkov made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]
          holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2019-July/013889.html
          holyfoot Alexey Botchkov made changes -
          Assignee Alexey Botchkov [ holyfoot ] Sergei Golubchik [ serg ]
          Status In Progress [ 3 ] In Review [ 10002 ]
          serg Sergei Golubchik made changes -
          Priority Critical [ 2 ] Major [ 3 ]
          serg Sergei Golubchik made changes -
          Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
          Status In Review [ 10002 ] Stalled [ 10000 ]

          This is good, just one detail — you cannot add new errors or warnings to 10.3, because 10.4 is already GA, and adding new warnings to 10.3 would cause 10.4 error numbers to change.

          So, just use, say,

                push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
                                    ER_WRONG_NAME_FOR_INDEX,
                                    "Name '%-.100s' ignored for PRIMARY key.",
                                    key->name.str);
          

          serg Sergei Golubchik added a comment - This is good, just one detail — you cannot add new errors or warnings to 10.3, because 10.4 is already GA, and adding new warnings to 10.3 would cause 10.4 error numbers to change. So, just use, say, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_WRONG_NAME_FOR_INDEX, "Name '%-.100s' ignored for PRIMARY key." , key->name.str);
          julien.fritsch Julien Fritsch made changes -
          Comment [ A comment with security level 'Developers' was removed. ]
          julien.fritsch Julien Fritsch made changes -
          Priority Major [ 3 ] Critical [ 2 ]
          holyfoot Alexey Botchkov made changes -
          Status Stalled [ 10000 ] In Progress [ 3 ]
          holyfoot Alexey Botchkov added a comment - https://github.com/MariaDB/server/commit/c6efbc543d6fb3004f320ef9d02542a4692ca88a
          holyfoot Alexey Botchkov made changes -
          issue.field.resolutiondate 2019-07-31 12:56:21.0 2019-07-31 12:56:21.942
          holyfoot Alexey Botchkov made changes -
          Fix Version/s 10.3.17 [ 23411 ]
          Fix Version/s 10.4.7 [ 23720 ]
          Fix Version/s 10.3 [ 22126 ]
          Fix Version/s 10.4 [ 22408 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]

          You forgot to update .result files for MyRocks tests. Now fixed.

          psergei Sergei Petrunia added a comment - You forgot to update .result files for MyRocks tests. Now fixed.
          greenman Ian Gilfillan made changes -
          Fix Version/s 10.4.8 [ 23721 ]
          Fix Version/s 10.3.18 [ 23719 ]
          Fix Version/s 10.3.17 [ 23411 ]
          Fix Version/s 10.4.7 [ 23720 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 90244 ] MariaDB v4 [ 155107 ]
          mariadb-jira-automation Jira Automation (IT) made changes -
          Zendesk Related Tickets 164209

          People

            holyfoot Alexey Botchkov
            hholzgra Hartmut Holzgraefe
            Votes:
            1 Vote for this issue
            Watchers:
            9 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.