Skip to content

Commit

Permalink
expression: fix unexpected constant fold when year compare string (pi…
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored Mar 16, 2021
1 parent 23227ea commit 7a9b07e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 1 addition & 4 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,7 @@ func RefineComparedConstant(ctx sessionctx.Context, targetFieldType types.FieldT
if err != nil {
return con, false
}
if c, err = doubleDatum.CompareDatum(sc, &intDatum); err != nil {
return con, false
}
if c != 0 {
if doubleDatum.GetFloat64() > math.Trunc(doubleDatum.GetFloat64()) {
return con, true
}
return &Constant{
Expand Down
10 changes: 10 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8879,6 +8879,16 @@ func (s *testIntegrationSuite) Test22717(c *C) {
tk.MustQuery("select d from t where d").Check(testkit.Rows("0", "1", "0,1"))
}

func (s *testIntegrationSuite) Test23262(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a year)")
tk.MustExec("insert into t values(2002)")
tk.MustQuery("select * from t where a=2").Check(testkit.Rows("2002"))
tk.MustQuery("select * from t where a='2'").Check(testkit.Rows("2002"))
}

func (s *testIntegrationSerialSuite) TestPartitionPruningRelaxOP(c *C) {
// Discovered while looking at issue 19941 (not completely related)
// relaxOP relax the op > to >= and < to <=
Expand Down

0 comments on commit 7a9b07e

Please sign in to comment.