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

This commit is contained in:
Shenghui Wu
2019-08-07 16:42:10 +08:00
committed by pingcap-github-bot
parent 028f63cb4a
commit 8fac5e23ed
2 changed files with 19 additions and 0 deletions

View File

@ -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 {

View File

@ -4630,6 +4630,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) {