Skip to content

Commit 9e35a43

Browse files
committed
docs: update plan replayer object storage behavior
1 parent d52c3c3 commit 9e35a43

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

sql-plan-replayer.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ You can use `PLAN REPLAYER` to save the on-site information of a TiDB cluster. T
2020
PLAN REPLAYER DUMP [WITH STATS AS OF TIMESTAMP expression] EXPLAIN [ANALYZE] sql-statement;
2121
```
2222

23+
By default, TiDB stores files generated by `PLAN REPLAYER` in local storage. If you set [`tidb_cloud_storage_uri`](/system-variables.md#tidb_cloud_storage_uri-new-in-v740) to a valid external storage URI, TiDB stores the generated `ZIP` files in the specified storage. For supported URI formats, see [URI Formats of External Storage Services](/external-storage-uri.md).
24+
2325
Based on `sql-statement`, TiDB sorts out and exports the following on-site information:
2426

2527
- TiDB version
@@ -54,11 +56,14 @@ plan replayer dump with stats as of timestamp '2023-07-17 12:00:00' explain sele
5456
plan replayer dump with stats as of timestamp '442012134592479233' explain select * from t;
5557
```
5658

57-
`PLAN REPLAYER DUMP` packages the table information above into a `ZIP` file and returns the file identifier as the execution result.
59+
`PLAN REPLAYER DUMP` packages the table information above into a `ZIP` file and returns the download information as the execution result:
60+
61+
- If the configured storage backend supports presigned URLs, TiDB returns a presigned URL.
62+
- Otherwise, TiDB returns a file token.
5863

5964
> **Note:**
6065
>
61-
> The `ZIP` file is stored in a TiDB cluster for at most one hour. After one hour, TiDB will delete it.
66+
> The result file is kept for at most one hour. After one hour, TiDB deletes it from the corresponding local or external storage.
6267
6368
```sql
6469
MySQL [test]> plan replayer dump explain select * from t;
@@ -88,6 +93,17 @@ SELECT @@tidb_last_plan_replayer_token;
8893
1 row in set (0.00 sec)
8994
```
9095

96+
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:
97+
98+
```sql
99+
+----------------------------------------------------------------------------------------------------------------------+
100+
| Dump_link |
101+
+----------------------------------------------------------------------------------------------------------------------+
102+
| https://storage.example.com/replayer_xxx.zip?X-Amz-Algorithm=...&X-Amz-Credential=...&X-Amz-Signature=... |
103+
+----------------------------------------------------------------------------------------------------------------------+
104+
1 row in set (0.00 sec)
105+
```
106+
91107
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.
92108

93109
```sql
@@ -111,7 +127,17 @@ SELECT @@tidb_last_plan_replayer_token;
111127
1 row in set (0.00 sec)
112128
```
113129

114-
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:
130+
If `PLAN REPLAYER DUMP` returns a presigned URL, you can use the URL directly to download the file:
131+
132+
{{< copyable "shell-regular" >}}
133+
134+
```shell
135+
curl "${presigned_url}" > plan_replayer.zip
136+
```
137+
138+
The presigned URL is valid for up to one hour.
139+
140+
If `PLAN REPLAYER DUMP` returns a file token, you need to use the TiDB HTTP interface and the file token to download the file:
115141

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

@@ -261,11 +287,13 @@ mysql> SELECT * FROM mysql.plan_replayer_status;
261287
3 rows in set (0.00 sec)
262288
```
263289

264-
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).
290+
If [`tidb_cloud_storage_uri`](/system-variables.md#tidb_cloud_storage_uri-new-in-v740) is configured, the captured file is also stored in the configured external storage. The `token` column still records the file token.
291+
292+
To download the file of `PLAN REPLAYER CAPTURE`, use the `token` value together with the TiDB HTTP interface. This is the same as the file-token based download flow described in [Examples of exporting cluster information](#examples-of-exporting-cluster-information).
265293

266294
> **Note:**
267295
>
268-
> 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.
296+
> 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.
269297
270298
### Remove the capture tasks
271299

system-variables.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,10 +1725,11 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1;
17251725
- Persists to cluster: Yes
17261726
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
17271727
- Default value: `""`
1728-
- This variable is used to specify the Amazon S3 cloud storage URI to enable [Global Sort](/tidb-global-sort.md). After enabling the [TiDB Distributed eXecution Framework (DXF)](/tidb-distributed-execution-framework.md), you can use the Global Sort feature by configuring the URI and pointing it to an appropriate cloud storage path with the necessary permissions to access the storage. For more details, see [Amazon S3 URI format](/external-storage-uri.md#amazon-s3-uri-format).
1729-
- The following statements can use the Global Sort feature.
1728+
- This variable is used to specify the cloud storage URI for TiDB features that use external storage. After enabling the [TiDB Distributed eXecution Framework (DXF)](/tidb-distributed-execution-framework.md), you can use the [Global Sort](/tidb-global-sort.md) feature by configuring the URI and pointing it to an appropriate cloud storage path with the necessary permissions to access the storage. [`PLAN REPLAYER`](/sql-plan-replayer.md) also uses this URI to store the generated files. If this variable is empty, `PLAN REPLAYER` uses local storage. For URI formats, see [URI Formats of External Storage Services](/external-storage-uri.md).
1729+
- The following statements or features can use this variable.
17301730
- The [`ADD INDEX`](/sql-statements/sql-statement-add-index.md) statement.
17311731
- The [`IMPORT INTO`](/sql-statements/sql-statement-import-into.md) statement for import jobs.
1732+
- [`PLAN REPLAYER`](/sql-plan-replayer.md), including files generated by `PLAN REPLAYER DUMP`, `PLAN REPLAYER CAPTURE`, and `PLAN REPLAYER CONTINUOUS CAPTURE`.
17321733

17331734
### tidb_ddl_error_count_limit
17341735

@@ -3701,7 +3702,7 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified
37013702
- Scope: SESSION
37023703
- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
37033704
- Type: String
3704-
- This variable is read-only and is used to obtain the result of the last `PLAN REPLAYER DUMP` execution in the current session.
3705+
- 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.
37053706

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

0 commit comments

Comments
 (0)