Skip to content

Commit 885cc3e

Browse files
authored
Update docs around slow_query tables (#19160)
1 parent 74e6e55 commit 885cc3e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

information-schema/information-schema-slow-query.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,61 @@ Currently, because statistics of the system tables are not collected, sometimes
262262
```sql
263263
SELECT /*+ AGG_TO_COP() */ COUNT(*) FROM CLUSTER_SLOW_QUERY GROUP BY user;
264264
```
265+
266+
## View execution information
267+
268+
By running an [`EXPLAIN ANALYZE`](/sql-statements/sql-statement-explain-analyze.md) query on the `SLOW_QUERY` table, you can get detailed information about how the database fetches the slow query information. However, this information is **not** available when you run `EXPLAIN ANALYZE` on the `CLUSTER_SLOW_QUERY` table.
269+
270+
Example:
271+
272+
```sql
273+
EXPLAIN ANALYZE SELECT * FROM INFORMATION_SCHEMA.SLOW_QUERY LIMIT 1\G
274+
```
275+
276+
```
277+
*************************** 1. row ***************************
278+
id: Limit_7
279+
estRows: 1.00
280+
actRows: 1
281+
task: root
282+
access object:
283+
execution info: time:3.46ms, loops:2, RU:0.000000
284+
operator info: offset:0, count:1
285+
memory: N/A
286+
disk: N/A
287+
*************************** 2. row ***************************
288+
id: └─MemTableScan_10
289+
estRows: 10000.00
290+
actRows: 64
291+
task: root
292+
access object: table:SLOW_QUERY
293+
execution info: time:3.45ms, loops:1, initialize: 55.5µs, read_file: 1.21ms, parse_log: {time:4.11ms, concurrency:15}, total_file: 1, read_file: 1, read_size: 4.06 MB
294+
operator info: only search in the current 'tidb-slow.log' file
295+
memory: 1.26 MB
296+
disk: N/A
297+
2 rows in set (0.01 sec)
298+
```
299+
300+
In the output, check the following fields (formatted for readability) in the `execution info` section:
301+
302+
```
303+
initialize: 55.5µs,
304+
read_file: 1.21ms,
305+
parse_log: {
306+
time:4.11ms,
307+
concurrency:15
308+
},
309+
total_file: 1,
310+
read_file: 1,
311+
read_size: 4.06 MB
312+
```
313+
314+
| Field | Description |
315+
|---|---|
316+
| `initialize` | Time spent initializing |
317+
| `read_file` | Time spent reading the slow log file |
318+
| `parse_log.time` | Time spent parsing the slow log file |
319+
| `parse_log.concurrency` | Concurrency for parsing the slow log file (set by [`tidb_distsql_scan_concurrency`](/system-variables.md#tidb_distsql_scan_concurrency)) |
320+
| `total_file` | Total number of slow log files |
321+
| `read_file` | Number of slow log files that are read |
322+
| `read_size` | Bytes read from the log file |

system-variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1;
17871787
- If a table has a lot of partitions, you can reduce the variable value appropriately (determined by the size of the data to be scanned and the frequency of the scan) to avoid TiKV becoming out of memory (OOM).
17881788
- For a simple query with only a `LIMIT` clause, if the `LIMIT` value is less than 100000, the scan operation pushed down to TiKV treats the value of this variable as `1` to enhance execution efficiency.
17891789
- For the `SELECT MAX/MIN(col) FROM ...` query, if the `col` column has an index sorted in the same order required by the `MAX(col)` or `MIN(col)` function, TiDB will rewrite the query to `SELECT col FROM ... LIMIT 1` for processing, and the value of this variable will also be processed as `1`. For example, for `SELECT MIN(col) FROM ...`, if the `col` column has an ascending index, TiDB can quickly obtain the `MIN(col)` value by rewriting the query to `SELECT col FROM ... LIMIT 1` and directly reading the first row of the index.
1790+
- For queries on the [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md) table, this variable controls the concurrency for parsing the slow log file.
17901791

17911792
### tidb_dml_batch_size
17921793

0 commit comments

Comments
 (0)