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

AUTO_INCREMENT increased incorrectly when INSERT INTO... SELECT

    XMLWordPrintable

Details

    Description

      create schema if not exists DD; use DD;
      DROP TABLE IF EXISTS D1; DROP TABLE IF EXISTS D2;
      CREATE TABLE D1 (`ID` int(11) PRIMARY KEY AUTO_INCREMENT, 
        `INFO` longtext DEFAULT NULL) ENGINE=InnoDB;
      CREATE TABLE D2 (`ID` int(11) PRIMARY KEY AUTO_INCREMENT, 
        `SECTION` int(11) NOT NULL) ENGINE=InnoDB;
       
      insert into D1 (`INFO`) values ('x');
      insert into D1 (`INFO`) values ('x');
      insert into D2 (`SECTION`) values (1);
      insert into D2 (`SECTION`) select 2 as `SECTION` from D1;
      insert into D2 (`SECTION`) values (1);
      MariaDB [DD]> select * from D2;
      +----+---------+
      | ID | SECTION |
      +----+---------+
      |  1 |       1 |
      |  2 |       2 |
      |  3 |       2 |
      |  5 |       1 |
      +----+---------+
      4 rows in set (0.000 sec)
      

      Shouldn't the maximum ID value be 4?

      Attachments

        Activity

          People

            thiru Thirunarayanan Balathandayuthapani
            edward Edward Stoever
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.