Skip to content

Commit

Permalink
planner: fix incorrect TableDual plan built from nulleq (#24596)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylzd committed May 13, 2021
1 parent aa3e64d commit 1df03a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion util/ranger/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point {
if col.RetType.EvalType() == types.ETString && (value.Kind() == types.KindString || value.Kind() == types.KindBinaryLiteral) {
value.SetString(value.GetString(), col.RetType.Collate)
}
if col.GetType().Tp == mysql.TypeYear {
// If nulleq with null value, values.ToInt64 will return err
if col.GetType().Tp == mysql.TypeYear && !value.IsNull() {
// If the original value is adjusted, we need to change the condition.
// For example, col < 2156. Since the max year is 2155, 2156 is changed to 2155.
// col < 2155 is wrong. It should be col <= 2155.
Expand Down
3 changes: 2 additions & 1 deletion util/ranger/ranger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,12 +1504,13 @@ func (s *testRangerSuite) TestIndexRangeForYear(c *C) {
// test index range
testKit.MustExec("DROP TABLE IF EXISTS t")
testKit.MustExec("CREATE TABLE t (a year(4), key(a))")
testKit.MustExec("INSERT INTO t VALUES (1), (70), (99), (0), ('0')")
testKit.MustExec("INSERT INTO t VALUES (1), (70), (99), (0), ('0'), (NULL)")
testKit.MustQuery("SELECT * FROM t WHERE a < 15698").Check(testkit.Rows("0", "1970", "1999", "2000", "2001"))
testKit.MustQuery("SELECT * FROM t WHERE a <= 0").Check(testkit.Rows("0"))
testKit.MustQuery("SELECT * FROM t WHERE a <= 1").Check(testkit.Rows("0", "1970", "1999", "2000", "2001"))
testKit.MustQuery("SELECT * FROM t WHERE a < 2000").Check(testkit.Rows("0", "1970", "1999"))
testKit.MustQuery("SELECT * FROM t WHERE a > -1").Check(testkit.Rows("0", "1970", "1999", "2000", "2001"))
testKit.MustQuery("SELECT * FROM t WHERE a <=> NULL").Check(testkit.Rows("<nil>"))

tests := []struct {
indexPos int
Expand Down

0 comments on commit 1df03a6

Please sign in to comment.