Skip to content

Commit

Permalink
cardinality: remove the unnecessary limitation that the "exponential …
Browse files Browse the repository at this point in the history
…backoff" entry stats can't use iteself for estimation (#56850)

close #56915
  • Loading branch information
time-and-fate authored Oct 28, 2024
1 parent 484c1ae commit cc37099
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 0 additions & 3 deletions pkg/planner/cardinality/row_count_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/casetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 27,
shard_count = 28,
deps = [
"//pkg/domain",
"//pkg/errno",
Expand Down
19 changes: 19 additions & 0 deletions pkg/planner/core/casetest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
))
}
2 changes: 0 additions & 2 deletions tests/integrationtest/t/planner/core/indexmerge_path.test
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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%';

0 comments on commit cc37099

Please sign in to comment.