Skip to content

Commit

Permalink
*: support concurrently init stats (#52273)
Browse files Browse the repository at this point in the history
ref #52102
  • Loading branch information
hawkingrei authored Apr 1, 2024
1 parent 8aebc9b commit 9a55a11
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 34 deletions.
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ type Performance struct {
// If ForceInitStats is false, tidb can provide service before init stats is finished. Note that during the period
// of init stats the optimizer may make bad decisions due to pseudo stats.
ForceInitStats bool `toml:"force-init-stats" json:"force-init-stats"`

// ConcurrentlyInitStats indicates whether to use concurrency to init stats.
ConcurrentlyInitStats bool `toml:"concurrently-init-stats" json:"concurrently-init-stats"`
}

// PlanCache is the PlanCache section of the config.
Expand Down Expand Up @@ -1007,6 +1010,7 @@ var defaultConf = Config{
EnableLoadFMSketch: false,
LiteInitStats: true,
ForceInitStats: true,
ConcurrentlyInitStats: false,
},
ProxyProtocol: ProxyProtocol{
Networks: "",
Expand Down
2 changes: 1 addition & 1 deletion pkg/infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ func (b *Builder) applyCreateTable(m *meta.Meta, dbInfo *model.DBInfo, tableID i
if tblInfo == nil {
// When we apply an old schema diff, the table may has been dropped already, so we need to fall back to
// full load.
return nil, ErrTableNotExists.GenWithStackByArgs(
return nil, ErrTableNotExists.FastGenByArgs(
fmt.Sprintf("(Schema ID %d)", dbInfo.ID),
fmt.Sprintf("(Table ID %d)", tableID),
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (is *infoSchema) TableByName(schema, table model.CIStr) (t table.Table, err
return
}
}
return nil, ErrTableNotExists.GenWithStackByArgs(schema, table)
return nil, ErrTableNotExists.FastGenByArgs(schema, table)
}

func (is *infoSchema) TableIsView(schema, table model.CIStr) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6309,7 +6309,7 @@ func (b *PlanBuilder) buildUpdateLists(ctx context.Context, tableList []*ast.Tab
tableInfo := tn.TableInfo
tableVal, found := b.is.TableByID(tableInfo.ID)
if !found {
return nil, nil, false, infoschema.ErrTableNotExists.GenWithStackByArgs(tn.DBInfo.Name.O, tableInfo.Name.O)
return nil, nil, false, infoschema.ErrTableNotExists.FastGenByArgs(tn.DBInfo.Name.O, tableInfo.Name.O)
}
for i, colInfo := range tableVal.Cols() {
if !colInfo.IsGenerated() {
Expand Down
10 changes: 5 additions & 5 deletions pkg/planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ func (b *PlanBuilder) buildAdminCheckTable(ctx context.Context, as *ast.AdminStm
tableInfo := as.Tables[0].TableInfo
tbl, ok := b.is.TableByID(tableInfo.ID)
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O)
return nil, infoschema.ErrTableNotExists.FastGenByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O)
}
p := &CheckTable{
DBName: tblName.Schema.O,
Expand Down Expand Up @@ -3914,11 +3914,11 @@ func (b *PlanBuilder) resolveGeneratedColumns(ctx context.Context, columns []*ta
func (b *PlanBuilder) buildInsert(ctx context.Context, insert *ast.InsertStmt) (Plan, error) {
ts, ok := insert.Table.TableRefs.Left.(*ast.TableSource)
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs()
return nil, infoschema.ErrTableNotExists.FastGenByArgs()
}
tn, ok := ts.Source.(*ast.TableName)
if !ok {
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs()
return nil, infoschema.ErrTableNotExists.FastGenByArgs()
}
tableInfo := tn.TableInfo
if tableInfo.IsView() {
Expand Down Expand Up @@ -4426,7 +4426,7 @@ func (b *PlanBuilder) buildLoadData(ctx context.Context, ld *ast.LoadDataStmt) (
tableInPlan, ok := b.is.TableByID(tableInfo.ID)
if !ok {
db := b.ctx.GetSessionVars().CurrentDB
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(db, tableInfo.Name.O)
return nil, infoschema.ErrTableNotExists.FastGenByArgs(db, tableInfo.Name.O)
}
schema, names, err := expression.TableInfo2SchemaAndNames(b.ctx, model.NewCIStr(""), tableInfo)
if err != nil {
Expand Down Expand Up @@ -4510,7 +4510,7 @@ func (b *PlanBuilder) buildImportInto(ctx context.Context, ld *ast.ImportIntoStm
tableInPlan, ok := b.is.TableByID(tableInfo.ID)
if !ok {
db := b.ctx.GetSessionVars().CurrentDB
return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(db, tableInfo.Name.O)
return nil, infoschema.ErrTableNotExists.FastGenByArgs(db, tableInfo.Name.O)
}
schema, names, err := expression.TableInfo2SchemaAndNames(b.ctx, model.NewCIStr(""), tableInfo)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/statistics/handle/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
"//pkg/statistics/handle/cache",
"//pkg/statistics/handle/globalstats",
"//pkg/statistics/handle/history",
"//pkg/statistics/handle/initstats",
"//pkg/statistics/handle/lockstats",
"//pkg/statistics/handle/logutil",
"//pkg/statistics/handle/storage",
Expand Down
Loading

0 comments on commit 9a55a11

Please sign in to comment.