Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: add plancodec id for all type TableScan/IndexScan. (#21935) #21964

Merged
merged 5 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,10 @@ func (s *testTableSuite) TestStmtSummaryTable(c *C) {
max_prewrite_regions, avg_affected_rows, query_sample_text, plan
from information_schema.statements_summary
where digest_text like 'select * from t%'`,
).Check(testkit.Rows("Select test test.t t:k 1 2 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10\troot \t100 \t\n" +
"\t├─IndexScan_8 \tcop[tikv]\t100 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableScan_9 \tcop[tikv]\t100 \ttable:t, keep order:false, stats:pseudo"))
).Check(testkit.Rows("Select test test.t t:k 1 2 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10 \troot \t100 \t\n" +
"\t├─IndexRangeScan_8\tcop[tikv]\t100 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableRowIDScan_9\tcop[tikv]\t100 \ttable:t, keep order:false, stats:pseudo"))

// select ... order by
tk.MustQuery(`select stmt_type, schema_name, table_names, index_names, exec_count, sum_cop_task_num, avg_total_keys,
Expand All @@ -1001,10 +1001,11 @@ func (s *testTableSuite) TestStmtSummaryTable(c *C) {
max_prewrite_regions, avg_affected_rows, query_sample_text, plan
from information_schema.statements_summary
where digest_text like 'select * from t%'`,
).Check(testkit.Rows("Select test test.t t:k 2 4 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10\troot \t100 \t\n" +
"\t├─IndexScan_8 \tcop[tikv]\t100 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableScan_9 \tcop[tikv]\t100 \ttable:t, keep order:false, stats:pseudo"))
).Check(testkit.Rows(
"Select test test.t t:k 2 4 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10 \troot \t100 \t\n" +
"\t├─IndexRangeScan_8\tcop[tikv]\t100 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableRowIDScan_9\tcop[tikv]\t100 \ttable:t, keep order:false, stats:pseudo"))

// Disable it again.
tk.MustExec("set global tidb_enable_stmt_summary = false")
Expand Down Expand Up @@ -1051,10 +1052,10 @@ func (s *testTableSuite) TestStmtSummaryTable(c *C) {
max_prewrite_regions, avg_affected_rows, query_sample_text, plan
from information_schema.statements_summary
where digest_text like 'select * from t%'`,
).Check(testkit.Rows("Select test test.t t:k 1 2 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10\troot \t1000 \t\n" +
"\t├─IndexScan_8 \tcop[tikv]\t1000 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableScan_9 \tcop[tikv]\t1000 \ttable:t, keep order:false, stats:pseudo"))
).Check(testkit.Rows("Select test test.t t:k 1 2 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10 \troot \t1000 \t\n" +
"\t├─IndexRangeScan_8\tcop[tikv]\t1000 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableRowIDScan_9\tcop[tikv]\t1000 \ttable:t, keep order:false, stats:pseudo"))

// Disable it in global scope.
tk.MustExec("set global tidb_enable_stmt_summary = false")
Expand All @@ -1070,10 +1071,10 @@ func (s *testTableSuite) TestStmtSummaryTable(c *C) {
max_prewrite_regions, avg_affected_rows, query_sample_text, plan
from information_schema.statements_summary
where digest_text like 'select * from t%'`,
).Check(testkit.Rows("Select test test.t t:k 2 4 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10\troot \t1000 \t\n" +
"\t├─IndexScan_8 \tcop[tikv]\t1000 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableScan_9 \tcop[tikv]\t1000 \ttable:t, keep order:false, stats:pseudo"))
).Check(testkit.Rows("Select test test.t t:k 2 4 0 0 0 0 0 0 0 0 0 select * from t where a=2 \tid \ttask \testRows\toperator info\n" +
"\tIndexLookUp_10 \troot \t1000 \t\n" +
"\t├─IndexRangeScan_8\tcop[tikv]\t1000 \ttable:t, index:k(a), range:[2,2], keep order:false, stats:pseudo\n" +
"\t└─TableRowIDScan_9\tcop[tikv]\t1000 \ttable:t, keep order:false, stats:pseudo"))

// Unset session variable.
tk.MustExec("set session tidb_enable_stmt_summary = ''")
Expand Down
31 changes: 21 additions & 10 deletions planner/core/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/planner/util"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/stringutil"
)

Expand All @@ -49,13 +50,18 @@ func (p *PhysicalLock) ExplainInfo() string {
// ExplainID overrides the ExplainID in order to match different range.
func (p *PhysicalIndexScan) ExplainID() fmt.Stringer {
return stringutil.MemoizeStr(func() string {
if p.isFullScan() {
return "IndexFullScan_" + strconv.Itoa(p.id)
}
return "IndexRangeScan_" + strconv.Itoa(p.id)
return p.TP() + "_" + strconv.Itoa(p.id)
})
}

// TP overrides the TP in order to match different range.
func (p *PhysicalIndexScan) TP() string {
if p.isFullScan() {
return plancodec.TypeIndexFullScan
}
return plancodec.TypeIndexRangeScan
}

// ExplainInfo implements Plan interface.
func (p *PhysicalIndexScan) ExplainInfo() string {
return p.AccessObject(false) + ", " + p.OperatorInfo(false)
Expand Down Expand Up @@ -157,15 +163,20 @@ func (p *PhysicalIndexScan) isFullScan() bool {
// ExplainID overrides the ExplainID in order to match different range.
func (p *PhysicalTableScan) ExplainID() fmt.Stringer {
return stringutil.MemoizeStr(func() string {
if p.isChildOfIndexLookUp {
return "TableRowIDScan_" + strconv.Itoa(p.id)
} else if p.isFullScan() {
return "TableFullScan_" + strconv.Itoa(p.id)
}
return "TableRangeScan_" + strconv.Itoa(p.id)
return p.TP() + "_" + strconv.Itoa(p.id)
})
}

// TP overrides the TP in order to match different range.
func (p *PhysicalTableScan) TP() string {
if p.isChildOfIndexLookUp {
return plancodec.TypeTableRowIDScan
} else if p.isFullScan() {
return plancodec.TypeTableFullScan
}
return plancodec.TypeTableRangeScan
}

// ExplainInfo implements Plan interface.
func (p *PhysicalTableScan) ExplainInfo() string {
return p.AccessObject(false) + ", " + p.OperatorInfo(false)
Expand Down
Loading