Skip to content

Commit

Permalink
expression: do not adjust int when it is null and compared year (#22821
Browse files Browse the repository at this point in the history
…) (#22844)
  • Loading branch information
ti-srebot authored Mar 18, 2021
1 parent e889a5c commit f379151
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6454,6 +6454,15 @@ func (s *testSuite) TestIssue20305(c *C) {
tk.MustQuery("SELECT * FROM `t3` where y <= a").Check(testkit.Rows("2155 2156"))
}

func (s *testSuite) TestIssue22817(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t3")
tk.MustExec("create table t3 (a year)")
tk.MustExec("insert into t3 values (1991), (\"1992\"), (\"93\"), (94)")
tk.MustQuery("select * from t3 where a >= NULL").Check(testkit.Rows())
}

func (s *testSuite) TestIssue13953(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
4 changes: 2 additions & 2 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,15 +1373,15 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
}
}
// int constant [cmp] year type
if arg0IsCon && arg0IsInt && arg1Type.Tp == mysql.TypeYear {
if arg0IsCon && arg0IsInt && arg1Type.Tp == mysql.TypeYear && !arg0.Value.IsNull() {
adjusted, failed := types.AdjustYear(arg0.Value.GetInt64(), false)
if failed == nil {
arg0.Value.SetInt64(adjusted)
finalArg0 = arg0
}
}
// year type [cmp] int constant
if arg1IsCon && arg1IsInt && arg0Type.Tp == mysql.TypeYear {
if arg1IsCon && arg1IsInt && arg0Type.Tp == mysql.TypeYear && !arg1.Value.IsNull() {
adjusted, failed := types.AdjustYear(arg1.Value.GetInt64(), false)
if failed == nil {
arg1.Value.SetInt64(adjusted)
Expand Down

0 comments on commit f379151

Please sign in to comment.