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

infoschema: fix select * from inspection_summary would return null. (#16099) #17697

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion executor/inspection_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ type inspectSwapMemoryUsed struct{}

func (inspectSwapMemoryUsed) genSQL(timeRange plannercore.QueryTimeRange) string {
sql := fmt.Sprintf("select instance, max(value) as max_used from metrics_schema.node_memory_swap_used %s group by instance having max_used > 0", timeRange.Condition())
fmt.Println(sql)
return sql
}

Expand Down
4 changes: 3 additions & 1 deletion executor/inspection_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func (e *inspectionSummaryRetriever) retrieve(ctx context.Context, sctx sessionc
condition := e.timeRange.Condition()
var finalRows [][]types.Datum
for rule, tables := range inspectionSummaryRules {
if !rules.exist(rule) {
if len(rules.set) != 0 && !rules.set.Exist(rule) {
continue
}
for _, name := range tables {
Expand All @@ -435,6 +435,7 @@ func (e *inspectionSummaryRetriever) retrieve(ctx context.Context, sctx sessionc
continue
}
cols := def.Labels
comment := def.Comment
cond := condition
if def.Quantile > 0 {
cols = append(cols, "quantile")
Expand Down Expand Up @@ -493,6 +494,7 @@ func (e *inspectionSummaryRetriever) retrieve(ctx context.Context, sctx sessionc
row.GetFloat64(0), // avg
row.GetFloat64(1), // min
row.GetFloat64(2), // max
comment,
))
}
}
Expand Down
23 changes: 17 additions & 6 deletions executor/inspection_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,22 @@ func (s *inspectionSummarySuite) TestInspectionSummary(c *C) {
result := tk.ResultSetToResultWithCtx(ctx, rs[0], Commentf("execute inspect SQL failed"))
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(0), Commentf("unexpected warnings: %+v", tk.Se.GetSessionVars().StmtCtx.GetWarnings()))
result.Check(testkit.Rows(
"query-summary tikv-0 tidb_query_duration Select 0.99 0 0 0",
"query-summary tikv-1 tidb_query_duration Update 0.99 2 1 3",
"query-summary tikv-2 tidb_query_duration Delete 0.99 5 5 5",
"query-summary tidb-0 tidb_qps Query, Error <nil> 1 1 1",
"query-summary tidb-0 tidb_qps Query, OK <nil> 0 0 0",
"query-summary tidb-1 tidb_qps Quit, Error <nil> 7 5 9",
"query-summary tikv-0 tidb_query_duration Select 0.99 0 0 0 The quantile of TiDB query durations(second)",
"query-summary tikv-1 tidb_query_duration Update 0.99 2 1 3 The quantile of TiDB query durations(second)",
"query-summary tikv-2 tidb_query_duration Delete 0.99 5 5 5 The quantile of TiDB query durations(second)",
"query-summary tidb-0 tidb_qps Query, Error <nil> 1 1 1 TiDB query processing numbers per second",
"query-summary tidb-0 tidb_qps Query, OK <nil> 0 0 0 TiDB query processing numbers per second",
"query-summary tidb-1 tidb_qps Quit, Error <nil> 7 5 9 TiDB query processing numbers per second",
))

// Test for select * from information_schema.inspection_summary without specify rules.
rs, err = tk.Se.Execute(ctx, "select * from information_schema.inspection_summary where metrics_name = 'tidb_qps'")
c.Assert(err, IsNil)
result = tk.ResultSetToResultWithCtx(ctx, rs[0], Commentf("execute inspect SQL failed"))
c.Assert(tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(0), Commentf("unexpected warnings: %+v", tk.Se.GetSessionVars().StmtCtx.GetWarnings()))
result.Check(testkit.Rows(
"query-summary tidb-0 tidb_qps Query, Error <nil> 1 1 1 TiDB query processing numbers per second",
"query-summary tidb-0 tidb_qps Query, OK <nil> 0 0 0 TiDB query processing numbers per second",
"query-summary tidb-1 tidb_qps Quit, Error <nil> 7 5 9 TiDB query processing numbers per second",
))
}
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ var tableInspectionSummaryCols = []columnInfo{
{name: "AVG_VALUE", tp: mysql.TypeDouble, size: 22, decimal: 6},
{name: "MIN_VALUE", tp: mysql.TypeDouble, size: 22, decimal: 6},
{name: "MAX_VALUE", tp: mysql.TypeDouble, size: 22, decimal: 6},
{name: "COMMENT", tp: mysql.TypeVarchar, size: 256},
}

var tableInspectionRulesCols = []columnInfo{
Expand Down