Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto increment increments by 2 while it should be increment by 1 #52214

Closed
dveeden opened this issue Mar 28, 2024 · 3 comments
Closed

Auto increment increments by 2 while it should be increment by 1 #52214

dveeden opened this issue Mar 28, 2024 · 3 comments
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/compatibility

Comments

@dveeden
Copy link
Contributor

dveeden commented Mar 28, 2024

Bug Report

1. Minimal reproduce step (Required)

CREATE TABLE t1(id SERIAL);
INSERT INTO t1() VALUES();
INSERT INTO t1() VALUES();
SELECT LAST_INSERT_ID();
TABLE t1;
INSERT INTO t1() VALUES(),(),();
SELECT LAST_INSERT_ID();
TABLE t1;
SHOW GLOBAL VARIABLES LIKE 'auto_increment%';

2. What did you expect to see? (Required)

MySQL 8.3.0

sql> CREATE TABLE t1(id SERIAL);
Query OK, 0 rows affected (0.0551 sec)

sql> INSERT INTO t1() VALUES();
Query OK, 1 row affected (0.0110 sec)

sql> INSERT INTO t1() VALUES();
Query OK, 1 row affected (0.0100 sec)

sql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
|                2 |
+------------------+
1 row in set (0.0003 sec)

sql> TABLE t1;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.0004 sec)

sql> INSERT INTO t1() VALUES(),(),();
Query OK, 3 rows affected (0.0096 sec)

Records: 3  Duplicates: 0  Warnings: 0

sql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
|                3 |
+------------------+
1 row in set (0.0004 sec)

sql> TABLE t1;
+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
+----+
5 rows in set (0.0004 sec)

sql> SHOW GLOBAL VARIABLES LIKE 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.0028 sec)

3. What did you see instead (Required)

TiDB

mysql> CREATE TABLE t1(id SERIAL);
Query OK, 0 rows affected (0.17 sec)

mysql> INSERT INTO t1() VALUES();
Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO t1() VALUES();
Query OK, 1 row affected (0.00 sec)

mysql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
|                3 |
+------------------+
1 row in set (0.00 sec)

mysql> TABLE t1;
+----+
| id |
+----+
|  1 |
|  3 |
+----+
2 rows in set (0.00 sec)

mysql> INSERT INTO t1() VALUES(),(),();
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
|                5 |
+------------------+
1 row in set (0.00 sec)

mysql> TABLE t1;
+----+
| id |
+----+
|  1 |
|  3 |
|  5 |
|  6 |
|  7 |
+----+
5 rows in set (0.00 sec)

mysql> SHOW GLOBAL VARIABLES LIKE 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

Tested with 7.5.1 and 8.0.0

@dveeden dveeden added type/bug The issue is confirmed as a bug. type/compatibility sig/sql-infra SIG: SQL Infra severity/moderate compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Mar 28, 2024
@dveeden
Copy link
Contributor Author

dveeden commented Mar 28, 2024

cc @mjonss

@bb7133
Copy link
Member

bb7133 commented Mar 29, 2024

Hi @dveeden , this is actually a known compatibility issue of TiDB, see #982 for more details.

We've tried to fix it(like #28448) but we're not confident enough for merging it(changing any existing behavior could be a problem for TiDB users). That's why it is only changed/fixed with AUTO_ID_CACHE=1(#39041).

@dveeden
Copy link
Contributor Author

dveeden commented Mar 29, 2024

Closing this as duplicate of #982

@dveeden dveeden closed this as not planned Won't fix, can't repro, duplicate, stale Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug. type/compatibility
Projects
None yet
Development

No branches or pull requests

2 participants