Skip to content

Commit b75bdd1

Browse files
authored
stats: optimize build topn and histogram (#63285)
close #63286
1 parent 2a389c8 commit b75bdd1

File tree

9 files changed

+578
-165
lines changed

9 files changed

+578
-165
lines changed

pkg/planner/core/planbuilder.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,6 @@ func (b *PlanBuilder) buildDropBindPlan(v *ast.DropBindingStmt) (base.Plan, erro
792792
b.visitInfo = appendVisitInfo(b.visitInfo, mysql.SuperPriv, "", "", "", nil)
793793
return p, nil
794794
}
795-
796795
func (b *PlanBuilder) buildSetBindingStatusPlan(v *ast.SetBindingStmt) (base.Plan, error) {
797796
var p *SQLBindPlan
798797
if v.OriginNode != nil {
@@ -1299,7 +1298,7 @@ func getPossibleAccessPaths(ctx base.PlanContext, tableHints *hint.PlanHints, in
12991298

13001299
hasScanHint = true
13011300

1302-
// It is syntactically valid to omit index_list for USE INDEX, which means use no indexes.
1301+
// It is syntactically valid to omit index_list for USE INDEX, which means "use no indexes".
13031302
// Omitting index_list for FORCE INDEX or IGNORE INDEX is a syntax error.
13041303
// See https://dev.mysql.com/doc/refman/8.0/en/index-hints.html.
13051304
if !isolationReadEnginesHasTiKV && hint.IndexNames == nil {
@@ -1471,7 +1470,6 @@ func (b *PlanBuilder) buildPrepare(x *ast.PrepareStmt) base.Plan {
14711470
}
14721471
return p
14731472
}
1474-
14751473
func (b *PlanBuilder) buildAdmin(ctx context.Context, as *ast.AdminStmt) (base.Plan, error) {
14761474
var ret base.Plan
14771475
var err error
@@ -2253,7 +2251,6 @@ func (b *PlanBuilder) getFullAnalyzeColumnsInfo(
22532251

22542252
return nil, nil, nil
22552253
}
2256-
22572254
func (b *PlanBuilder) getColumnsBasedOnPredicateColumns(
22582255
tbl *resolve.TableNameW,
22592256
predicateCols, mustAnalyzedCols *calcOnceMap,
@@ -3041,8 +3038,8 @@ var analyzeOptionDefault = map[ast.AnalyzeOptionType]uint64{
30413038
// TopN reduced from 500 to 100 due to concerns over large number of TopN values collected for customers with many tables.
30423039
// 100 is more inline with other databases. 100-256 is also common for NumBuckets with other databases.
30433040
var analyzeOptionDefaultV2 = map[ast.AnalyzeOptionType]uint64{
3044-
ast.AnalyzeOptNumBuckets: 256,
3045-
ast.AnalyzeOptNumTopN: 100,
3041+
ast.AnalyzeOptNumBuckets: statistics.DefaultHistogramBuckets,
3042+
ast.AnalyzeOptNumTopN: statistics.DefaultTopNValue,
30463043
ast.AnalyzeOptCMSketchWidth: 2048,
30473044
ast.AnalyzeOptCMSketchDepth: 5,
30483045
ast.AnalyzeOptNumSamples: 0,
@@ -3818,7 +3815,6 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (base.
38183815
}
38193816
return p, nil
38203817
}
3821-
38223818
func collectVisitInfoFromRevokeStmt(ctx context.Context, sctx base.PlanContext, vi []visitInfo, stmt *ast.RevokeStmt) ([]visitInfo, error) {
38233819
// To use REVOKE, you must have the GRANT OPTION privilege,
38243820
// and you must have the privileges that you are granting.
@@ -5151,7 +5147,6 @@ func checkForUserVariables(in ast.Node) error {
51515147
}
51525148
return nil
51535149
}
5154-
51555150
func (b *PlanBuilder) buildDDL(ctx context.Context, node ast.DDLNode) (base.Plan, error) {
51565151
var authErr error
51575152
switch v := node.(type) {

pkg/statistics/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
"cmsketch.go",
1111
"cmsketch_util.go",
1212
"column.go",
13+
"constants.go",
1314
"debugtrace.go",
1415
"estimate.go",
1516
"fmsketch.go",
@@ -47,6 +48,7 @@ go_library(
4748
"//pkg/util/context",
4849
"//pkg/util/dbterror",
4950
"//pkg/util/fastrand",
51+
"//pkg/util/generic",
5052
"//pkg/util/hack",
5153
"//pkg/util/intest",
5254
"//pkg/util/logutil",
@@ -83,7 +85,7 @@ go_test(
8385
data = glob(["testdata/**"]),
8486
embed = [":statistics"],
8587
flaky = True,
86-
shard_count = 42,
88+
shard_count = 43,
8789
deps = [
8890
"//pkg/config",
8991
"//pkg/config/kerneltype",

0 commit comments

Comments
 (0)