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

point get -1 on bigint unsigned primary key gets max.uInt64 value #10056

Closed
darren opened this issue Apr 4, 2019 · 1 comment · Fixed by #10113
Closed

point get -1 on bigint unsigned primary key gets max.uInt64 value #10056

darren opened this issue Apr 4, 2019 · 1 comment · Fixed by #10113
Assignees
Labels
type/bug This issue is a bug.

Comments

@darren
Copy link
Contributor

darren commented Apr 4, 2019

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "root@tcp(127.0.0.1:4000)/test")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	db.Exec("CREATE TABLE IF NOT Exists `t1` (`id` bigint(20) UNSIGNED NOT NULL, PRIMARY KEY (`id`) )")
	db.Exec("insert into t1 values (18446744073709551615)")

	var i = ^uint64(0)

	rows, err := db.Query("select id from t1 where id=?", i)
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	var r uint64
	for rows.Next() {
		rows.Scan(&r)
		fmt.Printf("GOT: %d \n", r)
	}

	rows, err = db.Query("select id from t1 where id=?", -1)
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	for rows.Next() {
		rows.Scan(&r)
		fmt.Printf("GOT: %d \n", r)
	}
}
  1. What did you expect to see?

run against MySQL it returns

GOT: 18446744073709551615
  1. What did you see instead?

run against TiDB it returns:

GOT: 18446744073709551615
GOT: 18446744073709551615
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
Release Version: v3.0.0-beta.1-68-ge48b258f9
Git Commit Hash: e48b258f9226ed8d4e6147154afb26ab7d8c59b2
Git Branch: master
UTC Build Time: 2019-04-04 05:05:01
GoVersion: go version go1.12.1 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false

related issue: go-sql-driver/mysql#838

@lysu lysu added the type/bug This issue is a bug. label Apr 8, 2019
@lysu
Copy link
Collaborator

lysu commented Apr 8, 2019

Thanks for your feedback! @darren
It's a bug, we will take a look, and also welcome to issue PR if you interesting this :D

@lysu lysu self-assigned this Apr 10, 2019
@zz-jason zz-jason changed the title bigint unsigned select problem point get -1 on bigint unsigned primary key gets max.uInt64 value Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants