Skip to content

Commit

Permalink
planner: fix wrong range calculation for Nulleq function on Enum valu…
Browse files Browse the repository at this point in the history
…es (#32440) (#32496)

close #32428
  • Loading branch information
ti-srebot authored Apr 29, 2022
1 parent c679590 commit c0f22ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
22 changes: 22 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3378,6 +3378,28 @@ func (s *testIntegrationSuite) TestIssue26719(c *C) {
tk.MustExec(`rollback`)
}

func (s *testIntegrationSuite) TestIssue32428(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table `t1` (`a` enum('aa') DEFAULT NULL, KEY `k` (`a`))")
tk.MustExec("insert into t1 values('aa')")
tk.MustExec("insert into t1 values(null)")
tk.MustQuery("select a from t1 where a<=>'aa'").Check(testkit.Rows("aa"))
tk.MustQuery("select a from t1 where a<=>null").Check(testkit.Rows("<nil>"))

tk.MustExec(`CREATE TABLE IDT_MULTI15860STROBJSTROBJ (
COL1 enum('aa') DEFAULT NULL,
COL2 int(41) DEFAULT NULL,
COL3 year(4) DEFAULT NULL,
KEY U_M_COL4 (COL1,COL2),
KEY U_M_COL5 (COL3,COL2))`)
tk.MustExec(`insert into IDT_MULTI15860STROBJSTROBJ values("aa", 1013610488, 1982)`)
tk.MustQuery(`SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = "aa"`).Check(testkit.Rows()) // empty result
tk.MustExec(`prepare stmt from "SELECT * FROM IDT_MULTI15860STROBJSTROBJ t1 RIGHT JOIN IDT_MULTI15860STROBJSTROBJ t2 ON t1.col1 <=> t2.col1 where t1.col1 is null and t2.col1 = ?"`)
tk.MustExec(`set @a="aa"`)
tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows()) // empty result
}

func (s *testIntegrationSerialSuite) TestPushDownProjectionForTiFlash(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
3 changes: 1 addition & 2 deletions planner/core/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2390,8 +2390,7 @@ func (s *testPrepareSerialSuite) TestIssue30100(c *C) {
tk.MustExec("set @a=0;")
tk.MustQuery("execute stmt using @a").Check(testkit.Rows())
tk.MustQuery("execute stmt using @a").Check(testkit.Rows())
// If the plan contains the tableDual, it can not be cached.
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0"))
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1"))
}

func (s *testPlanSerialSuite) TestPartitionTable(c *C) {
Expand Down
6 changes: 5 additions & 1 deletion util/ranger/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ func handleEnumFromBinOp(sc *stmtctx.StatementContext, ft *types.FieldType, val
res = append(res, &point{value: d, excl: false, start: false})
}

if op == ast.NullEQ && val.IsNull() {
res = append(res, &point{start: true}, &point{}) // null point
}

tmpEnum := types.Enum{}
for i := 0; i <= len(ft.Elems); i++ {
if i == 0 {
Expand Down Expand Up @@ -486,7 +490,7 @@ func handleEnumFromBinOp(sc *stmtctx.StatementContext, ft *types.FieldType, val
if v >= 0 {
appendPointFunc(d)
}
case ast.EQ:
case ast.EQ, ast.NullEQ:
if v == 0 {
appendPointFunc(d)
}
Expand Down

0 comments on commit c0f22ee

Please sign in to comment.