Skip to content

Commit

Permalink
infoschema: fix select * from inspection_summary would return null. (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
reafans authored Apr 10, 2020
1 parent 1c73dec commit 8891c9d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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 @@ -952,6 +952,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

0 comments on commit 8891c9d

Please sign in to comment.