Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9e35a43
docs: update plan replayer object storage behavior
zeminzhou Mar 12, 2026
97afcb2
docs: clarify plan replayer capture token column
zeminzhou Mar 12, 2026
1953809
Update system-variables.md
zeminzhou Apr 1, 2026
4718329
Update system-variables.md
zeminzhou Apr 1, 2026
8202483
Update sql-plan-replayer.md
zeminzhou Apr 1, 2026
b81d4fb
Update sql-plan-replayer.md
zeminzhou Apr 1, 2026
554bf8a
Update sql-plan-replayer.md
zeminzhou Apr 1, 2026
fd56d6e
Update sql-plan-replayer.md
zeminzhou Apr 1, 2026
9e606b6
Update sql-plan-replayer.md
zeminzhou Apr 1, 2026
5782357
Update sql-plan-replayer.md
zeminzhou Apr 1, 2026
ae163ff
docs: plan replayer use dedicated external storage sysvar
zeminzhou Apr 1, 2026
31fe998
docs: plan replayer use dedicated external storage sysvar
zeminzhou Apr 1, 2026
b019854
docs: plan replayer use dedicated external storage sysvar
zeminzhou Apr 1, 2026
b80cc0a
docs: decouple plan replayer external storage sysvar
zeminzhou Apr 1, 2026
037efe5
fix format
Oreoxmt Apr 2, 2026
8d3ceb6
Update sql-plan-replayer.md
zeminzhou Apr 2, 2026
fbf10b9
Update sql-plan-replayer.md
zeminzhou Apr 2, 2026
1dc3b35
Update system-variables.md
zeminzhou Apr 2, 2026
98f41c8
Update system-variable-reference.md
zeminzhou Apr 2, 2026
2bf1c33
docs: align plan replayer storage path docs
zeminzhou Apr 8, 2026
b49ac50
clarify PLAN REPLAYER external storage behavior by deployment type
Oreoxmt Apr 14, 2026
619babb
Apply suggestions from code review
Oreoxmt Apr 14, 2026
801fe54
Merge pull request #1 from Oreoxmt/update-tidb_cloud_storage_uri
zeminzhou Apr 14, 2026
ae3c181
update TOC
Oreoxmt Apr 14, 2026
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
36 changes: 31 additions & 5 deletions sql-plan-replayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ You can use `PLAN REPLAYER` to save the on-site information of a TiDB cluster. T
PLAN REPLAYER DUMP [WITH STATS AS OF TIMESTAMP expression] EXPLAIN [ANALYZE] sql-statement;
```

By default, TiDB stores files generated by `PLAN REPLAYER` in local storage. If you set [`tidb_plan_replayer_external_storage_uri`](/system-variables.md#tidb_plan_replayer_external_storage_uri-new-in-v900) to a valid external storage URI, TiDB stores the generated `ZIP` files in the specified location. The configured URI must point to a storage path with the required read, write, and delete permissions. For supported URI formats, see [URI Formats of External Storage Services](/external-storage-uri.md).

Based on `sql-statement`, TiDB sorts out and exports the following on-site information:

- TiDB version
Expand Down Expand Up @@ -54,11 +56,14 @@ plan replayer dump with stats as of timestamp '2023-07-17 12:00:00' explain sele
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.
`PLAN REPLAYER DUMP` packages the table information above into a `ZIP` file and returns the download information as the execution result:
Comment thread
zeminzhou marked this conversation as resolved.
Outdated

- If the configured storage backend supports presigned URLs, TiDB returns a presigned URL.
- Otherwise, TiDB returns a file token.

> **Note:**
>
> The `ZIP` file is stored in a TiDB cluster for at most one hour. After one hour, TiDB will delete it.
> The result file is kept for at most one hour. After one hour, TiDB deletes it from the corresponding local or external storage.

```sql
MySQL [test]> plan replayer dump explain select * from t;
Expand Down Expand Up @@ -88,6 +93,17 @@ SELECT @@tidb_last_plan_replayer_token;
1 row in set (0.00 sec)
```

If the configured storage backend supports presigned URLs, the result returned by `PLAN REPLAYER DUMP` or `tidb_last_plan_replayer_token` is a presigned URL instead of a file token. For example:

```sql
+----------------------------------------------------------------------------------------------------------------------+
| Dump_link |
+----------------------------------------------------------------------------------------------------------------------+
| https://storage.example.com/replayer_xxx.zip?X-Amz-Algorithm=...&X-Amz-Credential=...&X-Amz-Signature=... |
+----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

When there are multiple SQL statements, you can obtain the result of the `PLAN REPLAYER DUMP` execution using a file. The results of multiple SQL statements are separated by `;` in this file.

```sql
Expand All @@ -111,7 +127,15 @@ SELECT @@tidb_last_plan_replayer_token;
1 row in set (0.00 sec)
```

