From 55afb7ba8691dd03a65f148e653df536ffc47415 Mon Sep 17 00:00:00 2001
From: baurine <2008.hbl@gmail.com>
Date: Mon, 25 Sep 2023 14:48:16 +0800
Subject: [PATCH] feat(statements): show `plan_cache_hits` field
---
pkg/apiserver/statement/models.go | 2 ++
.../src/client/api/models/statement-model.ts | 6 ++++++
ui/packages/tidb-dashboard-client/swagger/spec.json | 3 +++
.../src/apps/Statement/pages/Detail/PlanDetailTabBasic.tsx | 4 ++++
.../src/apps/Statement/translations/en.yaml | 2 ++
.../src/apps/Statement/translations/zh.yaml | 2 ++
.../src/apps/Statement/utils/tableColumns.tsx | 1 +
ui/packages/tidb-dashboard-lib/src/client/models.ts | 6 ++++++
8 files changed, 26 insertions(+)
diff --git a/pkg/apiserver/statement/models.go b/pkg/apiserver/statement/models.go
index 262adb27a0..fcbba6df64 100644
--- a/pkg/apiserver/statement/models.go
+++ b/pkg/apiserver/statement/models.go
@@ -84,6 +84,8 @@ type Model struct {
AggBinaryPlan string `json:"binary_plan" agg:"ANY_VALUE(binary_plan)"`
AggPlanDigest string `json:"plan_digest" agg:"ANY_VALUE(plan_digest)"`
AggPlanHint *string `json:"plan_hint" agg:"ANY_VALUE(plan_hint)"`
+ AggPlanCacheHits int `json:"plan_cache_hits" agg:"SUM(plan_cache_hits)"`
+
// RocksDB
AggMaxRocksdbDeleteSkippedCount uint `json:"max_rocksdb_delete_skipped_count" agg:"MAX(max_rocksdb_delete_skipped_count)"`
AggAvgRocksdbDeleteSkippedCount uint `json:"avg_rocksdb_delete_skipped_count" agg:"CAST(SUM(exec_count * avg_rocksdb_delete_skipped_count) / SUM(exec_count) as SIGNED)"`
diff --git a/ui/packages/tidb-dashboard-client/src/client/api/models/statement-model.ts b/ui/packages/tidb-dashboard-client/src/client/api/models/statement-model.ts
index 9f97e37432..6a1047af8e 100644
--- a/ui/packages/tidb-dashboard-client/src/client/api/models/statement-model.ts
+++ b/ui/packages/tidb-dashboard-client/src/client/api/models/statement-model.ts
@@ -416,6 +416,12 @@ export interface StatementModel {
* @memberof StatementModel
*/
'plan'?: string;
+ /**
+ *
+ * @type {number}
+ * @memberof StatementModel
+ */
+ 'plan_cache_hits'?: number;
/**
*
* @type {boolean}
diff --git a/ui/packages/tidb-dashboard-client/swagger/spec.json b/ui/packages/tidb-dashboard-client/swagger/spec.json
index 9b8d95abbc..1ceea8bb6b 100644
--- a/ui/packages/tidb-dashboard-client/swagger/spec.json
+++ b/ui/packages/tidb-dashboard-client/swagger/spec.json
@@ -5440,6 +5440,9 @@
"description": "deprecated, replaced by BinaryPlanText",
"type": "string"
},
+ "plan_cache_hits": {
+ "type": "integer"
+ },
"plan_can_be_bound": {
"type": "boolean"
},
diff --git a/ui/packages/tidb-dashboard-lib/src/apps/Statement/pages/Detail/PlanDetailTabBasic.tsx b/ui/packages/tidb-dashboard-lib/src/apps/Statement/pages/Detail/PlanDetailTabBasic.tsx
index d7f87a89c1..8b990578d0 100644
--- a/ui/packages/tidb-dashboard-lib/src/apps/Statement/pages/Detail/PlanDetailTabBasic.tsx
+++ b/ui/packages/tidb-dashboard-lib/src/apps/Statement/pages/Detail/PlanDetailTabBasic.tsx
@@ -33,6 +33,10 @@ export const tabBasicItems = (data: StatementModel) => [
key: 'exec_count',
value:
},
+ {
+ key: 'plan_cache_hits',
+ value:
+ },
{
key: 'sum_latency',
value: getValueFormat('ns')(data.sum_latency || 0, 1)
diff --git a/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/en.yaml b/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/en.yaml
index 7a36d5336b..7996282ecb 100755
--- a/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/en.yaml
+++ b/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/en.yaml
@@ -104,6 +104,8 @@ statement:
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
+ plan_cache_hits: '# Plan Cache Hits'
+ plan_cache_hits_tooltip: Number of times the execution plan cache is hit
avg_latency: Mean Latency
avg_latency_tooltip: Execution time of single query
avg_mem: Mean Memory
diff --git a/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/zh.yaml b/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/zh.yaml
index 550cd4e05c..42de7bf47f 100755
--- a/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/zh.yaml
+++ b/ui/packages/tidb-dashboard-lib/src/apps/Statement/translations/zh.yaml
@@ -102,6 +102,8 @@ statement:
exec_count_tooltip: 该类 SQL 语句在时间段内被执行的总次数
plan_count: 计划数
plan_count_tooltip: 该类 SQL 语句在时间段内的不同执行计划数量
+ plan_cache_hits: 计划缓存命中次数
+ plan_cache_hits_tooltip: 该类 SQL 语句在时间段内的计划缓存命中次数
avg_latency: 平均耗时
avg_latency_tooltip: 单条 SQL 查询的执行时间
avg_mem: 平均内存
diff --git a/ui/packages/tidb-dashboard-lib/src/apps/Statement/utils/tableColumns.tsx b/ui/packages/tidb-dashboard-lib/src/apps/Statement/utils/tableColumns.tsx
index 8c4f6b23d7..141b5466f6 100644
--- a/ui/packages/tidb-dashboard-lib/src/apps/Statement/utils/tableColumns.tsx
+++ b/ui/packages/tidb-dashboard-lib/src/apps/Statement/utils/tableColumns.tsx
@@ -186,6 +186,7 @@ export function statementColumns(
maxWidth: 300,
columnActionsMode: ColumnActionsMode.clickable
}),
+ tcf.bar.single('plan_cache_hits', 'short', rows),
avgMaxColumn(tcf, 'avg_mem', 'bytes', rows),
avgMaxColumn(tcf, 'avg_disk', 'bytes', rows),
errorsWarningsColumn(tcf, rows),
diff --git a/ui/packages/tidb-dashboard-lib/src/client/models.ts b/ui/packages/tidb-dashboard-lib/src/client/models.ts
index a24848bc82..7fb1d8b21b 100644
--- a/ui/packages/tidb-dashboard-lib/src/client/models.ts
+++ b/ui/packages/tidb-dashboard-lib/src/client/models.ts
@@ -3168,6 +3168,12 @@ export interface StatementModel {
* @memberof StatementModel
*/
'plan'?: string;
+ /**
+ *
+ * @type {number}
+ * @memberof StatementModel
+ */
+ 'plan_cache_hits'?: number;
/**
*
* @type {boolean}