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

create table with serial primary key - differing result if pk declared separately

    XMLWordPrintable

Details

    Description

      create table products_spk (
        id serial primary key);
      

      Quite conveniently and as a major enhancement over MySQL produces no secondary index.

      | Table        | Create Table                                                        |
      | products_spk | CREATE TABLE `products_spk` (                                       |
      |              |   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,                 |
      |              |   PRIMARY KEY (`id`)                                                |
      |              | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci  |
      

      However if the PRIMARY KEY is declared separately we get a secondary duplicate index:

      create table products (
        id serial,
        primary key(id));
      

      | Table    | Create Table                                                        |
      | products | CREATE TABLE `products` (                                           |
      |          |   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,                 |
      |          |   PRIMARY KEY (`id`),                                               |
      |          |   UNIQUE KEY `id` (`id`)                                            |
      |          | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci  |
      

      As a desired result the second form will not create the secondary unique key index.

      (arose after boasting MariaDB advantage over MySQL and discovering this edgecase).

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              danblack Daniel Black
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.