Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ranger: handle longlong overflow properly (#52365) #53498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1797,3 +1797,14 @@ partition by hash (a) partitions 3`)
require.False(t, tk.Session().GetSessionVars().FoundInPlanCache)
tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 1105 skip prepared plan-cache: query accesses partitioned tables is un-cacheable if tidb_partition_pruning_mode = 'static'"))
}

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 @@ -173,10 +173,11 @@ func convertPoint(sctx planctx.PlanContext, 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 @@ -3253,6 +3253,6 @@ TableReader_7 0.00 root partition:dual data:Selection_6
└─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
desc select * from t where a in (-6895222, 3125507, 9223372036854775809);
id estRows task access object operator info
TableReader_7 8000.00 root partition:p0 data:Selection_6
└─Selection_6 8000.00 cop[tikv] in(planner__core__partition_pruner.t.a, -6895222, 3125507, 9223372036854775809)
TableReader_7 20.00 root partition:p0 data:Selection_6
└─Selection_6 20.00 cop[tikv] in(planner__core__partition_pruner.t.a, -6895222, 3125507, 9223372036854775809)
└─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo