Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: update slow query document #922

Merged
merged 4 commits into from
Oct 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions sql/slow-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,28 @@ sql:select count(c) from sbtest1 use index (k_1)
### 定位问题语句的方法

并不是所有 SLOW_QUERY 的语句都是有问题的。会造成集群整体压力增大的,是那些 process_time 很大的语句。wait_time 很大,但 process_time 很小的语句通常不是问题语句,是因为被问题语句阻塞,在执行队列等待造成的响应时间过长。

### `admin show slow` 命令

除了获取 TiDB 日志,还有一种定位慢查询的方式是通过 `admin show slow` SQL 命令:

```sql
admin show slow recent N
admin show slow top [internal | all] N
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For code blocks, we use 3 backticks both before and after the code block. To keep it consistent and easy to identify (for display improvement later), please update all code blocks in this PR. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

`recent N` 会显示最近的 N 条慢查询记录,例如:

```sql
admin show recent 10
```

`top N` 则显示最近一段时间(大约几天)内,最慢的查询记录。如果指定 `internal` 选项,则返回查询系统内部 SQL 的慢查询记录;如果指定 `all` 选项,返回系统内部和用户 SQL 汇总以后的慢查询记录;默认只返回用户 SQL 中的慢查询记录。

```sql
admin show top 3
admin show top internal 3
admin show top all 5
```

由于内存限制,保留的慢查询记录的条数是有限的。当命令查询的 `N` 大于记录条数时,返回的结果记录条数会小于 `N`。