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

Merged
merged 2 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -921,7 +921,7 @@ func (b *builtinArithmeticPlusIntSig) plusUS(result *chunk.Column, lhi64s, rhi64
}
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) {
if result.IsNull(i) {
continue
}
Expand Down
6 changes: 6 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10260,3 +10260,9 @@ func (s *testIntegrationSuite) TestIssue27236(c *C) {
row = tk.MustQuery(`select extract(hour_second from c1) from t order by c1;`)
row.Check(testkit.Rows("-8385959", "7005959"))
}

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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the original test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean add this to test case ?

tidb> create table t1 (a bigint unsigned);
Query OK, 0 rows affected (0.01 sec)

tidb> insert into t1 values (0xfffffffffffffff0);
Query OK, 1 row affected (0.00 sec)

tidb> insert into t1 select a + 1 from t1;

I don’t think this is necessary. The test case I added can show that there was a bug before, and this bug has been fixed in this pr

}