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: do not adjust int when it is null and compared year (#22821) #22844

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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