Skip to content

Commit

Permalink
ranger: handle longlong overflow properly (#52365) (#53497)
Browse files Browse the repository at this point in the history
close #45783
  • Loading branch information
ti-chi-bot authored May 23, 2024
1 parent c9ed8f4 commit 45d1613
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 11 additions & 0 deletions pkg/planner/core/plan_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1397,3 +1397,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 pkg/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, newTp *types.FieldType)
// see issue #20101: overflow when converting integer to year
} else if newTp.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 newTp.GetType() == mysql.TypeNewDecimal && terror.ErrorEqual(err, types.ErrOverflow) {
// Ignore the types.ErrOverflow when we convert TypeNewDecimal values.
} else if (newTp.GetType() == mysql.TypeNewDecimal || newTp.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 && newTp.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
4 changes: 2 additions & 2 deletions tests/integrationtest/r/planner/core/partition_pruner.result
Original file line number Diff line number Diff line change
Expand Up @@ -3687,6 +3687,6 @@ id estRows task access object operator info
TableDual_7 0.00 root rows:0
desc select * from t where a in (-6895222, 3125507, 9223372036854775809);
id estRows task access object operator info
TableReader_9 8000.00 root data:Selection_8
└─Selection_8 8000.00 cop[tikv] in(planner__core__partition_pruner.t.a, -6895222, 3125507, 9223372036854775809)
TableReader_9 20.00 root data:Selection_8
└─Selection_8 20.00 cop[tikv] in(planner__core__partition_pruner.t.a, -6895222, 3125507, 9223372036854775809)
└─TableFullScan_7 10000.00 cop[tikv] table:t, partition:p0 keep order:false, stats:pseudo

0 comments on commit 45d1613

Please sign in to comment.