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 0405ca6b3877d..2a45e28fe7ecf 100644 --- a/types/datum.go +++ b/types/datum.go @@ -1578,6 +1578,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) }