Skip to content

Commit

Permalink
statistics: fix async merge global stats use cmsketch twice (#59198)
Browse files Browse the repository at this point in the history
close #59194
  • Loading branch information
L-maple authored Jan 25, 2025
1 parent 4b98d4e commit 2412351
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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"))
}

0 comments on commit 2412351

Please sign in to comment.