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 OverFlowErr when convert bit to int64 (#20266) #20312

Merged
merged 2 commits into from
Oct 14, 2020
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
9 changes: 9 additions & 0 deletions planner/core/expression_rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ func (s *testExpressionRewriterSuite) TestCompareSubquery(c *C) {
"<nil> 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) {
Expand Down
5 changes: 5 additions & 0 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down