Skip to content

Commit

Permalink
statement: Display number of plans in the list (#746)
Browse files Browse the repository at this point in the history
Signed-off-by: Breezewish <me@breeswish.org>
(cherry picked from commit f190e8b)
  • Loading branch information
breezewish committed Sep 8, 2020
1 parent 8161cd8 commit e58edc9
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions pkg/apiserver/statement/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type TimeRange struct {
}

type Model struct {
AggPlanCount int `json:"plan_count" agg:"COUNT(DISTINCT plan_digest)"`
AggExecCount int `json:"exec_count" agg:"SUM(exec_count)"`
AggSumErrors int `json:"sum_errors" agg:"SUM(sum_errors)"`
AggSumWarnings int `json:"sum_warnings" agg:"SUM(sum_warnings)"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/apiserver/statement/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func QueryStatementsOverview(
schemas, stmtTypes []string,
text string) (result []Model, err error) {
fields := getAggrFields(
"plan_count",
"table_names",
"schema_name",
"digest",
Expand All @@ -158,7 +159,7 @@ func QueryStatementsOverview(
Select(strings.Join(fields, ", ")).
Table(statementsTable).
Where("summary_begin_time >= FROM_UNIXTIME(?) AND summary_end_time <= FROM_UNIXTIME(?)", beginTime, endTime).
Group("schema_name, digest, digest_text").
Group("schema_name, digest").
Order("agg_sum_latency DESC")

if len(schemas) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/apps/Statement/pages/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function DetailPage() {
</Descriptions.Item>
<Descriptions.Item
label={
<TextWithInfo.TransKey transKey="statement.pages.detail.desc.plan_count" />
<TextWithInfo.TransKey transKey="statement.fields.plan_count" />
}
>
{plans.length}
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/apps/Statement/pages/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defColumnKeys: IColumnKeys = {
sum_latency: true,
avg_latency: true,
exec_count: true,
avg_mem: true,
plan_count: true,
related_schemas: true,
}

Expand Down
5 changes: 3 additions & 2 deletions ui/lib/apps/Statement/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ statement:
title: Statement Information
desc:
time_range: Selected Time Range
plan_count: Execution Plans
plans:
note: There are multiple execution plans for this kind of SQL statement. You can choose to view one or multiple of them.
title:
Expand Down Expand Up @@ -65,8 +64,10 @@ statement:
digest_text_tooltip: Similar queries have same statement template even for different query parameters
sum_latency: Total Latency
sum_latency_tooltip: Total execution time for this kind of statement
exec_count: Execution Count
exec_count: '# Exec'
exec_count_tooltip: Total execution count for this kind of statement
plan_count: '# Plans'
plan_count_tooltip: Number of distinct execution plans of this statement in current time range
avg_latency: Mean Latency
avg_latency_tooltip: Execution time of single query
avg_mem: Mean Memory
Expand Down
3 changes: 2 additions & 1 deletion ui/lib/apps/Statement/translations/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ statement:
title: SQL 语句信息
desc:
time_range: 时间范围
plan_count: 执行计划数
plans:
note: 该 SQL 模板在选定的时间范围内有多个执行计划,您可以选择查看其中一个或多个执行计划。
title:
Expand Down Expand Up @@ -66,6 +65,8 @@ statement:
sum_latency_tooltip: 该类 SQL 语句在时间段内的累计执行时间
exec_count: 执行次数
exec_count_tooltip: 该类 SQL 语句在时间段内被执行的总次数
plan_count: 计划数
plan_count_tooltip: 该类 SQL 语句在时间段内的不同执行计划数量
avg_latency: 平均耗时
avg_latency_tooltip: 单条 SQL 查询的执行时间
avg_mem: 平均内存
Expand Down
14 changes: 14 additions & 0 deletions ui/lib/apps/Statement/utils/tableColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ function commonColumnName(fieldName: string): any {
return <TextWithInfo.TransKey transKey={`statement.fields.${fieldName}`} />
}

function planCountColumn(
_rows?: { plan_count?: number }[] // used for type check only
): IColumn {
return {
name: commonColumnName('plan_count'),
key: 'plan_count',
fieldName: 'plan_count',
minWidth: 100,
maxWidth: 300,
columnActionsMode: ColumnActionsMode.clickable,
}
}

function planDigestColumn(
_rows?: { plan_digest?: string }[] // used for type check only
): IColumn {
Expand Down Expand Up @@ -322,6 +335,7 @@ export function statementColumns(
sumLatencyColumn(rows),
avgMinMaxLatencyColumn(rows),
execCountColumn(rows),
planCountColumn(rows),
avgMaxMemColumn(rows),
errorsWarningsColumn(rows),
avgParseLatencyColumn(rows),
Expand Down

0 comments on commit e58edc9

Please sign in to comment.