diff --git a/pkg/planner/core/plan_cache_test.go b/pkg/planner/core/plan_cache_test.go index 6d7c150c5e406..76282a6fb3da8 100644 --- a/pkg/planner/core/plan_cache_test.go +++ b/pkg/planner/core/plan_cache_test.go @@ -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")) +} diff --git a/pkg/util/ranger/ranger.go b/pkg/util/ranger/ranger.go index 2baf7bef0628a..2770a656b2d21 100644 --- a/pkg/util/ranger/ranger.go +++ b/pkg/util/ranger/ranger.go @@ -172,10 +172,11 @@ func convertPoint(sctx *rangerctx.RangerContext, point *point, newTp *types.Fiel // 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 diff --git a/tests/integrationtest/r/planner/core/partition_pruner.result b/tests/integrationtest/r/planner/core/partition_pruner.result index 49abcbf99dd2a..b7048e6e2b11c 100644 --- a/tests/integrationtest/r/planner/core/partition_pruner.result +++ b/tests/integrationtest/r/planner/core/partition_pruner.result @@ -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