Skip to content

Commit

Permalink
statistics: fix a error check to prevent nil dereference (#27295) (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Sep 10, 2021
1 parent 540493b commit 50b4763
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion statistics/selectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ func getMaskAndRanges(ctx sessionctx.Context, exprs []expression.Expression, ran
}
var res *ranger.DetachRangeResult
res, err = ranger.DetachCondAndBuildRangeForIndex(ctx, exprs, cols, lengths)
ranges, accessConds, remainedConds, isDNF = res.Ranges, res.AccessConds, res.RemainedConds, res.IsDNFCond
if err != nil {
return 0, nil, false, err
}
ranges, accessConds, remainedConds, isDNF = res.Ranges, res.AccessConds, res.RemainedConds, res.IsDNFCond
default:
panic("should never be here")
}
Expand Down
10 changes: 10 additions & 0 deletions statistics/selectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,13 @@ func (s *testStatsSuite) TestCollationColumnEstimate(c *C) {
tk.MustQuery(input[i]).Check(testkit.Rows(output[i]...))
}
}

func (s *testStatsSuite) TestIssue27294(c *C) {
defer cleanEnv(c, s.store, s.do)
testKit := testkit.NewTestKit(c, s.store)

testKit.MustExec("use test")
testKit.MustExec("drop table if exists tt")
testKit.MustExec("create table tt (COL1 blob DEFAULT NULL,COL2 decimal(37,4) DEFAULT NULL,COL3 timestamp NULL DEFAULT NULL,COL4 int(11) DEFAULT NULL,UNIQUE KEY U_M_COL4(COL1(10),COL2), UNIQUE KEY U_M_COL5(COL3,COL2));")
testKit.MustExec("explain select * from tt where col1 is not null or col2 not between 454623814170074.2771 and -975540642273402.9269 and col3 not between '2039-1-19 10:14:57' and '2002-3-27 14:40:23';")
}

0 comments on commit 50b4763

Please sign in to comment.