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) #46700

Merged
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 executor/revoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (s *testSuite1) TestIssue41773(c *C) {
}

// Check https://github.com/pingcap/tidb/issues/41048
func (s *testSuite1) TestCaseInsensitiveSchemaNames(c *C) {
func (s *testSerialSuite2) TestCaseInsensitiveSchemaNames(c *C) {
defer collate.SetNewCollationEnabledForTest(false)
collate.SetNewCollationEnabledForTest(true)
tk := testkit.NewTestKit(c, s.store)
Expand Down
15 changes: 15 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7069,3 +7069,18 @@ func TestIfFunctionWithNull(t *testing.T) {
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(
testkit.Rows("20000 35100"))
}

func TestIssue45410(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
// 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 @@ -1160,9 +1160,10 @@ func (d *Datum) convertToUint(sc *stmtctx.StatementContext, target *FieldType) (
case KindMysqlDuration:
dec := d.GetMysqlDuration().ToNumber()
err = dec.Round(dec, 0, ModeHalfEven)
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
}
case KindMysqlDecimal:
val, err = ConvertDecimalToUint(sc, d.GetMysqlDecimal(), upperBound, tp)
Expand Down