diff --git a/tidb-resource-control.md b/tidb-resource-control.md index 2f681173d0e65..26676d1224c89 100644 --- a/tidb-resource-control.md +++ b/tidb-resource-control.md @@ -278,7 +278,7 @@ Supported operations (`ACTION`): - `DRYRUN`: no action is taken. The records are appended for the runaway queries. This is mainly used to observe whether the condition setting is reasonable. - `COOLDOWN`: the execution priority of the query is lowered to the lowest level. The query continues to execute with the lowest priority and does not occupy resources of other operations. - `KILL`: the identified query is automatically terminated and reports an error `Query execution was interrupted, identified as runaway query`. -- `SWITCH_GROUP`: switches the identified query to the specified resource group for continued execution. This option is introduced in v8.4.0. +- `SWITCH_GROUP`: switches the identified query to the specified resource group for continued execution. After the query completes, the consequential SQL statements are executed in the original resource group. If the target resource group does not exist, the query stays in the original resource group. This option is introduced in v8.4.0. To avoid too many concurrent runaway queries that exhaust system resources, the resource control feature introduces a quick identification mechanism, which can quickly identify and isolate runaway queries. You can use this feature through the `WATCH` clause. When a query is identified as a runaway query, this mechanism extracts the matching feature (defined by the parameter after `WATCH`) of the query. In the next period of time (defined by `DURATION`), the matching feature of the runaway query is added to the watch list, and the TiDB instance matches queries with the watch list. The matching queries are directly marked as runaway queries and isolated according to the corresponding action, instead of waiting for them to be identified by conditions. The `KILL` operation terminates the query and reports an error `Quarantined and interrupted because of being in runaway watch list`. @@ -302,15 +302,18 @@ The parameters of `QUERY_LIMIT` are as follows: > **Note:** > -> It is recommended to use the `SWITCH_GROUP` statement together with the [`QUERY WATCH`](/tidb-resource-control.md#query-watch-parameters) statement. Because `QUERY_LIMIT` only triggers the corresponding `ACTION` operation when the query execution time exceeds the configured `EXEC_ELAPSED`, `SWITCH_GROUP` might not be able to switch the query to the target resource group in a timely manner in such scenarios. +> If you want to quarantine the runaway queries strictly in one resource group, it is recommended to set directive `SWITCH_GROUP` together with the [`QUERY WATCH`](/tidb-resource-control.md#query-watch-parameters) statement. Because `QUERY_LIMIT` only triggers the corresponding `ACTION` operation when the query meets the criteria, `SWITCH_GROUP` might not be able to switch the query to the target resource group in a timely manner in such scenarios. #### Examples 1. Create a resource group `rg1` with a quota of 500 RUs per second, and define a runaway query as one that exceeds 60 seconds, and lower the priority of the runaway query. + ```sql CREATE RESOURCE GROUP IF NOT EXISTS rg1 RU_PER_SEC = 500 QUERY_LIMIT=(EXEC_ELAPSED='60s', ACTION=COOLDOWN); ``` + 2. Change the `rg1` resource group to terminate the runaway queries, and mark the queries with the same pattern as runaway queries immediately in the next 10 minutes. + ```sql ALTER RESOURCE GROUP rg1 QUERY_LIMIT=(EXEC_ELAPSED='60s', ACTION=KILL, WATCH=SIMILAR DURATION='10m'); ```