From 0431dc932d876dc54e05415a7a02730346a31dfa Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Wed, 30 Sep 2020 13:00:09 +0800 Subject: [PATCH] cherry pick #20266 to release-4.0 Signed-off-by: ti-srebot --- planner/core/expression_rewriter_test.go | 9 +++++++++ types/datum.go | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/planner/core/expression_rewriter_test.go b/planner/core/expression_rewriter_test.go index 35e8776ce3825..a2253bf75d154 100644 --- a/planner/core/expression_rewriter_test.go +++ b/planner/core/expression_rewriter_test.go @@ -224,6 +224,15 @@ func (s *testExpressionRewriterSuite) TestCompareSubquery(c *C) { " 2", )) tk.MustQuery("select * from t t1 where b = all (select a from t t2)").Check(testkit.Rows()) + + // for issue 20059 + tk.MustExec("DROP TABLE IF EXISTS `t`") + tk.MustExec("CREATE TABLE `t` ( `a` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") + tk.MustExec("INSERT INTO `t` VALUES (1);") + tk.MustExec("DROP TABLE IF EXISTS `table_40_utf8_4`;") + tk.MustExec("CREATE TABLE `table_40_utf8_4` (`col_tinyint_key_unsigned` tinyint(4) DEFAULT NULL, `col_bit64_key_signed` bit(64) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;") + tk.MustExec("INSERT INTO `table_40_utf8_4` VALUES (31, -18);") + tk.MustQuery("select count(1) from table_40_utf8_4 where ( select count(1) from t where table_40_utf8_4.col_bit64_key_signed!=table_40_utf8_4.col_tinyint_key_unsigned)").Check(testkit.Rows("1")) } func (s *testExpressionRewriterSuite) TestCheckFullGroupBy(c *C) { diff --git a/types/datum.go b/types/datum.go index 4c1958a953b77..7cc5a2204a0e6 100644 --- a/types/datum.go +++ b/types/datum.go @@ -1570,6 +1570,11 @@ func (d *Datum) ToDecimal(sc *stmtctx.StatementContext) (*MyDecimal, error) { // ToInt64 converts to a int64. func (d *Datum) ToInt64(sc *stmtctx.StatementContext) (int64, error) { + switch d.Kind() { + case KindMysqlBit: + uintVal, err := d.GetBinaryLiteral().ToInt(sc) + return int64(uintVal), err + } return d.toSignedInteger(sc, mysql.TypeLonglong) }