Skip to content

Commit

Permalink
ranger: handle longlong overflow properly (pingcap#52365) (pingcap#53496
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 1, 2024
1 parent 447fc91 commit 417b8fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions planner/core/plan_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2541,3 +2541,14 @@ func BenchmarkNonPreparedPlanCacheDML(b *testing.B) {
tk.MustExec("delete from t where a = 2")
}
}

func TestIndexRange(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)

tk.MustExec(`CREATE TABLE posts (id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY)`)
tk.MustExec(`INSERT INTO posts (id) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);`)
tk.MustExec(`set tidb_enable_non_prepared_plan_cache=1;`)
tk.MustQuery(`SELECT posts.* FROM posts WHERE (id = 1 or id = 9223372036854775808);`).Check(testkit.Rows("1"))
}
5 changes: 3 additions & 2 deletions util/ranger/ranger.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ func convertPoint(sctx sessionctx.Context, point *point, tp *types.FieldType) (*
// see issue #20101: overflow when converting integer to year
} else if tp.GetType() == mysql.TypeBit && terror.ErrorEqual(err, types.ErrDataTooLong) {
// see issue #19067: we should ignore the types.ErrDataTooLong when we convert value to TypeBit value
} else if tp.GetType() == mysql.TypeNewDecimal && terror.ErrorEqual(err, types.ErrOverflow) {
// Ignore the types.ErrOverflow when we convert TypeNewDecimal values.
} else if (tp.GetType() == mysql.TypeNewDecimal || tp.GetType() == mysql.TypeLonglong) && terror.ErrorEqual(err, types.ErrOverflow) {
// Ignore the types.ErrOverflow when we convert TypeNewDecimal/TypeLonglong values.
// A trimmed valid boundary point value would be returned then. Accordingly, the `excl` of the point
// would be adjusted. Impossible ranges would be skipped by the `validInterval` call later.
// tests in TestIndexRange/TestIndexRangeForDecimal
} else if point.value.Kind() == types.KindMysqlTime && tp.GetType() == mysql.TypeTimestamp && terror.ErrorEqual(err, types.ErrWrongValue) {
// See issue #28424: query failed after add index
// 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
Expand Down

0 comments on commit 417b8fc

Please sign in to comment.