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 wrong way to check for overflow (#27122) #27418

Merged
merged 4 commits into from
Sep 16, 2021
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
2 changes: 1 addition & 1 deletion expression/builtin_arithmetic_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ func (b *builtinArithmeticPlusIntSig) plusUS(result *chunk.Column, lhi64s, rhi64
if rh < 0 && uint64(-rh) > uint64(lh) {
return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", b.args[0].String(), b.args[1].String()))
}
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(lh) {
if rh > 0 && uint64(lh) > math.MaxUint64-uint64(rh) {
return types.ErrOverflow.GenWithStackByArgs("BIGINT UNSIGNED", fmt.Sprintf("(%s + %s)", b.args[0].String(), b.args[1].String()))
}

Expand Down
6 changes: 6 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9804,6 +9804,12 @@ func (s *testIntegrationSuite2) TestIssue25526(c *C) {
rows.Check(testkit.Rows())
}

func (s *testIntegrationSuite) TestIssue26977(c *C) {
tk := testkit.NewTestKit(c, s.store)
result := tk.MustQuery("select a + 1 as f from (select cast(0xfffffffffffffff0 as unsigned) as a union select cast(1 as unsigned)) t having f != 2;")
result.Check(testkit.Rows("18446744073709551601"))
}

func (s *testIntegrationSuite) TestIssue27233(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
Expand Down