Skip to content

Commit 3485857

Browse files
authored
ranger: handle float/integers overflow properly (#53501)
close #46538
1 parent c973157 commit 3485857

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pkg/planner/core/plan_cache_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,11 @@ func TestIndexRange(t *testing.T) {
18031803
tk := testkit.NewTestKit(t, store)
18041804
tk.MustExec(`use test`)
18051805

1806-
tk.MustExec(`CREATE TABLE posts (id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY)`)
1807-
tk.MustExec(`INSERT INTO posts (id) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);`)
1806+
tk.MustExec(`CREATE TABLE t0 (id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY)`)
1807+
tk.MustExec(`CREATE TABLE t1(c0 FLOAT ZEROFILL, PRIMARY KEY(c0));`)
1808+
tk.MustExec(`INSERT INTO t0 (id) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);`)
1809+
tk.MustExec("INSERT INTO t1(c0) VALUES (1);")
18081810
tk.MustExec(`set tidb_enable_non_prepared_plan_cache=1;`)
1809-
tk.MustQuery(`SELECT posts.* FROM posts WHERE (id = 1 or id = 9223372036854775808);`).Check(testkit.Rows("1"))
1811+
tk.MustQuery(`SELECT t0.* FROM t0 WHERE (id = 1 or id = 9223372036854775808);`).Check(testkit.Rows("1"))
1812+
tk.MustQuery("SELECT t1.c0 FROM t1 WHERE t1.c0!=BIN(-1);").Check(testkit.Rows("1"))
18101813
}

pkg/util/ranger/ranger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ func convertPoint(sctx *rangerctx.RangerContext, point *point, newTp *types.Fiel
172172
// see issue #20101: overflow when converting integer to year
173173
} else if newTp.GetType() == mysql.TypeBit && terror.ErrorEqual(err, types.ErrDataTooLong) {
174174
// see issue #19067: we should ignore the types.ErrDataTooLong when we convert value to TypeBit value
175-
} else if (newTp.GetType() == mysql.TypeNewDecimal || newTp.GetType() == mysql.TypeLonglong) && terror.ErrorEqual(err, types.ErrOverflow) {
176-
// Ignore the types.ErrOverflow when we convert TypeNewDecimal/TypeLonglong values.
175+
} else if (newTp.GetType() == mysql.TypeNewDecimal || mysql.IsIntegerType(newTp.GetType()) || newTp.GetType() == mysql.TypeFloat) && terror.ErrorEqual(err, types.ErrOverflow) {
176+
// Ignore the types.ErrOverflow when we convert TypeNewDecimal/TypeTiny/TypeShort/TypeInt24/TypeLong/TypeLonglong/TypeFloat values.
177177
// A trimmed valid boundary point value would be returned then. Accordingly, the `excl` of the point
178178
// would be adjusted. Impossible ranges would be skipped by the `validInterval` call later.
179179
// tests in TestIndexRange/TestIndexRangeForDecimal

0 commit comments

Comments
 (0)