Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explaination about tidb_allow_batch_cop #3265

Merged
merged 7 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tidb-specific-system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,3 +736,13 @@ TiDB 默认会在建表时为新表分裂 Region。开启该变量后,会在
默认值:0

这个变量用来显示上一个 `execute` 语句所使用的执行计划是不是直接从 plan cache 中取出来的。

### tidb_allow_batch_cop <span class="version-mark">从 v4.0 版本开始引入</span>

作用域:SESSION | GLOBAL

默认值:0

这个变量用来设置从 TiFlash 读取数据时,是否把 Region 的请求进行合并。

当查询的表拥有 TiFlash 副本,且查询涉及的 Region 数量比较多,可以尝试设置该变量为 `1`(对带 `aggregation` 下推到 TiFlash Coprocessor 的请求生效),或设置该变量为 `2`(对全部下推到 TiFlash Coprocessor 请求生效)。
21 changes: 20 additions & 1 deletion tiflash/tune-tiflash-performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,29 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/']
set @@tidb_distsql_scan_concurrency = 80;
```

2. 开启聚合推过 JOIN / UNION 等 TiDB 算子的优化:
2. 开启 Super batch 功能:
[`tidb_allow_batch_cop`](/tidb-specific-system-variables.md#tidb_allow_batch_cop) 变量用来设置从 TiFlash 读取时,是否把 Region 的请求进行合并。当查询中涉及的 Region 数量比较大,可以尝试设置该变量为 `1`(对带 `aggregation` 下推到 TiFlash Coprocessor 的请求生效),或设置该变量为 `2`(对全部下推到 TiFlash Coprocessor 请求生效)。

{{< copyable "sql" >}}

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

3. 尝试开启聚合推过 `Join` / `Union` 等 TiDB 算子的优化:
[`tidb_opt_agg_push_down`](/tidb-specific-system-variables.md#tidb_opt_agg_push_down) 变量用来设置优化器是否执行聚合函数下推到 Join 之前的优化操作。当查询中聚合操作执行很慢时,可以尝试设置该变量为 1。

{{< copyable "sql" >}}

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

4. 尝试开启 `Distince` 推过 `Join` / `Union` 等 TiDB 算子的优化:
[`tidb_opt_distinct_agg_push_down`](/tidb-specific-system-variables.md#tidb_opt_distinct_agg_push_down) 变量用来设置优化器是否执行带有 `Distinct` 的聚合函数(比如 `select count(distinct a) from t`)下推到 Coprocessor 的优化操作。当查询中带有 `Distinct` 的聚合操作执行很慢时,可以尝试设置该变量为 `1`。

{{< copyable "sql" >}}

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