diff --git a/TOC.md b/TOC.md index 99ce71f28afec..60bd431a6cc68 100644 --- a/TOC.md +++ b/TOC.md @@ -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) @@ -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 diff --git a/dashboard/top-sql.md b/dashboard/top-sql.md new file mode 100644 index 0000000000000..a2530e78e1841 --- /dev/null +++ b/dashboard/top-sql.md @@ -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) \ No newline at end of file diff --git a/media/dashboard/top-sql-details.png b/media/dashboard/top-sql-details.png new file mode 100644 index 0000000000000..cf415cbbb4c96 Binary files /dev/null and b/media/dashboard/top-sql-details.png differ diff --git a/media/dashboard/top-sql-overview.png b/media/dashboard/top-sql-overview.png new file mode 100644 index 0000000000000..814cef8a1ccfd Binary files /dev/null and b/media/dashboard/top-sql-overview.png differ diff --git a/media/top-sql-details.png b/media/top-sql-details.png new file mode 100644 index 0000000000000..bb9d01cdf7a3b Binary files /dev/null and b/media/top-sql-details.png differ diff --git a/media/top-sql-overview.png b/media/top-sql-overview.png new file mode 100644 index 0000000000000..982d4c3cc43f0 Binary files /dev/null and b/media/top-sql-overview.png differ diff --git a/system-variables.md b/system-variables.md index fdc72605eafa9..b8f861e1b78f8 100644 --- a/system-variables.md +++ b/system-variables.md @@ -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` New in v5.4.0 + +- 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 New in v3.0.4 and v4.0 - Scope: GLOBAL