Skip to content

Commit ca69622

Browse files
authored
expression: fix wrong result for unsigned non-const int cmp const duration (#46620)
close #45410
1 parent e8b590c commit ca69622

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

expression/integration_test/integration_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7824,7 +7824,7 @@ func TestIfFunctionWithNull(t *testing.T) {
78247824
testkit.Rows("20000 35100"))
78257825
}
78267826

7827-
func TestIssue41733(t *testing.T) {
7827+
func TestIssue41733AndIssue45410(t *testing.T) {
78287828
store := testkit.CreateMockStore(t)
78297829
tk := testkit.NewTestKit(t, store)
78307830
tk.MustExec("create database testIssue41733")
@@ -7855,4 +7855,14 @@ func TestIssue41733(t *testing.T) {
78557855
tk.MustExec("INSERT IGNORE INTO t_big(c0) VALUES (1E20)")
78567856
tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1264 Out of range value for column 'c0' at row 1"))
78577857
tk.MustQuery("select * from t_big;").Check(testkit.Rows("18446744073709551615"))
7858+
7859+
// Issue 45410
7860+
tk.MustExec("create database testIssue45410")
7861+
defer tk.MustExec("drop database testIssue45410")
7862+
tk.MustExec("use testIssue45410")
7863+
7864+
tk.MustExec("DROP TABLE IF EXISTS t1;")
7865+
tk.MustExec("CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL );")
7866+
tk.MustExec("INSERT INTO t1 VALUES (0);")
7867+
tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1"))
78587868
}

types/datum.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,9 +1216,10 @@ func (d *Datum) convertToUint(sc *stmtctx.StatementContext, target *FieldType) (
12161216
case KindMysqlDuration:
12171217
dec := d.GetMysqlDuration().ToNumber()
12181218
err = dec.Round(dec, 0, ModeHalfUp)
1219-
ival, err1 := dec.ToInt()
1220-
if err1 == nil {
1221-
val, err = ConvertIntToUint(sc, ival, upperBound, tp)
1219+
var err1 error
1220+
val, err1 = ConvertDecimalToUint(sc, dec, upperBound, tp)
1221+
if err == nil {
1222+
err = err1
12221223
}
12231224
case KindMysqlDecimal:
12241225
val, err = ConvertDecimalToUint(sc, d.GetMysqlDecimal(), upperBound, tp)

0 commit comments

Comments
 (0)