Skip to content

Commit

Permalink
Add Top SQL doc pingcap#8123 (pingcap#7418)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiancai authored Jan 25, 2022
1 parent d96a3fb commit e442e70
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
- [Identify Slow Queries](/identify-slow-queries.md)
- [Analyze Slow Queries](/analyze-slow-queries.md)
- [SQL Diagnostics](/information-schema/information-schema-sql-diagnostics.md)
- [Identify Expensive Queries](/identify-expensive-queries.md)
- [Identify Expensive Queries Using Top SQL](/dashboard/top-sql.md)
- [Identify Expensive Queries Using Logs](/identify-expensive-queries.md)
- [Statement Summary Tables](/statement-summary-tables.md)
- [Troubleshoot Hotspot Issues](/troubleshoot-hot-spot-issues.md)
- [Troubleshoot Increased Read and Write Latency](/troubleshoot-cpu-issues.md)
Expand Down Expand Up @@ -619,6 +620,7 @@
- [Access](/dashboard/dashboard-access.md)
- [Overview Page](/dashboard/dashboard-overview.md)
- [Cluster Info Page](/dashboard/dashboard-cluster-info.md)
- [Top SQL](/dashboard/top-sql.md)
- [Key Visualizer Page](/dashboard/dashboard-key-visualizer.md)
- [Metrics Relation Graph](/dashboard/dashboard-metrics-relation.md)
- SQL Statements Analysis
Expand Down
43 changes: 43 additions & 0 deletions dashboard/top-sql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Top SQL
summary: This document describes how to use Top SQL to locate SQL queries that contribute to a high load.
---

# Top SQL

> **Warning:**
>
> Currently, Top SQL is an experimental feature. It is not recommended that you use it for production environments.
This document describes how to use Top SQL to locate SQL queries that contribute to a high load of a TiDB or TiKV node in a specified time range. For example, you can use Top SQL to locate an analytic query that consumes 99% of the load for a low-load database.

For a specified TiDB or TiKV node, Top SQL provides the following features:

* Show the top 5 types of SQL queries that contribute the most to the load in a specified time range.
* Show information such as CPU usage, requests per second, average latency, and query plan of a particular query, which can be used for potential performance optimization to improve your business.

## Enable Top SQL

The Top SQL feature is disabled by default. You can enable the feature for the entire cluster using either of the following methods:

- Method 1: Log in to TiDB Dashboard, click **Top SQL** in the left pane, click the gear button in the upper-right corner of the page, and then enable the Top SQL feature.
- Method 2: Set the value of the TiDB system variable [`tidb_enable_top_sql`](/system-variables.md#tidb_enable_top_sql-new-in-v540) to `ON`.

> **Note:**
>
> Enabling Top SQL has a slight impact on the performance of your cluster.
## Use Top SQL

Once Top SQL is enabled, you can log into TiDB Dashboard, and then click **Top SQL** in the left pane to use it.

![Top SQL](/media/dashboard/top-sql-overview.png)

Usage tips:

* You can select the target node and time range in the drop-down lists at the top of the page, or you can select the time range in the chart.
* If the data in the chart is out of date, you can click **Refresh**, or select auto-refresh and specify the auto-refresh interval in the **Refresh** drop-down list.
* The chart shows the top 5 types of queries that contribute the most to the load of the selected node in the selected time range.
* You can select a query type in the list to view the execution plan of that query type on this node and the execution details such as the Call/sec, Scan Rows/sec, Scan Indexes/sec, and Latency/call.

![Top SQL Details](/media/dashboard/top-sql-details.png)
Binary file added media/dashboard/top-sql-details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/dashboard/top-sql-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/top-sql-details.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/top-sql-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,16 @@ SET tidb_slow_log_threshold = 200;
- Unit: Seconds
- This variable is used to set the refresh time of [statement summary tables](/statement-summary-tables.md).
### `tidb_enable_top_sql` <span class="version-mark">New in v5.4.0</span>
- Scope: GLOBAL
- Default value: `OFF`
- This variable is used to control whether to enable the [Top SQL](/dashboard/top-sql.md) feature.
> **Warning:**
>
> Currently, Top SQL is an experimental feature. It is not recommended that you use it for production environments.
### tidb_store_limit <span class="version-mark">New in v3.0.4 and v4.0</span>
- Scope: GLOBAL
Expand Down

0 comments on commit e442e70

Please sign in to comment.