Skip to content

Commit

Permalink
executor: add config EnableCollectExecutionInfo (pingcap#15493)
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang authored Apr 13, 2020
1 parent 10907ce commit e90aac2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ type Config struct {
// EnableDynamicConfig enables the TiDB to fetch configs from PD and update itself during runtime.
// see https://github.com/pingcap/tidb/pull/13660 for more details.
EnableDynamicConfig bool `toml:"enable-dynamic-config" json:"enable-dynamic-config"`
// EnableCollectExecutionInfo enables the TiDB to collect execution info.
EnableCollectExecutionInfo bool `toml:"enable-collect-execution-info" json:"enable-collect-execution-info"`
}

// UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed
Expand Down Expand Up @@ -665,7 +667,8 @@ var defaultConf = Config{
AllowAutoRandom: false,
AllowsExpressionIndex: false,
},
EnableDynamicConfig: false,
EnableDynamicConfig: false,
EnableCollectExecutionInfo: false,
}

var (
Expand Down
16 changes: 11 additions & 5 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/distsql"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/executor/aggfuncs"
Expand Down Expand Up @@ -95,6 +96,9 @@ type MockPhysicalPlan interface {
}

func (b *executorBuilder) build(p plannercore.Plan) Executor {
if config.GetGlobalConfig().EnableCollectExecutionInfo && b.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl == nil {
b.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl = execdetails.NewRuntimeStatsColl()
}
switch v := p.(type) {
case nil:
return nil
Expand Down Expand Up @@ -879,7 +883,9 @@ func (b *executorBuilder) buildExplain(v *plannercore.Explain) Executor {
explain: v,
}
if v.Analyze {
b.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl = execdetails.NewRuntimeStatsColl()
if b.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl == nil {
b.ctx.GetSessionVars().StmtCtx.RuntimeStatsColl = execdetails.NewRuntimeStatsColl()
}
explainExec.analyzeExec = b.build(v.TargetPlan)
}
return explainExec
Expand Down Expand Up @@ -1986,6 +1992,10 @@ func (b *executorBuilder) constructDAGReq(plans []plannercore.PhysicalPlan) (dag
dagReq = &tipb.DAGRequest{}
dagReq.TimeZoneName, dagReq.TimeZoneOffset = timeutil.Zone(b.ctx.GetSessionVars().Location())
sc := b.ctx.GetSessionVars().StmtCtx
if sc.RuntimeStatsColl != nil {
collExec := true
dagReq.CollectExecutionSummaries = &collExec
}
dagReq.Flags = sc.PushDownFlags()
dagReq.Executors, streaming, err = constructDistExec(b.ctx, plans)

Expand Down Expand Up @@ -2656,10 +2666,6 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte
}

func (builder *dataReaderBuilder) buildTableReaderFromHandles(ctx context.Context, e *TableReaderExecutor, handles []int64) (Executor, error) {
if e.runtimeStats != nil && e.dagPB.CollectExecutionSummaries == nil {
colExec := true
e.dagPB.CollectExecutionSummaries = &colExec
}
startTS, err := builder.getSnapshotTS()
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion executor/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ func (e *HashJoinExec) Close() error {
if e.runtimeStats != nil {
concurrency := cap(e.joiners)
e.runtimeStats.SetConcurrencyInfo("Concurrency", concurrency)
e.runtimeStats.SetAdditionalInfo(e.rowContainer.stat.String())
if e.rowContainer != nil {
e.runtimeStats.SetAdditionalInfo(e.rowContainer.stat.String())
}
}
err := e.baseExecutor.Close()
return err
Expand Down
7 changes: 7 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,13 @@ func (s *SessionVars) SetSystemVar(name string, val string) error {
} else {
s.StmtCtx.AppendWarning(errors.Errorf("cannot update %s when enabling dynamic configs", TiDBCheckMb4ValueInUTF8))
}
case TiDBEnableCollectExecutionInfo:
conf := config.GetGlobalConfig()
if !conf.EnableDynamicConfig {
config.GetGlobalConfig().EnableCollectExecutionInfo = TiDBOptOn(val)
} else {
s.StmtCtx.AppendWarning(errors.Errorf("cannot update %s when enabling dynamic configs", TiDBEnableCollectExecutionInfo))
}
}
s.systems[name] = val
return nil
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ var defaultSysVars = []*SysVar{
{ScopeSession, TiDBEnableSlowLog, BoolToIntStr(logutil.DefaultTiDBEnableSlowLog)},
{ScopeSession, TiDBQueryLogMaxLen, strconv.Itoa(logutil.DefaultQueryLogMaxLen)},
{ScopeSession, TiDBCheckMb4ValueInUTF8, BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUTF8)},
{ScopeSession, TiDBEnableCollectExecutionInfo, BoolToIntStr(logutil.DefaultTiDBEnableSlowLog)},
}

// SynonymsSysVariables is synonyms of system variables.
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ const (

// TiDBMetricSchemaRangeDuration indicates the range duration when query metric schema.
TiDBMetricSchemaRangeDuration = "tidb_metric_query_range_duration"

// TiDBEnableCollectExecutionInfo indicates that whether execution info is collected.
TiDBEnableCollectExecutionInfo = "tidb_enable_collect_execution_info"
)

// Default TiDB system variable values.
Expand Down Expand Up @@ -481,6 +484,7 @@ const (
DefTiDBStoreLimit = 0
DefTiDBMetricSchemaStep = 60 // 60s
DefTiDBMetricSchemaRangeDuration = 60 // 60s
DefTidbEnableCollectExecutionInfo = false
)

// Process global variables.
Expand Down
5 changes: 4 additions & 1 deletion sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) {
return BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUTF8), true, nil
case TiDBCapturePlanBaseline:
return CapturePlanBaseline.GetVal(), true, nil
case TiDBEnableCollectExecutionInfo:
return BoolToIntStr(config.GetGlobalConfig().EnableCollectExecutionInfo), true, nil
}
sVal, ok := s.GetSystemVar(key)
if ok {
Expand Down Expand Up @@ -417,7 +419,8 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string,
TiDBBatchDelete, TiDBBatchCommit, TiDBEnableCascadesPlanner, TiDBEnableWindowFunction, TiDBPProfSQLCPU,
TiDBLowResolutionTSO, TiDBEnableIndexMerge, TiDBEnableNoopFuncs,
TiDBCheckMb4ValueInUTF8, TiDBEnableSlowLog, TiDBRecordPlanInSlowLog,
TiDBScatterRegion, TiDBGeneralLog, TiDBConstraintCheckInPlace, TiDBEnableVectorizedExpression:
TiDBScatterRegion, TiDBGeneralLog, TiDBConstraintCheckInPlace, TiDBEnableVectorizedExpression,
TiDBEnableCollectExecutionInfo:
fallthrough
case GeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, LogBin,
CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, PseudoSlaveMode, LowPriorityUpdates,
Expand Down

0 comments on commit e90aac2

Please sign in to comment.