cardinality: remove the unnecessary limitation that the "exponential backoff" entry stats can't use iteself for estimation (#56850)

close pingcap/tidb#56915
This commit is contained in:
Zhou Kunqin
2024-10-29 02:47:31 +08:00
committed by GitHub
parent 484c1ae88e
commit cc370993fe
4 changed files with 20 additions and 6 deletions

View File

@ -476,9 +476,6 @@ func expBackoffEstimation(sctx planctx.PlanContext, idx *statistics.Index, coll
// `GetRowCountByIndexRanges()` when the input `indexRange` is a multi-column range. This
// check avoids infinite recursion.
for _, idxID := range idxIDs {
if idxID == idx.Histogram.ID {
continue
}
idxStats := coll.GetIdx(idxID)
if idxStats == nil || statistics.IndexStatsIsInvalid(sctx, idxStats, coll, idxID) {
continue

View File

@ -12,7 +12,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 27,
shard_count = 28,
deps = [
"//pkg/domain",
"//pkg/errno",

View File

@ -515,3 +515,22 @@ func TestIndexMergeJSONMemberOf2FlakyPart(t *testing.T) {
"└─TableRowIDScan_6(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[d:unInitialized]",
))
}
func TestIssue56915(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`drop table if exists t`)
tk.MustExec(`create table t(a int, b int, j json, index ia(a), index mvi( (cast(j as signed array)), a, b) );`)
tk.MustExec(`insert into t value(1,1,'[1,2,3,4,5]');`)
tk.MustExec(`insert into t value(1,1,'[1,2,3,4,5]');`)
tk.MustExec(`insert into t value(1,1,'[1,2,3,4,5]');`)
tk.MustExec(`insert into t value(1,1,'[1,2,3,4,5]');`)
tk.MustExec(`insert into t value(1,1,'[6]');`)
tk.MustExec(`analyze table t all columns;`)
tk.MustQuery("explain format = brief select * from t where a = 1 and 6 member of (j);").Check(testkit.Rows(
"IndexMerge 1.00 root type: union",
"├─IndexRangeScan(Build) 1.00 cop[tikv] table:t, index:mvi(cast(`j` as signed array), a, b) range:[6 1,6 1], keep order:false, stats:partial[j:unInitialized]",
"└─TableRowIDScan(Probe) 1.00 cop[tikv] table:t keep order:false, stats:partial[j:unInitialized]",
))
}

View File

@ -15,7 +15,6 @@ analyze table t index a;
analyze table t index a, idx, idx2;
--disable_warnings
# TestIndexMergeJSONMemberOf
drop table if exists t;
create table t(
@ -503,4 +502,3 @@ EXPLAIN format = brief SELECT /*+ use_index_merge(t1, mvi4) */ * from t1 where
c = 1 and
json_contains(j, '[4,5]') and
d not like '%test%';