Skip to content

Commit

Permalink
sql: update statement summary doc (#14738)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 committed Aug 18, 2023
1 parent 6e5112a commit bc1b4ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions statement-summary-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,18 @@ select * from employee where id in (...) and salary between ? and ?;
statement summary 配置示例如下:

```sql
set global tidb_stmt_summary_max_stmt_count = 3000;
set global tidb_enable_stmt_summary = true;
set global tidb_stmt_summary_refresh_interval = 1800;
set global tidb_stmt_summary_history_size = 24;
```

以上配置生效后,`statements_summary` 每 30 分钟清空一次,所以 `statements_summary_history` 保存最近 12 小时的历史数`statements_summary_evicted` 保存最近 24 个发生了 evict 的时间段记录;`statements_summary_evicted` 则以 30 分钟为一个记录周期,表容量为 24 个时间段。
以上配置生效后,`statements_summary` 每 30 分钟清空一次,`statements_summary_history` 最多保存 3000 种 SQL 种类的数据,每种类型的 SQL 保存最近出现过的 24 个时间段的数据`statements_summary_evicted` 保存最近 24 个发生了 evict 的时间段记录;`statements_summary_evicted` 则以 30 分钟为一个记录周期,表容量为 24 个时间段。

> **注意:**
>
> `tidb_stmt_summary_history_size``tidb_stmt_summary_max_stmt_count``tidb_stmt_summary_max_sql_length` 这些配置都影响内存占用,建议根据实际情况调整(取决于 SQL 大小、SQL 数量、机器配置)不宜设置得过大。内存大小可通过 `tidb_stmt_summary_history_size` \* `tidb_stmt_summary_max_stmt_count` \* `tidb_stmt_summary_max_sql_length` \* `3` 来进行估算。
> - 假设某种 SQL 每分钟都出现,那 `statements_summary_history` 中会保存这种 SQL 最近 12 个小时的数据。但如果某种 SQL 只在每天 00:00 ~ 00:30 出现,则 `statements_summary_history` 中会保存这种 SQL 24 个时间段的数据,每个时间段的间隔都是 1 天,所以会有这种 SQL 最近 24 天的数据。
> - `tidb_stmt_summary_history_size``tidb_stmt_summary_max_stmt_count``tidb_stmt_summary_max_sql_length` 这些配置都影响内存占用,建议根据实际情况调整(取决于 SQL 大小、SQL 数量、机器配置)不宜设置得过大。内存大小可通过 `tidb_stmt_summary_history_size` \* `tidb_stmt_summary_max_stmt_count` \* `tidb_stmt_summary_max_sql_length` \* `3` 来进行估算。
### 为 statement summary 设定合适的大小

Expand Down

0 comments on commit bc1b4ad

Please sign in to comment.