Skip to content

Commit

Permalink
executor: do not log expensive query for system table. (pingcap#2601)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored and XuHuaiyu committed Feb 7, 2017
1 parent 16c1aae commit 2afa11f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion executor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"github.com/ngaut/log"
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/plan"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -180,6 +182,7 @@ type stmtAttributes struct {
hasRange bool
hasOrder bool
hasLimit bool
isSystemTable bool
}

func (pa *stmtAttributes) fromSelectStmt(stmt *ast.SelectStmt) {
Expand Down Expand Up @@ -222,6 +225,7 @@ func (pa *stmtAttributes) fromPlan(p plan.Plan) {
if len(x.AccessCondition) > 0 {
pa.hasRange = true
}
pa.setIsSystemTable(x.DBName)
case *plan.PhysicalIndexScan:
pa.hasIndexScan = true
if len(x.AccessCondition) > 0 {
Expand All @@ -230,6 +234,7 @@ func (pa *stmtAttributes) fromPlan(p plan.Plan) {
if x.DoubleRead {
pa.hasIndexDouble = true
}
pa.setIsSystemTable(x.DBName)
case *plan.PhysicalHashSemiJoin:
pa.hasJoin = true
}
Expand All @@ -239,6 +244,12 @@ func (pa *stmtAttributes) fromPlan(p plan.Plan) {
}
}

func (pa *stmtAttributes) setIsSystemTable(dbName model.CIStr) {
if dbName.L == mysql.SystemDB {
pa.isSystemTable = true
}
}

const (
attrSimple = "Simple"
attrFull = "Full"
Expand Down Expand Up @@ -290,7 +301,7 @@ func (pa *stmtAttributes) toLabel() string {
}

func (pa *stmtAttributes) logExpensiveStmt(sql string) {
if pa.hasRange || pa.hasLimit {
if pa.hasRange || pa.hasLimit || pa.isSystemTable {
return
}
if !pa.hasIndexScan && !pa.hasTableScan && !pa.hasIndexDouble {
Expand Down
2 changes: 1 addition & 1 deletion plan/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ func (b *planBuilder) buildDataSource(tn *ast.TableName) LogicalPlan {
tableInfo: tableInfo,
baseLogicalPlan: newBaseLogicalPlan(Tbl, b.allocator),
statisticTable: statisticTable,
DBName: &schemaName,
DBName: schemaName,
}
p.self = p
p.initIDAndContext(b.ctx)
Expand Down
2 changes: 1 addition & 1 deletion plan/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ type DataSource struct {
indexHints []*ast.IndexHint
tableInfo *model.TableInfo
Columns []*model.ColumnInfo
DBName *model.CIStr
DBName model.CIStr

TableAsName *model.CIStr

Expand Down
4 changes: 2 additions & 2 deletions plan/physical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ func (p *Analyze) prepareSimpleTableScan(cols []*model.ColumnInfo) *PhysicalTabl
Table: p.Table.TableInfo,
Columns: cols,
TableAsName: &p.Table.Name,
DBName: &p.Table.DBInfo.Name,
DBName: p.Table.DBInfo.Name,
physicalTableSource: physicalTableSource{client: p.ctx.GetClient()},
}
ts.tp = Tbl
Expand All @@ -1045,7 +1045,7 @@ func (p *Analyze) prepareSimpleIndexScan(idxOffset int, cols []*model.ColumnInfo
Columns: cols,
TableAsName: &p.Table.Name,
OutOfOrder: false,
DBName: &p.Table.DBInfo.Name,
DBName: p.Table.DBInfo.Name,
physicalTableSource: physicalTableSource{client: p.ctx.GetClient()},
DoubleRead: false,
}
Expand Down
6 changes: 3 additions & 3 deletions plan/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type PhysicalIndexScan struct {
Index *model.IndexInfo
Ranges []*IndexRange
Columns []*model.ColumnInfo
DBName *model.CIStr
DBName model.CIStr
Desc bool
OutOfOrder bool
// DoubleRead means if the index executor will read kv two times.
Expand All @@ -62,7 +62,7 @@ type PhysicalIndexScan struct {
type PhysicalMemTable struct {
basePlan

DBName *model.CIStr
DBName model.CIStr
Table *model.TableInfo
Columns []*model.ColumnInfo
Ranges []TableRange
Expand Down Expand Up @@ -329,7 +329,7 @@ type PhysicalTableScan struct {

Table *model.TableInfo
Columns []*model.ColumnInfo
DBName *model.CIStr
DBName model.CIStr
Desc bool
Ranges []TableRange
pkCol *expression.Column
Expand Down

0 comments on commit 2afa11f

Please sign in to comment.