Skip to content

Commit

Permalink
Update docs around slow_query tables (pingcap#18895)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiancai authored Oct 24, 2024
1 parent 37fccb0 commit edb143b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
58 changes: 58 additions & 0 deletions information-schema/information-schema-slow-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,61 @@ DESC SELECT COUNT(*) FROM CLUSTER_SLOW_QUERY WHERE user = 'u1';
```sql
SELECT /*+ AGG_TO_COP() */ COUNT(*) FROM CLUSTER_SLOW_QUERY GROUP BY user;
```

## 查看执行信息

通过对 `SLOW_QUERY` 表执行 [`EXPLAIN ANALYZE`](/sql-statements/sql-statement-explain-analyze.md),你可以获取数据库如何检索慢查询信息的详情。然而,如果对 `CLUSTER_SLOW_QUERY` 表执行 `EXPLAIN ANALYZE`,将无法获取这些信息。

示例:

```sql
EXPLAIN ANALYZE SELECT * FROM INFORMATION_SCHEMA.SLOW_QUERY LIMIT 1\G
```

```
*************************** 1. row ***************************
id: Limit_7
estRows: 1.00
actRows: 1
task: root
access object:
execution info: time:3.46ms, loops:2, RU:0.000000
operator info: offset:0, count:1
memory: N/A
disk: N/A
*************************** 2. row ***************************
id: └─MemTableScan_10
estRows: 10000.00
actRows: 64
task: root
access object: table:SLOW_QUERY
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
operator info: only search in the current 'tidb-slow.log' file
memory: 1.26 MB
disk: N/A
2 rows in set (0.01 sec)
```

在输出中,查看 `execution info` 中的以下字段(为便于阅读,这些字段的格式已优化):

```
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
```

| 字段 | 描述 |
|---|---|
| `initialize` | 用于初始化的时间 |
| `read_file` | 用于读取慢日志文件的时间 |
| `parse_log.time` | 用于解析慢日志文件的时间 |
| `parse_log.concurrency` | 解析慢日志文件的并发度(由 [`tidb_distsql_scan_concurrency`](/system-variables.md#tidb_distsql_scan_concurrency) 控制) |
| `total_file` | 慢日志文件的总数 |
| `read_file` | 已读取的慢日志文件数 |
| `read_size` | 从日志文件中读取的字节数 |
1 change: 1 addition & 0 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,7 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1;
- 若表的分区较多可以适当调小该参数(取决于扫描数据量的大小以及扫描频率),避免 TiKV 内存溢出 (OOM)。
- 对于仅包含 `LIMIT` 子句的简单查询,如果 `LIMIT` 行数小于 100000,该查询的 scan 操作被下推到 TiKV 时,会将该变量的值视为 `1` 进行处理,以提升执行效率。
- 对于查询语句 `SELECT MAX/MIN(col) FROM ...`,如果 `col` 列有索引且该索引的顺序与 `MAX(col)``MIN(col)` 函数所需的顺序一致,TiDB 会将该查询改写为 `SELECT col FROM ... LIMIT 1` 进行处理,该变量的值也将视为 `1` 进行处理。例如,对于 `SELECT MIN(col) FROM ...`,如果 `col` 列有升序排列的索引,TiDB 通过将该查询改写为 `SELECT col FROM ... LIMIT 1`,可以直接读取该索引中第一条数据,从而快速得到 `MIN(col)` 值。
- 在对 [`SLOW_QUERY`](/information-schema/information-schema-slow-query.md) 表进行查询时,此变量可以控制解析慢日志文件的并发度。

### `tidb_dml_batch_size`

Expand Down

0 comments on commit edb143b

Please sign in to comment.