Because the file cannot be downloaded on MySQL Client, you need to use the TiDB HTTP interface and the file identifier to download the file:
If `PLAN REPLAYER DUMP` returns a presigned URL, you can use the URL directly to download the file. The presigned URL is valid for up to one hour.

{{< copyable "shell-regular" >}}
Comment thread
zeminzhou marked this conversation as resolved.
Outdated

```shell
curl "${presigned_url}" > plan_replayer.zip
```

If `PLAN REPLAYER DUMP` returns a file token, you need to use the TiDB HTTP interface and the file token to download the file:

{{< copyable "shell-regular" >}}

Expand Down Expand Up @@ -261,11 +285,13 @@ mysql> SELECT * FROM mysql.plan_replayer_status;
3 rows in set (0.00 sec)
```

The method of downloading the file of `PLAN REPLAYER CAPTURE` is the same as that of `PLAN REPLAYER`. For details, see [Examples of exporting cluster information](#examples-of-exporting-cluster-information).
If [`tidb_plan_replayer_external_storage_uri`](/system-variables.md#tidb_plan_replayer_external_storage_uri-new-in-v900) is configured, TiDB also stores captured files in the specified external storage. The `token` column in the `mysql.plan_replayer_status` table records the file token of each captured file.

To download a file generated by `PLAN REPLAYER CAPTURE`, use the value in the `token` column together with the TiDB HTTP interface. This process is the same as the file token-based download flow described in [Examples of exporting cluster information](#examples-of-exporting-cluster-information).

> **Note:**
>
> The result file of `PLAN REPLAYER CAPTURE` is kept in the TiDB cluster for up to one week. After one week, TiDB deletes the file.
> The result file of `PLAN REPLAYER CAPTURE` is kept for up to one week. After one week, TiDB deletes it from the corresponding local or external storage.

### Remove the capture tasks

Expand Down
8 changes: 8 additions & 0 deletions system-variable-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3391,6 +3391,14 @@ Referenced in:
- [System Variables](/system-variables.md#tidb_plan_cache_max_plan_size-new-in-v710)
- [TiDB 7.1.0 Release Notes](/releases/release-7.1.0.md)


Comment thread
zeminzhou marked this conversation as resolved.
Outdated
### tidb_plan_replayer_external_storage_uri

Referenced in:

- [System Variables](/system-variables.md#tidb_plan_replayer_external_storage_uri-new-in-v900)
- [Use PLAN REPLAYER to Save and Restore the On-Site Information of a Cluster](/sql-plan-replayer.md)

### tidb_pprof_sql_cpu

Referenced in:
Expand Down
16 changes: 15 additions & 1 deletion system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -3701,7 +3701,7 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified
- Scope: SESSION
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
- Type: String
- This variable is read-only and is used to obtain the result of the last `PLAN REPLAYER DUMP` execution in the current session.
- This variable is read-only and is used to obtain the result of the last `PLAN REPLAYER DUMP` execution in the current session. The result is either a file token or, if the configured storage backend supports it, a presigned URL.

### tidb_load_based_replica_read_threshold <span class="version-mark">New in v7.0.0</span>

Expand Down Expand Up @@ -5367,6 +5367,20 @@ SHOW WARNINGS;
- Range: `[0, 9223372036854775807]`, in bytes. The memory format with the units "KiB|MiB|GiB|TiB" is also supported. `0` means no limit.
- This variable controls the maximum size of a plan that can be cached in prepared or non-prepared plan cache. If the size of a plan exceeds this value, the plan will not be cached. For more details, see [Memory management of prepared plan cache](/sql-prepared-plan-cache.md#memory-management-of-prepared-plan-cache) and [Non-prepared plan cache](/sql-plan-management.md#usage).


### tidb_plan_replayer_external_storage_uri <span class="version-mark">New in v9.0.0</span>
Comment thread
Oreoxmt marked this conversation as resolved.
Outdated

- Scope: GLOBAL
- Persists to cluster: Yes
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
- Type: String
- Default value: `""`
- This variable is used to specify the external storage URI for files generated by [`PLAN REPLAYER`](/sql-plan-replayer.md). If this variable is empty, `PLAN REPLAYER` uses local storage. The configured URI must point to a storage path with the required read, write, and delete permissions. For supported URI formats, see [URI Formats of External Storage Services](/external-storage-uri.md).
Comment thread
Oreoxmt marked this conversation as resolved.
Outdated
- The following statements and features use this variable:
- [`PLAN REPLAYER DUMP`](/sql-plan-replayer.md)
- [`PLAN REPLAYER CAPTURE`](/sql-plan-replayer.md)
- [`PLAN REPLAYER CONTINUOUS CAPTURE`](/sql-plan-replayer.md)
Comment thread
zeminzhou marked this conversation as resolved.
Outdated

### tidb_pprof_sql_cpu <span class="version-mark">New in v4.0</span>

> **Note:**
Expand Down
Loading