Skip to content

Commit 1f6f6df

Browse files
authored
ranger: handle longlong overflow properly (#52365) (#53495)
close #45783
1 parent 042fa27 commit 1f6f6df

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

planner/core/plan_cache_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,13 @@ func TestIssue44830(t *testing.T) {
588588
tk.MustQuery(`execute st using @a, @a, @b, @b, @b, @b`).Sort().Check(testkit.Rows("1 1", "2 2"))
589589
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0")) // contain duplicated values in the in-list
590590
}
591+
592+
func TestIndexRange(t *testing.T) {
593+
store := testkit.CreateMockStore(t)
594+
tk := testkit.NewTestKit(t, store)
595+
tk.MustExec(`use test`)
596+
597+
tk.MustExec(`CREATE TABLE posts (id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY)`)
598+
tk.MustExec(`INSERT INTO posts (id) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);`)
599+
tk.MustQuery(`SELECT posts.* FROM posts WHERE (id = 1 or id = 9223372036854775808);`).Check(testkit.Rows("1"))
600+
}

util/ranger/ranger.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ func convertPoint(sctx sessionctx.Context, point *point, tp *types.FieldType) (*
169169
// see issue #20101: overflow when converting integer to year
170170
} else if tp.GetType() == mysql.TypeBit && terror.ErrorEqual(err, types.ErrDataTooLong) {
171171
// see issue #19067: we should ignore the types.ErrDataTooLong when we convert value to TypeBit value
172-
} else if tp.GetType() == mysql.TypeNewDecimal && terror.ErrorEqual(err, types.ErrOverflow) {
173-
// Ignore the types.ErrOverflow when we convert TypeNewDecimal values.
172+
} else if (tp.GetType() == mysql.TypeNewDecimal || tp.GetType() == mysql.TypeLonglong) && terror.ErrorEqual(err, types.ErrOverflow) {
173+
// Ignore the types.ErrOverflow when we convert TypeNewDecimal/TypeLonglong values.
174174
// A trimmed valid boundary point value would be returned then. Accordingly, the `excl` of the point
175175
// would be adjusted. Impossible ranges would be skipped by the `validInterval` call later.
176+
// tests in TestIndexRange/TestIndexRangeForDecimal
176177
} else if point.value.Kind() == types.KindMysqlTime && tp.GetType() == mysql.TypeTimestamp && terror.ErrorEqual(err, types.ErrWrongValue) {
177178
// See issue #28424: query failed after add index
178179
// Ignore conversion from Date[Time] to Timestamp since it must be either out of range or impossible date, which will not match a point select

0 commit comments

Comments
 (0)