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

expression: fix a bug when comparing bit with string (#11654) #11660

Merged
merged 4 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,9 @@ func RefineComparedConstant(ctx sessionctx.Context, targetFieldType types.FieldT
}
sc := ctx.GetSessionVars().StmtCtx

if targetFieldType.Tp == mysql.TypeBit {
targetFieldType = *types.NewFieldType(mysql.TypeLonglong)
}
var intDatum types.Datum
intDatum, err = dt.ConvertTo(sc, &targetFieldType)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4507,6 +4507,22 @@ func (s *testIntegrationSuite) TestIssue10675(c *C) {
tk.MustQuery(`select * from t where a < 184467440737095516167.1;`).Check(
testkit.Rows("1"))
tk.MustQuery(`select * from t where a > 184467440737095516167.1;`).Check(testkit.Rows())

// issue 11647
tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(b bit(1));`)
tk.MustExec(`insert into t values(b'1');`)
tk.MustQuery(`select count(*) from t where b = 1;`).Check(testkit.Rows("1"))
tk.MustQuery(`select count(*) from t where b = '1';`).Check(testkit.Rows("1"))
tk.MustQuery(`select count(*) from t where b = b'1';`).Check(testkit.Rows("1"))

tk.MustExec(`drop table if exists t;`)
tk.MustExec(`create table t(b bit(63));`)
// Not 64, because the behavior of mysql is amazing. I have no idea to fix it.
tk.MustExec(`insert into t values(b'111111111111111111111111111111111111111111111111111111111111111');`)
tk.MustQuery(`select count(*) from t where b = 9223372036854775807;`).Check(testkit.Rows("1"))
tk.MustQuery(`select count(*) from t where b = '9223372036854775807';`).Check(testkit.Rows("1"))
tk.MustQuery(`select count(*) from t where b = b'111111111111111111111111111111111111111111111111111111111111111';`).Check(testkit.Rows("1"))
}

func (s *testIntegrationSuite) TestDatetimeMicrosecond(c *C) {
Expand Down