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-plan-replayer: add doc for historical stats integration into the plan replayer #14243

Merged
Merged
Changes from 1 commit
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
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 @@ You can use `PLAN REPLAYER` to save the on-site information of a TiDB cluster. T
{{< copyable "sql" >}}

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

Based on `sql-statement`, TiDB sorts out and exports the following on-site information:
Expand All @@ -33,6 +33,10 @@ Based on `sql-statement`, TiDB sorts out and exports the following on-site infor
- The result of `EXPLAIN [ANALYZE] sql-statement`
- Some internal procudures of query optimization

If historical statistics are [enabled](/system-variables.md#tidb_enable_historical_stats), you can specify a time in the `PLAN REPLAYER` statement to get the historical statistics at the corresponding time. You can directly specify the time and date, or specify a timestamp here. When the time is specified, TiDB will look for the historical statistics before the specified time, and export the latest one among them.
time-and-fate marked this conversation as resolved.
Show resolved Hide resolved

If there are no historical statistics that satisfy the specified time, TiDB will export the latest statistics, as if the time is not specified, and also print error messages in the `errors.txt` of the output `ZIP` file.
time-and-fate marked this conversation as resolved.
Show resolved Hide resolved

> **Note:**
>
> `PLAN REPLAYER` **DOES NOT** export any table data.
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` packages the table information above into a `ZIP` file and returns the file identifier as the execution result.
Expand Down
Loading