Skip to content

Commit

Permalink
sql-plan-replayer: add doc for historical stats integration into the…
Browse files Browse the repository at this point in the history
… plan replayer (#14524)
  • Loading branch information
time-and-fate authored Aug 2, 2023
1 parent 741eb7a commit e5763ee
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sql-plan-replayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ summary: 了解如何使用 PLAN REPLAY 命令保存和恢复集群现场信息
{{< copyable "sql" >}}

```sql
PLAN REPLAYER DUMP EXPLAIN [ANALYZE] sql-statement;
PLAN REPLAYER DUMP EXPLAIN [ANALYZE] [WITH STATS AS OF TIMESTAMP expression] sql-statement;
```

TiDB 根据 `sql-statement` 整理出以下集群现场信息:
Expand All @@ -33,6 +33,10 @@ TiDB 根据 `sql-statement` 整理出以下集群现场信息:
- `EXPLAIN [ANALYZE] sql-statement` 的结果
- 优化器进行查询优化的一些内部步骤的记录

[启用历史统计信息](/system-variables.md#tidb_enable_historical_stats)时,可以在 `PLAN REPLAYER` 语句中指定时间来获取对应时间的统计信息。该语法支持直接指定日期时间或指定时间戳。此时,TiDB 会查找指定时间之前的历史统计信息,并导出其中最新的一份。

如果没有找到指定时间之前的历史统计信息,TiDB 会直接导出最新统计信息(和未指定时间时的行为一致),并且在导出的 `ZIP` 文件中的 `errors.txt` 中输出错误信息。

> **注意:**
>
> `PLAN REPLAYER` **不会**导出表中数据
Expand All @@ -48,6 +52,8 @@ insert into t values(1,1), (2, 2), (3, 3);
analyze table t;

plan replayer dump explain select * from t;
plan replayer dump with stats as of timestamp '2023-07-17 12:00:00' explain select * from t;
plan replayer dump with stats as of timestamp '442012134592479233' explain select * from t;
```

`PLAN REPLAYER DUMP` 会将以上信息打包整理成 `ZIP` 文件,并返回文件标识作为执行结果。
Expand Down

0 comments on commit e5763ee

Please sign in to comment.