-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
affects-4.0This bug affects 4.0.x versions.This bug affects 4.0.x versions.affects-5.0This bug affects 5.0.x versions.This bug affects 5.0.x versions.affects-5.1This bug affects 5.1.x versions.This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.This bug affects 5.2.x versions.affects-5.3This bug affects 5.3.x versions.This bug affects 5.3.x versions.affects-5.4This bug affects the 5.4.x(LTS) versions.This bug affects the 5.4.x(LTS) versions.affects-6.0affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.2affects-6.3affects-6.4affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-6.6affects-7.0affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.2affects-7.3affects-7.4affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.affects-7.6affects-8.0affects-8.1This bug affects the 8.1.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.affects-8.2affects-8.3affects-8.4compatibility-mysql80This is a compatibility issue with MySQL 8.0(but NOT 5.7)This is a compatibility issue with MySQL 8.0(but NOT 5.7)severity/majorsig/sql-infraSIG: SQL InfraSIG: SQL Infratype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.
Description
1. Minimal reproduce step (Required)
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/go-sql-driver/mysql"
)
func executeSQL(db *sql.DB, sql string) sql.Result {
result, err := db.Exec(sql)
if err != nil {
log.Fatal("Error executing query:", err)
}
return result
}
func insertRow(db *sql.DB, a, b int) int {
insertQuery := "INSERT INTO tb (a, b) VALUES (?, ?) ON DUPLICATE KEY UPDATE b = VALUES(b)"
result, err := db.Exec(insertQuery, a, b)
if err != nil {
log.Fatal("Error executing insert query:", err)
}
// Get the last inserted ID
lastInsertId, err := result.LastInsertId()
if err != nil {
log.Fatalf("Error fetching LastInsertId: %v", err)
}
return int(lastInsertId)
}
func main() {
// Define the MySQL connection string
dsn := "root@tcp(127.0.0.1:4000)/test"
//dsn := "root@tcp(127.0.0.1:3306)/test"
// Open a connection to the database
db, err := sql.Open("mysql", dsn)
if err != nil {
log.Fatalf("Error opening database connection: %v", err)
}
defer db.Close()
// Test the connection
err = db.Ping()
if err != nil {
log.Fatalf("Error connecting to the database: %v", err)
}
_ = executeSQL(db, "drop table if exists tb")
_ = executeSQL(db, "create table tb(pk int primary key auto_increment, a int, b int, unique(a))")
lastInsertId := insertRow(db, 1, 1)
fmt.Printf("Last inserted ID: %d\n", lastInsertId)
lastInsertId = insertRow(db, 2, 2)
fmt.Printf("Last inserted ID: %d\n", lastInsertId)
lastInsertId = insertRow(db, 1, 2)
fmt.Printf("Last inserted ID: %d\n", lastInsertId)
}
// tiup playground v7.5.1:
// Last inserted ID: 1
// Last inserted ID: 2
// Last inserted ID: 0
// MySQL v8.0.23:
// Last inserted ID: 1
// Last inserted ID: 2
// Last inserted ID: 1
2. What did you expect to see? (Required)
The code should return same result from mysql and tidb
3. What did you see instead (Required)
// tiup playground v7.5.1:
// Last inserted ID: 1
// Last inserted ID: 2
// Last inserted ID: 0
// MySQL v8.0.23:
// Last inserted ID: 1
// Last inserted ID: 2
// Last inserted ID: 1
4. What is your TiDB version? (Required)
mysql> select @@version;
+--------------------+
| @@version |
+--------------------+
| 8.0.11-TiDB-v7.5.1 |
+--------------------+
1 row in set (0.01 sec)
Metadata
Metadata
Assignees
Labels
affects-4.0This bug affects 4.0.x versions.This bug affects 4.0.x versions.affects-5.0This bug affects 5.0.x versions.This bug affects 5.0.x versions.affects-5.1This bug affects 5.1.x versions.This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.This bug affects 5.2.x versions.affects-5.3This bug affects 5.3.x versions.This bug affects 5.3.x versions.affects-5.4This bug affects the 5.4.x(LTS) versions.This bug affects the 5.4.x(LTS) versions.affects-6.0affects-6.1This bug affects the 6.1.x(LTS) versions.This bug affects the 6.1.x(LTS) versions.affects-6.2affects-6.3affects-6.4affects-6.5This bug affects the 6.5.x(LTS) versions.This bug affects the 6.5.x(LTS) versions.affects-6.6affects-7.0affects-7.1This bug affects the 7.1.x(LTS) versions.This bug affects the 7.1.x(LTS) versions.affects-7.2affects-7.3affects-7.4affects-7.5This bug affects the 7.5.x(LTS) versions.This bug affects the 7.5.x(LTS) versions.affects-7.6affects-8.0affects-8.1This bug affects the 8.1.x(LTS) versions.This bug affects the 8.1.x(LTS) versions.affects-8.2affects-8.3affects-8.4compatibility-mysql80This is a compatibility issue with MySQL 8.0(but NOT 5.7)This is a compatibility issue with MySQL 8.0(but NOT 5.7)severity/majorsig/sql-infraSIG: SQL InfraSIG: SQL Infratype/bugThe issue is confirmed as a bug.The issue is confirmed as a bug.