Skip to content

Commit

Permalink
Add explaination about tidb_allow_batch_cop (#3002)
Browse files Browse the repository at this point in the history
Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
  • Loading branch information
yikeke and ti-srebot authored Jun 24, 2020
1 parent 03c245c commit d0a2553
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tidb-specific-system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,13 @@ set tidb_query_log_max_len = 20
- Scope: SESSION
- Default value: 0
- This variable is used to show whether the execution plan used in the previous `execute` statement is taken directly from the plan cache.
### tidb_allow_batch_cop <span class="version-mark">New in v4.0 version</span>
- Scope: SESSION | GLOBAL
- Default value: 0
- This variable is used to control how TiDB sends a coprocessor request to TiFlash. It has the following values:
* `0`: Never send requests in batches
* `1`: Aggregation and join requests are sent in batches
* `2`: All coprocessor requests are sent in batches
26 changes: 25 additions & 1 deletion tiflash/tune-tiflash-performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,34 @@ If you want to save machine resources and have no requirement on isolation, you
set @@tidb_distsql_scan_concurrency = 80;
```

2. Enable the optimization for TiDB Operator such as the aggregate pushdown of `JOIN` or `UNION`:
2. Enable the super batch feature:

You can use the [`tidb_allow_batch_cop`](/tidb-specific-system-variables.md#tidb_allow_batch_cop) variable to set whether to merge Region requests when reading from TiFlash.

When the number of Regions involved in the query is relatively large, try to set this variable to `1` (effective for coprocessor requests with `aggregation` operators that are pushed down to TiFlash), or set this variable to `2` (effective for all coprocessor requests that are pushed down to TiFlash).

{{< copyable "sql" >}}

```sql
set @@tidb_allow_batch_cop = 1;
```

3. Enable the optimization of pushing down aggregate functions before TiDB operators such as `JOIN` or `UNION`:

You can use the [`tidb_opt_agg_push_down`](/tidb-specific-system-variables.md#tidb_opt_agg_push_down) variable to control the optimizer to execute this optimization. When the aggregate operations are quite slow in the query, try to set this variable to `1`.

{{< copyable "sql" >}}

```sql
set @@tidb_opt_agg_push_down = 1;
```

4. Enable the optimization of pushing down aggregate functions with `Distinct` before TiDB operators such as `JOIN` or `UNION`:

You can use the [`tidb_opt_distinct_agg_push_down`](/tidb-specific-system-variables.md#tidb_opt_distinct_agg_push_down) variable to control the optimizer to execute this optimization. When the aggregate operations with `Distinct` are quite slow in the query, try to set this variable to `1`.

{{< copyable "sql" >}}

```sql
set @@tidb_opt_distinct_agg_push_down = 1;
```

0 comments on commit d0a2553

Please sign in to comment.