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 result for unsigned non-const int cmp const duration #46620

Merged
merged 3 commits into from
Sep 6, 2023
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
12 changes: 11 additions & 1 deletion expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7814,7 +7814,7 @@ func TestIfFunctionWithNull(t *testing.T) {
testkit.Rows("20000 35100"))
}

func TestIssue41733(t *testing.T) {
func TestIssue41733AndIssue45410(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create database testIssue41733")
Expand Down Expand Up @@ -7845,4 +7845,14 @@ func TestIssue41733(t *testing.T) {
tk.MustExec("INSERT IGNORE INTO t_big(c0) VALUES (1E20)")
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
tk.MustQuery("select * from t_big;").Check(testkit.Rows("18446744073709551615"))

// Issue 45410
tk.MustExec("create database testIssue45410")
defer tk.MustExec("drop database testIssue45410")
tk.MustExec("use testIssue45410")

tk.MustExec("DROP TABLE IF EXISTS t1;")
tk.MustExec("CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL );")
tk.MustExec("INSERT INTO t1 VALUES (0);")
tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1"))
}
7 changes: 4 additions & 3 deletions types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,10 @@
case KindMysqlDuration:
dec := d.GetMysqlDuration().ToNumber()
err = dec.Round(dec, 0, ModeHalfUp)
ival, err1 := dec.ToInt()
if err1 == nil {
val, err = ConvertIntToUint(sc, ival, upperBound, tp)
var err1 error
val, err1 = ConvertDecimalToUint(sc, dec, upperBound, tp)
if err == nil {
err = err1

Check warning on line 1220 in types/datum.go

View check run for this annotation

Codecov / codecov/patch

types/datum.go#L1217-L1220

Added lines #L1217 - L1220 were not covered by tests
}
case KindMysqlDecimal:
val, err = ConvertDecimalToUint(sc, d.GetMysqlDecimal(), upperBound, tp)
Expand Down