matrixorigin / matrixone

Hyperconverged cloud-edge native database
https://docs.matrixorigin.cn/en
Apache License 2.0
1.77k stars 275 forks source link

[Bug]: not update last_insert_id when no need to generate auto increment value #19317

Open YANGGMM opened 5 hours ago

YANGGMM commented 5 hours ago

Is there an existing issue for the same bug?

Branch Name

main

Commit ID

newest

Other Environment Information

- Hardware parameters:
- OS type:
- Others:

Actual Behavior

mysql> Create table auto_increment02(col1 int auto_increment unique key)auto_increment = 10;
Query OK, 0 rows affected (0.12 sec)

mysql> Select * from auto_increment02;
Empty set (0.00 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)

mysql> Insert into auto_increment02 values();
Query OK, 1 row affected (0.01 sec)

mysql> Select * from auto_increment02;
+------+
| col1 |
+------+
|   10 |
+------+
1 row in set (0.00 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|               10 |
+------------------+
1 row in set (0.00 sec)

mysql> insert into auto_increment02 values(100);
Query OK, 1 row affected (0.01 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|               **11 |**
+------------------+
1 row in set (0.00 sec)

mysql> Select * from auto_increment02;
+------+
| col1 |
+------+
|   10 |
|  100 |
+------+
2 rows in set (0.00 sec)

mysql> Drop table auto_increment02;
Query OK, 0 rows affected (0.03 sec)

Expected Behavior

mysql> Create table auto_increment02(col1 int auto_increment unique key)auto_increment = 10;
Query OK, 0 rows affected (0.12 sec)

mysql> Select * from auto_increment02;
Empty set (0.00 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)

mysql> Insert into auto_increment02 values();
Query OK, 1 row affected (0.01 sec)

mysql> Select * from auto_increment02;
+------+
| col1 |
+------+
|   10 |
+------+
1 row in set (0.00 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|               10 |
+------------------+
1 row in set (0.00 sec)

mysql> insert into auto_increment02 values(100);
Query OK, 1 row affected (0.01 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|               **10|**
+------------------+
1 row in set (0.00 sec)

mysql> Select * from auto_increment02;
+------+
| col1 |
+------+
|   10 |
|  100 |
+------+
2 rows in set (0.00 sec)

mysql> Drop table auto_increment02;
Query OK, 0 rows affected (0.03 sec)

Steps to Reproduce

Drop table if exists auto_increment02;
Create table auto_increment02(col1 int auto_increment unique key)auto_increment = 10;
Select * from auto_increment02;
select last_insert_id();
Insert into auto_increment02 values();
Select * from auto_increment02;
select last_insert_id();
insert into auto_increment02 values(100);
select last_insert_id();
Select * from auto_increment02;
Drop table auto_increment02;

Additional information

No response

YANGGMM commented 5 hours ago

Drop table if exists auto_increment03; Create table auto_increment03(col1 int auto_increment unique key, col2 int auto_increment unique)auto_increment = 10; Select from auto_increment03; select last_insert_id(); Insert into auto_increment03 values(); Select from auto_increment03; select last_insert_id(); insert into auto_increment03 values(100,100); select last_insert_id(); insert into auto_increment03 (col1)values(1000); select last_insert_id(); Select * from auto_increment03; Drop table auto_increment03;