Skip to content

Commit 34c0ef6

Browse files
authored
expression: fix wrong result for unsigned non-const int cmp const duration (#46620) (#46699)
close #45410
1 parent 9d4f30d commit 34c0ef6

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

executor/cte_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,6 @@ func TestCTEWithLimit(t *testing.T) {
357357
}
358358

359359
func TestCTEPanic(t *testing.T) {
360-
t.Parallel()
361-
362360
store, close := testkit.CreateMockStore(t)
363361
defer close()
364362
tk := testkit.NewTestKit(t, store)

expression/integration_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10610,3 +10610,16 @@ func (s *testIntegrationSuite) TestIfFunctionWithNull(c *C) {
1061010610
tk.MustQuery("select min(if(apply_to_now_days <= 30,loan,null)) as min, max(if(apply_to_now_days <= 720,loan,null)) as max from (select loan, datediff(from_unixtime(unix_timestamp('2023-05-18 18:43:43') + 18000), from_unixtime(apply_time/1000 + 18000)) as apply_to_now_days from orders) t1;").Sort().Check(
1061110611
testkit.Rows("20000 35100"))
1061210612
}
10613+
10614+
func (s *testIntegrationSuite) TestIssue45410(c *C) {
10615+
tk := testkit.NewTestKit(c, s.store)
10616+
// Issue 45410
10617+
tk.MustExec("create database testIssue45410")
10618+
defer tk.MustExec("drop database testIssue45410")
10619+
tk.MustExec("use testIssue45410")
10620+
10621+
tk.MustExec("DROP TABLE IF EXISTS t1;")
10622+
tk.MustExec("CREATE TABLE t1 (c1 TINYINT(1) UNSIGNED NOT NULL );")
10623+
tk.MustExec("INSERT INTO t1 VALUES (0);")
10624+
tk.MustQuery("SELECT c1>=CAST('-787360724' AS TIME) FROM t1;").Check(testkit.Rows("1"))
10625+
}

types/datum.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,9 +1089,10 @@ func (d *Datum) convertToUint(sc *stmtctx.StatementContext, target *FieldType) (
10891089
case KindMysqlDuration:
10901090
dec := d.GetMysqlDuration().ToNumber()
10911091
err = dec.Round(dec, 0, ModeHalfEven)
1092-
ival, err1 := dec.ToInt()
1093-
if err1 == nil {
1094-
val, err = ConvertIntToUint(sc, ival, upperBound, tp)
1092+
var err1 error
1093+
val, err1 = ConvertDecimalToUint(sc, dec, upperBound, tp)
1094+
if err == nil {
1095+
err = err1
10951096
}
10961097
case KindMysqlDecimal:
10971098
val, err = ConvertDecimalToUint(sc, d.GetMysqlDecimal(), upperBound, tp)

0 commit comments

Comments
 (0)