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

statistics: fix async merge global stats use cmsketch twice (#59198) #59209

Open
wants to merge 3 commits into
base: release-8.5
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pkg/statistics/handle/globalstats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ go_test(
],
embed = [":globalstats"],
flaky = True,
shard_count = 26,
shard_count = 27,
deps = [
"//pkg/domain",
"//pkg/kv",
Expand Down
3 changes: 0 additions & 3 deletions pkg/statistics/handle/globalstats/global_stats_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ func (a *AsyncMergePartitionStats2GlobalStats) loadCMsketch(sctx sessionctx.Cont
if err != nil {
return err
}
a.cmsketch <- mergeItem[*statistics.CMSketch]{
cmsketch, i,
}
select {
case a.cmsketch <- mergeItem[*statistics.CMSketch]{
cmsketch, i,
Expand Down
20 changes: 20 additions & 0 deletions pkg/statistics/handle/globalstats/global_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,3 +975,23 @@ func TestGlobalStatsAndSQLBindingWithConcurrency(t *testing.T) {
tk.MustExec("set global tidb_merge_partition_stats_concurrency=2")
testGlobalStatsAndSQLBinding(tk)
}

func TestMergeGlobalStatsForCMSketch(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) partition by range (a) (
partition p0 values less than (10),
partition p1 values less than (20)
)`)
tk.MustExec("set @@tidb_analyze_version=1")
tk.MustExec("set @@tidb_partition_prune_mode='dynamic'")
tk.MustExec("insert into t values (1), (2), (3), (4), (5), (6), (6), (null), (11), (12), (13), (14), (15), (16), (17), (18), (19), (19)")
tk.MustExec("analyze table t")
tk.MustQuery("explain select * from t where a = 1").Check(
testkit.Rows("TableReader_7 1.00 root partition:p0 data:Selection_6",
"└─Selection_6 1.00 cop[tikv] eq(test.t.a, 1)",
" └─TableFullScan_5 18.00 cop[tikv] table:t keep order:false"))
}