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

last_insert_id() returns 0 when the value is explicitly added incompatible with MySQL 8.0 #42084

Open
yahonda opened this issue Mar 10, 2023 · 2 comments
Assignees
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) sig/sql-infra SIG: SQL Infra type/compatibility type/enhancement The issue or PR belongs to an enhancement.

Comments

@yahonda
Copy link
Member

yahonda commented Mar 10, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Startup tiup playground
$ tiup playground
  1. Connect to the TiDB
$ mysql --comments --host 127.0.0.1 --port 4000 -u root
  1. Execute these statements
use test;
CREATE TABLE `t` (
  `a` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`a`)
);
insert into t values(12);
select last_insert_id();

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

last_insert_id() should return 13 as MySQL 8.0.32 does.

mysql> CREATE TABLE `t` (
    ->   `a` int(11) NOT NULL AUTO_INCREMENT,
    ->   PRIMARY KEY (`a`)
    -> );
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> insert into t values(12);
Query OK, 1 row affected (0.00 sec)

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

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.32    |
+-----------+
1 row in set (0.00 sec)

mysql>

3. What did you see instead (Required)

last_insert_id() returns 0.

mysql> CREATE TABLE `t` (
    ->   `a` int(11) NOT NULL AUTO_INCREMENT,
    ->   PRIMARY KEY (`a`)
    -> );
Query OK, 0 rows affected (0.21 sec)

mysql>  insert into t values(12);
Query OK, 1 row affected (0.00 sec)

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

mysql>

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v6.6.0
Edition: Community
Git Commit Hash: f4ca0821fb96a2bdd37d2fb97eb26c07fc58d4e4
Git Branch: heads/refs/tags/v6.6.0
UTC Build Time: 2023-02-17 14:39:52
GoVersion: go1.19.5
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
1 row in set (0.00 sec)

mysql>
@yahonda yahonda added the type/bug The issue is confirmed as a bug. label Mar 10, 2023
@yahonda
Copy link
Member Author

yahonda commented Mar 10, 2023

Looks like this behavior changed between MySQL 5.7 and MySQL 8.0.
MySQL 5.7.41 behaves as same as TiDB 6.6.0.

mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 5.7.41    |
+-----------+
1 row in set (0.00 sec)

mysql> use test;
Database changed
mysql> CREATE TABLE `t` (
    ->   `a` int(11) NOT NULL AUTO_INCREMENT,
    ->   PRIMARY KEY (`a`)
    -> );
Query OK, 0 rows affected (0.02 sec)

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

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

mysql>

@yahonda
Copy link
Member Author

yahonda commented Mar 10, 2023

So far TiDB is "TiDB is highly compatible with the MySQL 5.7 protocol and the common features and syntax of MySQL 5.7" I think this is not a bug, rather than a feature request for MySQL 8.0 Compatibility

https://docs.pingcap.com/tidb/dev/mysql-compatibility

TiDB is highly compatible with the MySQL 5.7 protocol and the common features and syntax of MySQL 5.7

@yahonda yahonda mentioned this issue Mar 10, 2023
70 tasks
@yahonda yahonda changed the title last_insert_id() returns 0 when the value is explicitly added incompatible with MySQL last_insert_id() returns 0 when the value is explicitly added incompatible with MySQL 8.0 Mar 10, 2023
@SunRunAway SunRunAway added the compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) label Mar 10, 2023
@jebter jebter added the sig/sql-infra SIG: SQL Infra label Mar 10, 2023
@xhebox xhebox added type/enhancement The issue or PR belongs to an enhancement. and removed type/bug The issue is confirmed as a bug. labels Mar 10, 2023
@CbcWestwolf CbcWestwolf self-assigned this Mar 13, 2023
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) sig/sql-infra SIG: SQL Infra type/compatibility type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

5 participants