From 92cac702df48d7d2bbe801535a3d2b624d545f98 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 22 May 2020 12:53:40 +0800 Subject: [PATCH 1/6] Add super batch Signed-off-by: JaySon-Huang --- tidb-specific-system-variables.md | 10 ++++++++++ tiflash/tune-tiflash-performance.md | 22 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tidb-specific-system-variables.md b/tidb-specific-system-variables.md index ace30d7b410d..45f3e6957717 100644 --- a/tidb-specific-system-variables.md +++ b/tidb-specific-system-variables.md @@ -736,3 +736,13 @@ TiDB 默认会在建表时为新表分裂 Region。开启该变量后,会在 默认值:0 这个变量用来显示上一个 `execute` 语句所使用的执行计划是不是直接从 plan cache 中取出来的。 + +### tidb_allow_batch_cop 从 v4.0 版本开始引入 + +作用域:SESSION + +默认值:0 + +这个变量用来设置从 TiFlash 读取时,是否把 region 的请求进行合并。 + +当查询的表拥有 TiFlash 副本,且查询涉及的 region 数量比较大,可以尝试设置该变量为 1:对带 aggregation 的 TiFlash coprocessor 请求生效;或设置该变量为 2:对全部的 TiFlash coprocessor 请求生效。 diff --git a/tiflash/tune-tiflash-performance.md b/tiflash/tune-tiflash-performance.md index d9cb0eb12db0..38ec887bf420 100644 --- a/tiflash/tune-tiflash-performance.md +++ b/tiflash/tune-tiflash-performance.md @@ -22,10 +22,30 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/'] set @@tidb_distsql_scan_concurrency = 80; ``` -2. 开启聚合推过 JOIN / UNION 等 TiDB 算子的优化: +2. 开启 Super batch 功能: +这个变量用来设置从 TiFlash 读取时,是否把 region 的请求进行合并。当查询中涉及的 region 数量比较大,可以尝试设置该变量为 1:对带 aggregation 的 TiFlash coprocess 请求生效;设置该变量为 2:对全部的 TiFlash coprocessor 请求生效。 + + {{< copyable "sql" >}} + + ```sql + set @@tidb_allow_batch_cop = 1; + ``` + +3. 尝试开启聚合推过 `Join` / `Union` 等 TiDB 算子的优化: +这个变量用来设置优化器是否执行聚合函数下推到 Join 之前的优化操作。当查询中聚合操作执行很慢时,可以尝试设置该变量为 1。 {{< copyable "sql" >}} ```sql set @@tidb_opt_agg_push_down = 1; ``` + +4. 尝试开启 `Distince` 推过 `Join` / `Union` 等 TiDB 算子的优化: +这个变量用来设置优化器是否执行带有 `Distinct` 的聚合函数(比如 `select count(distinct a) from t`)下推到 Coprocessor 的优化操作。 +当查询中带有 `Distinct` 的聚合操作执行很慢时,可以尝试设置该变量为 `1`。 + + {{< copyable "sql" >}} + + ```sql + set @@tidb_opt_distinct_agg_push_down = 1; + ``` From 6542b07d96636585c271b47bdff2e8f4aa2f1307 Mon Sep 17 00:00:00 2001 From: JaySon Date: Fri, 22 May 2020 18:24:10 +0800 Subject: [PATCH 2/6] Apply suggestions from code review Co-authored-by: TomShawn <41534398+TomShawn@users.noreply.github.com> --- tidb-specific-system-variables.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tidb-specific-system-variables.md b/tidb-specific-system-variables.md index 45f3e6957717..02badc620b4e 100644 --- a/tidb-specific-system-variables.md +++ b/tidb-specific-system-variables.md @@ -743,6 +743,6 @@ TiDB 默认会在建表时为新表分裂 Region。开启该变量后,会在 默认值:0 -这个变量用来设置从 TiFlash 读取时,是否把 region 的请求进行合并。 +这个变量用来设置从 TiFlash 读取数据时,是否把 Region 的请求进行合并。 -当查询的表拥有 TiFlash 副本,且查询涉及的 region 数量比较大,可以尝试设置该变量为 1:对带 aggregation 的 TiFlash coprocessor 请求生效;或设置该变量为 2:对全部的 TiFlash coprocessor 请求生效。 +当查询的表拥有 TiFlash 副本,且查询涉及的 Region 数量比较多,可以尝试设置该变量为 `1`(对带 `aggregation` 的 TiFlash coprocessor 请求生效),或设置该变量为 `2`(对全部的 TiFlash coprocessor 请求生效)。 From a0fade5dcc0ad03b125821b847d9a1ad1834b956 Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 22 May 2020 18:30:27 +0800 Subject: [PATCH 3/6] address comment Signed-off-by: JaySon-Huang --- tiflash/tune-tiflash-performance.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tiflash/tune-tiflash-performance.md b/tiflash/tune-tiflash-performance.md index 38ec887bf420..4b89d1ca47c7 100644 --- a/tiflash/tune-tiflash-performance.md +++ b/tiflash/tune-tiflash-performance.md @@ -23,7 +23,7 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/'] ``` 2. 开启 Super batch 功能: -这个变量用来设置从 TiFlash 读取时,是否把 region 的请求进行合并。当查询中涉及的 region 数量比较大,可以尝试设置该变量为 1:对带 aggregation 的 TiFlash coprocess 请求生效;设置该变量为 2:对全部的 TiFlash coprocessor 请求生效。 +[`tidb_allow_batch_cop`](/tidb-specific-system-variables.md#tidb_allow_batch_cop) 变量用来设置从 TiFlash 读取时,是否把 Region 的请求进行合并。当查询中涉及的 Region 数量比较大,可以尝试设置该变量为 `1`(对带 `aggregation` 的 TiFlash coprocess 请求生效),或设置该变量为 `2`(对全部的 TiFlash coprocessor 请求生效)。 {{< copyable "sql" >}} @@ -32,7 +32,7 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/'] ``` 3. 尝试开启聚合推过 `Join` / `Union` 等 TiDB 算子的优化: -这个变量用来设置优化器是否执行聚合函数下推到 Join 之前的优化操作。当查询中聚合操作执行很慢时,可以尝试设置该变量为 1。 +[`tidb_opt_agg_push_down`](/tidb-specific-system-variables.md#tidb_opt_agg_push_down) 变量用来设置优化器是否执行聚合函数下推到 Join 之前的优化操作。当查询中聚合操作执行很慢时,可以尝试设置该变量为 1。 {{< copyable "sql" >}} @@ -40,9 +40,8 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/'] set @@tidb_opt_agg_push_down = 1; ``` -4. 尝试开启 `Distince` 推过 `Join` / `Union` 等 TiDB 算子的优化: -这个变量用来设置优化器是否执行带有 `Distinct` 的聚合函数(比如 `select count(distinct a) from t`)下推到 Coprocessor 的优化操作。 -当查询中带有 `Distinct` 的聚合操作执行很慢时,可以尝试设置该变量为 `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" >}} From 00fc5124fd388cb34b6fbd60f39e375a88c83dfe Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 22 May 2020 18:33:10 +0800 Subject: [PATCH 4/6] Fix typo Signed-off-by: JaySon-Huang --- tiflash/tune-tiflash-performance.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiflash/tune-tiflash-performance.md b/tiflash/tune-tiflash-performance.md index 4b89d1ca47c7..023fc170cda0 100644 --- a/tiflash/tune-tiflash-performance.md +++ b/tiflash/tune-tiflash-performance.md @@ -23,7 +23,7 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/'] ``` 2. 开启 Super batch 功能: -[`tidb_allow_batch_cop`](/tidb-specific-system-variables.md#tidb_allow_batch_cop) 变量用来设置从 TiFlash 读取时,是否把 Region 的请求进行合并。当查询中涉及的 Region 数量比较大,可以尝试设置该变量为 `1`(对带 `aggregation` 的 TiFlash coprocess 请求生效),或设置该变量为 `2`(对全部的 TiFlash coprocessor 请求生效)。 +[`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" >}} From 8355fc008a47f27f74776001a49608b3a19e11de Mon Sep 17 00:00:00 2001 From: JaySon-Huang Date: Fri, 22 May 2020 18:40:27 +0800 Subject: [PATCH 5/6] Fix Signed-off-by: JaySon-Huang --- tidb-specific-system-variables.md | 2 +- tiflash/tune-tiflash-performance.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tidb-specific-system-variables.md b/tidb-specific-system-variables.md index 02badc620b4e..efcab26691d9 100644 --- a/tidb-specific-system-variables.md +++ b/tidb-specific-system-variables.md @@ -745,4 +745,4 @@ TiDB 默认会在建表时为新表分裂 Region。开启该变量后,会在 这个变量用来设置从 TiFlash 读取数据时,是否把 Region 的请求进行合并。 -当查询的表拥有 TiFlash 副本,且查询涉及的 Region 数量比较多,可以尝试设置该变量为 `1`(对带 `aggregation` 的 TiFlash coprocessor 请求生效),或设置该变量为 `2`(对全部的 TiFlash coprocessor 请求生效)。 +当查询的表拥有 TiFlash 副本,且查询涉及的 Region 数量比较多,可以尝试设置该变量为 `1`(对带 `aggregation` 下推到 TiFlash Coprocessor 的请求生效),或设置该变量为 `2`(对全部下推到 TiFlash Coprocessor 请求生效)。 diff --git a/tiflash/tune-tiflash-performance.md b/tiflash/tune-tiflash-performance.md index 023fc170cda0..9ed240fe2270 100644 --- a/tiflash/tune-tiflash-performance.md +++ b/tiflash/tune-tiflash-performance.md @@ -23,7 +23,7 @@ aliases: ['/docs-cn/dev/reference/tiflash/tune-performance/'] ``` 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 请求生效)。 +[`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" >}} From 68d1cebafb9efe542db28f218ff0a047c17353e5 Mon Sep 17 00:00:00 2001 From: JaySon Date: Mon, 25 May 2020 13:03:07 +0800 Subject: [PATCH 6/6] Update scope --- tidb-specific-system-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tidb-specific-system-variables.md b/tidb-specific-system-variables.md index efcab26691d9..1f7d76a93625 100644 --- a/tidb-specific-system-variables.md +++ b/tidb-specific-system-variables.md @@ -739,7 +739,7 @@ TiDB 默认会在建表时为新表分裂 Region。开启该变量后,会在 ### tidb_allow_batch_cop 从 v4.0 版本开始引入 -作用域:SESSION +作用域:SESSION | GLOBAL 默认值:0