Skip to content

Commit

Permalink
support plan replayer for multi sqls (#10522)
Browse files Browse the repository at this point in the history
  • Loading branch information
shichun-0415 authored Sep 27, 2022
1 parent 1c08431 commit 26f519f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
45 changes: 43 additions & 2 deletions sql-plan-replayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,55 @@ plan replayer dump explain select * from t;
```sql
MySQL [test]> plan replayer dump explain select * from t;
```

```sql
+------------------------------------------------------------------+
| Dump_link |
+------------------------------------------------------------------+
| replayer_single_JOGvpu4t7dssySqJfTtS4A==_1635750890568691080.zip |
| replayer_JOGvpu4t7dssySqJfTtS4A==_1635750890568691080.zip |
+------------------------------------------------------------------+
1 row in set (0.015 sec)
```

Alternatively, you can use the session variable [`tidb_last_plan_replayer_token`](/system-variables.md#tidb_last_plan_replayer_token-new-in-v630) to obtain the result of the last `PLAN REPLAYER DUMP` execution.

```sql
SELECT @@tidb_last_plan_replayer_token;
```

```sql
+-----------------------------------------------------------+
| @@tidb_last_plan_replayer_token |
+-----------------------------------------------------------+
| replayer_Fdamsm3C7ZiPJ-LQqgVjkA==_1663304195885090000.zip |
+-----------------------------------------------------------+
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
plan replayer dump explain 'sqls.txt';
```

```sql
Query OK, 0 rows affected (0.03 sec)
```

```sql
SELECT @@tidb_last_plan_replayer_token;
```

```sql
+-----------------------------------------------------------+
| @@tidb_last_plan_replayer_token |
+-----------------------------------------------------------+
| replayer_LEDKg8sb-K0u24QesiH8ig==_1663226556509182000.zip |
+-----------------------------------------------------------+
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:

{{< copyable "shell-regular" >}}
Expand All @@ -78,7 +119,7 @@ http://${tidb-server-ip}:${tidb-server-status-port}/plan_replayer/dump/${file_to
{{< copyable "shell-regular" >}}

```shell
curl http://127.0.0.1:10080/plan_replayer/dump/replayer_single_JOGvpu4t7dssySqJfTtS4A==_1635750890568691080.zip > plan_replayer.zip
curl http://127.0.0.1:10080/plan_replayer/dump/replayer_JOGvpu4t7dssySqJfTtS4A==_1635750890568691080.zip > plan_replayer.zip
```

## Use `PLAN REPLAYER` to import cluster information
Expand Down
7 changes: 7 additions & 0 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,13 @@ For a system upgraded to v5.0 from an earlier version, if you have not modified
- The information of transaction fallback from async commit or one-phase commit to two-phase commit.
- The error encountered.
### `tidb_last_plan_replayer_token` <span class="version-mark">New in v6.3.0</span>
- Scope:SESSION
- Persists to cluster: 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.
### tidb_log_file_max_days <span class="version-mark">New in v5.3.0</span>
- Scope: SESSION
Expand Down

0 comments on commit 26f519f

Please sign in to comment.