Skip to content

Commit

Permalink
expression: fix a bug in when comparing bit with string (#11660)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Aug 9, 2019
1 parent 24380b6 commit eb6f46a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit eb6f46a

Please sign in to comment.