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

ADD PRIMARY KEY IF NOT EXISTS on composite key

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.0.31, 10.2.11, 10.0(EOL), 10.1(EOL), 10.2(EOL)
    • 10.0.36
    • None
    • Linux Mint

    Description

      I try to alter table to add a composite primary key with "if not exists clause" to a table. One of these column is already in a composite unique index with an other column.

      I get warning code 1061 "Multiple primary key defined".
      But without "IF NOT EXISTS", it works fine.

      This is my example :

      CREATE TABLE `HORIZON` (
      	`ID` BIGINT(20) NOT NULL,
      	`RANK` MEDIUMINT(4) NOT NULL,
      	`CHECK_POINT` BIGINT(20) NOT NULL,
      	UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`)
      ) COLLATE='utf8_general_ci' ENGINE=InnoDB ;
       
      ALTER TABLE `HORIZON` ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); /* warning code 1061 */
      ALTER TABLE `HORIZON` ADD PRIMARY KEY (`ID`, `CHECK_POINT`); /* works fine */
      

      Attachments

        Issue Links

          Activity

            antoine.lange Antoine Lange created issue -
            antoine.lange Antoine Lange made changes -
            Field Original Value New Value
            Priority Major [ 3 ] Minor [ 4 ]
            antoine.lange Antoine Lange made changes -
            Affects Version/s 10.2.11 [ 22634 ]
            antoine.lange Antoine Lange made changes -
            Summary ADD PRIMARY KEY IF NOT EXISTS on composite key with one ADD PRIMARY KEY IF NOT EXISTS on composite key
            antoine.lange Antoine Lange made changes -
            Description I try to alter table to add a composite primary key with "if not exists clause" to a table. One of these column is already in a composite unique index with an other column.

            I get warning code 1061 "Multiple primary key defined".
            But without "IF NOT EXISTS", it works fine.

            This is my example :
            {code:sql}
            CREATE TABLE `HORIZON` (
            `ID` BIGINT(20) NOT NULL,
            `RANK` MEDIUMINT(4) NOT NULL,
            `CHECK_POINT` BIGINT(20) NOT NULL,
            UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`)
            ) COLLATE='utf8_general_ci' ENGINE=InnoDB ;

            ALTER TABLE `HORIZON` ADD PRIMARY KEY (`ID`, `CHECK_POINT`); /* works fine */
            ALTER TABLE `HORIZON` ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); /* warning code 1061 */
            {code}
            I try to alter table to add a composite primary key with "if not exists clause" to a table. One of these column is already in a composite unique index with an other column.

            I get warning code 1061 "Multiple primary key defined".
            But without "IF NOT EXISTS", it works fine.

            This is my example :
            {code:sql}
            CREATE TABLE `HORIZON` (
            `ID` BIGINT(20) NOT NULL,
            `RANK` MEDIUMINT(4) NOT NULL,
            `CHECK_POINT` BIGINT(20) NOT NULL,
            UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`)
            ) COLLATE='utf8_general_ci' ENGINE=InnoDB ;

            ALTER TABLE `HORIZON` ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); /* warning code 1061 */
            ALTER TABLE `HORIZON` ADD PRIMARY KEY (`ID`, `CHECK_POINT`); /* works fine */
            {code}

            Thanks for the report and test case.

            It appears to be related to MDEV-8358, thus assigning to holyfoot.

            elenst Elena Stepanova added a comment - Thanks for the report and test case. It appears to be related to MDEV-8358 , thus assigning to holyfoot .
            elenst Elena Stepanova made changes -
            elenst Elena Stepanova made changes -
            Fix Version/s 10.0 [ 16000 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.2 [ 14601 ]
            Affects Version/s 10.0 [ 16000 ]
            Affects Version/s 10.1 [ 16100 ]
            Affects Version/s 10.2 [ 14601 ]
            Assignee Alexey Botchkov [ holyfoot ]
            elenst Elena Stepanova made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            serg Sergei Golubchik made changes -
            Priority Minor [ 4 ] Major [ 3 ]
            holyfoot Alexey Botchkov made changes -
            Status Confirmed [ 10101 ] In Progress [ 3 ]
            holyfoot Alexey Botchkov added a comment - fixing patch http://lists.askmonty.org/pipermail/commits/2018-June/012611.html
            holyfoot Alexey Botchkov made changes -
            Fix Version/s 10.0.36 [ 22916 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.0 [ 16000 ]
            Fix Version/s 10.1 [ 16100 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 84458 ] MariaDB v4 [ 153363 ]

            People

              holyfoot Alexey Botchkov
              antoine.lange Antoine Lange
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.