From 546f4c672cb21a81fae8fc555612fa87eda9cf53 Mon Sep 17 00:00:00 2001 From: yikeke Date: Tue, 23 Jun 2020 19:35:51 +0800 Subject: [PATCH] Add explaination about tidb_allow_batch_cop --- tidb-specific-system-variables.md | 10 ++++++++++ tiflash/tune-tiflash-performance.md | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tidb-specific-system-variables.md b/tidb-specific-system-variables.md index 2423595d8c3a6..996bc81fa4b51 100644 --- a/tidb-specific-system-variables.md +++ b/tidb-specific-system-variables.md @@ -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 New in v4.0 version + +- 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 diff --git a/tiflash/tune-tiflash-performance.md b/tiflash/tune-tiflash-performance.md index 2707f7e199b5e..da414bd58c0b2 100644 --- a/tiflash/tune-tiflash-performance.md +++ b/tiflash/tune-tiflash-performance.md @@ -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; + ```