TiFlash 性能调优

本文介绍了 TiFlash 性能调优的几种方式,包括机器资源规划和 TiDB 参数调优,通过这些方式,TiFlash 性能可以达到最优状态。

资源规划

对于希望节省机器资源,并且完全没有隔离要求的场景,可以使用 TiKV 和 TiFlash 联合部署。建议为 TiKV 与 TiFlash 分别留够资源,同时避免共享磁盘。

TiDB 相关参数调优

本部分介绍如何通过调整 TiDB 相关参数来提升 TiFlash 性能,具体包括如下几个方面:

强制开启 MPP 模式

MPP 执行计划可以充分利用分布式计算资源,从而显著提高批量数据查询的效率。当查询没有生成 MPP 执行计划的时候,你可以强制开启 MPP:

tidb_enforce_mpp 变量用于控制是否忽略优化器代价估算,强制使用 TiFlash 的 MPP 模式执行查询。要开启 MPP 模式查询,执行如下命令:

1. set @@tidb_enforce_mpp = ON;

在以下示例中,tidb_enforce_mpp 开启前,TiDB 需要从 TiKV 读取数据,并在 TiDB 侧执行 Join 和 Aggregation。tidb_enforce_mpp 开启后,Join 和 Aggregation 被下推到了 TiFlash。需要注意的是,有时候优化器生成的执行计划并不稳定,可能生成 MPP,也可能不生成,这时候可以开启 tidb_enforce_mpp,强制优化器生成 MPP 计划。

MPP 模式开启前:

1. mysql> explain analyze select o_orderpriority, count(*) as order_count from orders where o_orderdate >= '1995-01-01' and o_orderdate < date_add('1995-01-01', interval '3' month) and exists (select * from lineitem where l_orderkey = o_orderkey and l_commitdate < l_receiptdate) group by o_orderpriority;
2. +--------------------------------------+--------------+-----------+-----------+---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+------+
3. | id                                   | estRows      | actRows   | task      | access object                                           | execution info                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              | operator info                                                                                                                                                                          | memory     | disk |
4. +--------------------------------------+--------------+-----------+-----------+---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+------+
5. | Projection_9                         | 1.00         | 5         | root      |                                                         | time:22.8s, loops:5, Concurrency:OFF                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | tpch_100.orders.o_orderpriority, Column#27                                                                                                                                             | 1016 Bytes | N/A  |
6. | └─HashAgg_10                         | 1.00         | 5         | root      |                                                         | time:22.8s, loops:5, partial_worker:{wall_time:22.817403422s, concurrency:5, task_num:5027, tot_wait:1m52.560509138s, tot_exec:1.523754659s, tot_time:1m54.086196522s, max:22.817363394s, p95:22.817363394s}, final_worker:{wall_time:22.817416046s, concurrency:5, task_num:20, tot_wait:1m54.086784741s, tot_exec:155.94µs, tot_time:1m54.086948982s, max:22.817396284s, p95:22.817396284s}                                                                                                                                                                                               | group by:tpch_100.orders.o_orderpriority, funcs:count(1)->Column#27, funcs:firstrow(tpch_100.orders.o_orderpriority)->tpch_100.orders.o_orderpriority                                  | 511.7 KB   | N/A  |
7. |   └─IndexHashJoin_18                 | 4429262.13   | 5145138   | root      |                                                         | time:22.8s, loops:5028, inner:{total:1m52.6s, concurrency:5, task:227, construct:5.17s, fetch:1m40s, build:1.22s, join:7.49s}                                                                                                                                                                                                                                                                                                                                                                                                                                                               | semi join, inner:IndexLookUp_15, outer key:tpch_100.orders.o_orderkey, inner key:tpch_100.lineitem.l_orderkey, equal cond:eq(tpch_100.orders.o_orderkey, tpch_100.lineitem.l_orderkey) | 46.8 MB    | N/A  |
8. |     ├─TableReader_37(Build)          | 5536577.67   | 5610951   | root      |                                                         | time:4.89s, loops:5467, cop_task: {num: 2127, max: 408.7ms, min: 277.5µs, avg: 81.6ms, p95: 249.7ms, max_proc_keys: 226272, p95_proc_keys: 220128, tot_proc: 2m50.2s, tot_wait: 40ms, rpc_num: 2127, rpc_time: 2m53.6s, copr_cache_hit_ratio: 0.02, distsql_concurrency: 15}                                                                                                                                                                                                                                                                                                                | data:Selection_36                                                                                                                                                                      | 3.42 MB    | N/A  |
9. |     │ └─Selection_36                 | 5536577.67   | 5610951   | cop[tikv] |                                                         | tikv_task:{proc max:402ms, min:0s, avg: 79.7ms, p80:151ms, p95:245ms, iters:155122, tasks:2127}, scan_detail: {total_process_keys: 149478336, total_process_keys_size: 22705157593, total_keys: 149480413, get_snapshot_time: 187.9ms, rocksdb: {key_skipped_count: 149478336, block: {cache_hit_count: 393690}}}                                                                                                                                                                                                                                                                           | ge(tpch_100.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch_100.orders.o_orderdate, 1995-04-01 00:00:00.000000)                                                               | N/A        | N/A  |
10. |     │   └─TableFullScan_35           | 150000000.00 | 150000000 | cop[tikv] | table:orders                                            | tikv_task:{proc max:382ms, min:0s, avg: 74.6ms, p80:141ms, p95:229ms, iters:155122, tasks:2127}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | keep order:false                                                                                                                                                                       | N/A        | N/A  |
11. |     └─IndexLookUp_15(Probe)          | 22018496.89  | 14185840  | root      |                                                         | time:1m33.4s, loops:14204, index_task: {total_time: 1m10.8s, fetch_handle: 1m10.7s, build: 3.9ms, wait: 13.3ms}, table_task: {total_time: 1m44.4s, num: 1989, concurrency: 5}                                                                                                                                                                                                                                                                                                                                                                                                               |                                                                                                                                                                                        | 17.9 KB    | N/A  |
12. |       ├─IndexRangeScan_12(Build)     | 27523121.11  | 22441356  | cop[tikv] | table:lineitem, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) | time:1m8.8s, loops:23635, cop_task: {num: 12537, max: 179.3ms, min: 331.4µs, avg: 22.7ms, p95: 66.9ms, max_proc_keys: 13755, p95_proc_keys: 5088, tot_proc: 3m44s, tot_wait: 129ms, rpc_num: 12537, rpc_time: 4m44s, copr_cache_hit_ratio: 0.06, distsql_concurrency: 15}, tikv_task:{proc max:170ms, min:0s, avg: 18.8ms, p80:29ms, p95:62ms, iters:68823, tasks:12537}, scan_detail: {total_process_keys: 21985403, total_process_keys_size: 1165226359, total_keys: 27492546, get_snapshot_time: 563.1ms, rocksdb: {key_skipped_count: 21985403, block: {cache_hit_count: 44004354}}}    | range: decided by [eq(tpch_100.lineitem.l_orderkey, tpch_100.orders.o_orderkey)], keep order:false                                                                                     | N/A        | N/A  |
13. |       └─Selection_14(Probe)          | 22018496.89  | 14185840  | cop[tikv] |                                                         | time:1m34.8s, loops:16882, cop_task: {num: 12057, max: 240.4ms, min: 328.5µs, avg: 20.4ms, p95: 73.1ms, max_proc_keys: 15005, p95_proc_keys: 6118, tot_proc: 3m39.8s, tot_wait: 300ms, rpc_num: 12057, rpc_time: 4m5.7s, copr_cache_hit_ratio: 0.28, distsql_concurrency: 15}, tikv_task:{proc max:230ms, min:0s, avg: 27.5ms, p80:45ms, p95:82ms, iters:74165, tasks:12057}, scan_detail: {total_process_keys: 19916937, total_process_keys_size: 3957799619, total_keys: 24053143, get_snapshot_time: 1.07s, rocksdb: {key_skipped_count: 19254567, block: {cache_hit_count: 37816908}}}  | lt(tpch_100.lineitem.l_commitdate, tpch_100.lineitem.l_receiptdate)                                                                                                                    | N/A        | N/A  |
14. |         └─TableRowIDScan_13          | 27523121.11  | 22441356  | cop[tikv] | table:lineitem                                          | tikv_task:{proc max:230ms, min:0s, avg: 27.2ms, p80:45ms, p95:81ms, iters:74165, tasks:12057}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | keep order:false                                                                                                                                                                       | N/A        | N/A  |
15. +--------------------------------------+--------------+-----------+-----------+---------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+------+
16. 10 rows in set (22.82 sec)

开启 MPP 模式:

1. mysql> set @@tidb_enforce_mpp = ON;
2. Query OK, 0 rows affected (0.00 sec)

MPP 模式开启后:

1. mysql> explain analyze select o_orderpriority, count(*) as order_count from orders where o_orderdate >= '1995-01-01' and o_orderdate < date_add('1995-01-01', interval '3' month) and exists (select * from lineitem where l_orderkey = o_orderkey and l_commitdate < l_receiptdate) group by o_orderpriority;
2. +--------------------------------------------------+--------------+-----------+--------------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------+
3. | id                                               | estRows      | actRows   | task         | access object  | execution info                                                                                                                                                                                                                                                                                                                                        | operator info                                                                                                                                                                 | memory | disk |
4. +--------------------------------------------------+--------------+-----------+--------------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------+
5. | TableReader_59                                   | 1.00         | 5         | root         |                | time:5.97s, loops:2, cop_task: {num: 8, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00}                                                                                                                                                                                                                                               | data:ExchangeSender_58                                                                                                                                                        | N/A    | N/A  |
6. | └─ExchangeSender_58                              | 1.00         | 5         | mpp[tiflash] |                | tiflash_task:{proc max:5.97s, min:5.97s, avg: 5.97s, p80:5.97s, p95:5.97s, iters:5, tasks:3, threads:60}                                                                                                                                                                                                                                              | ExchangeType: PassThrough                                                                                                                                                     | N/A    | N/A  |
7. |   └─Projection_10                                | 1.00         | 5         | mpp[tiflash] |                | tiflash_task:{proc max:5.97s, min:5.96s, avg: 5.97s, p80:5.97s, p95:5.97s, iters:5, tasks:3, threads:60}                                                                                                                                                                                                                                              | tpch_100.orders.o_orderpriority, Column#27                                                                                                                                    | N/A    | N/A  |
8. |     └─Projection_54                              | 1.00         | 5         | mpp[tiflash] |                | tiflash_task:{proc max:5.97s, min:5.96s, avg: 5.97s, p80:5.97s, p95:5.97s, iters:5, tasks:3, threads:60}                                                                                                                                                                                                                                              | Column#27, tpch_100.orders.o_orderpriority                                                                                                                                    | N/A    | N/A  |
9. |       └─HashAgg_55                               | 1.00         | 5         | mpp[tiflash] |                | tiflash_task:{proc max:5.97s, min:5.96s, avg: 5.97s, p80:5.97s, p95:5.97s, iters:5, tasks:3, threads:60}                                                                                                                                                                                                                                              | group by:tpch_100.orders.o_orderpriority, funcs:sum(Column#32)->Column#27, funcs:firstrow(tpch_100.orders.o_orderpriority)->tpch_100.orders.o_orderpriority, stream_count: 20 | N/A    | N/A  |
10. |         └─ExchangeReceiver_57                    | 1.00         | 15        | mpp[tiflash] |                | tiflash_task:{proc max:5.97s, min:5.96s, avg: 5.97s, p80:5.97s, p95:5.97s, iters:5, tasks:3, threads:60}                                                                                                                                                                                                                                              | stream_count: 20                                                                                                                                                              | N/A    | N/A  |
11. |           └─ExchangeSender_56                    | 1.00         | 15        | mpp[tiflash] |                | tiflash_task:{proc max:5.96s, min:0s, avg: 1.99s, p80:5.96s, p95:5.96s, iters:768, tasks:3, threads:60}                                                                                                                                                                                                                                               | ExchangeType: HashPartition, Hash Cols: [name: tpch_100.orders.o_orderpriority, collate: utf8mb4_bin], stream_count: 20                                                       | N/A    | N/A  |
12. |             └─HashAgg_52                         | 1.00         | 15        | mpp[tiflash] |                | tiflash_task:{proc max:5.96s, min:0s, avg: 1.99s, p80:5.96s, p95:5.96s, iters:768, tasks:3, threads:60}                                                                                                                                                                                                                                               | group by:tpch_100.orders.o_orderpriority, funcs:count(1)->Column#32                                                                                                           | N/A    | N/A  |
13. |               └─HashJoin_41                      | 4429262.13   | 5145138   | mpp[tiflash] |                | tiflash_task:{proc max:5.95s, min:0s, avg: 1.98s, p80:5.95s, p95:5.95s, iters:118, tasks:3, threads:60}                                                                                                                                                                                                                                               | semi join, equal:[eq(tpch_100.orders.o_orderkey, tpch_100.lineitem.l_orderkey)], stream_count: 20                                                                             | N/A    | N/A  |
14. |                 ├─ExchangeReceiver_26(Build)     | 480030321.60 | 379356474 | mpp[tiflash] |                | tiflash_task:{proc max:3.26s, min:0s, avg: 1.09s, p80:3.26s, p95:3.26s, iters:42469, tasks:3, threads:60}                                                                                                                                                                                                                                             | stream_count: 20                                                                                                                                                              | N/A    | N/A  |
15. |                 │ └─ExchangeSender_25            | 480030321.60 | 379356474 | mpp[tiflash] |                | tiflash_task:{proc max:3.37s, min:0s, avg: 1.12s, p80:3.37s, p95:3.37s, iters:9292, tasks:3, threads:60}                                                                                                                                                                                                                                              | ExchangeType: HashPartition, Hash Cols: [name: tpch_100.lineitem.l_orderkey, collate: binary], stream_count: 20                                                               | N/A    | N/A  |
16. |                 │   └─Projection_60              | 480030321.60 | 379356474 | mpp[tiflash] |                | tiflash_task:{proc max:819.1ms, min:0s, avg: 273ms, p80:819.1ms, p95:819.1ms, iters:9292, tasks:3, threads:60}                                                                                                                                                                                                                                        | tpch_100.lineitem.l_orderkey                                                                                                                                                  | N/A    | N/A  |
17. |                 │     └─Selection_24             | 480030321.60 | 379356474 | mpp[tiflash] |                | tiflash_task:{proc max:817.1ms, min:0s, avg: 272.4ms, p80:817.1ms, p95:817.1ms, iters:9292, tasks:3, threads:60}                                                                                                                                                                                                                                      | lt(tpch_100.lineitem.l_commitdate, tpch_100.lineitem.l_receiptdate)                                                                                                           | N/A    | N/A  |
18. |                 │       └─TableFullScan_23       | 600037902.00 | 600037902 | mpp[tiflash] | table:lineitem | tiflash_task:{proc max:328.1ms, min:0s, avg: 109.4ms, p80:328.1ms, p95:328.1ms, iters:9292, tasks:3, threads:60}, tiflash_scan:{dtfile:{total_scanned_packs:73475, total_skipped_packs:13452, total_scanned_rows:600230532, total_skipped_rows:109887612, total_rs_index_load_time: 35ms, total_read_time: 34065ms}, total_create_snapshot_time: 0ms} | keep order:false                                                                                                                                                              | N/A    | N/A  |
19. |                 └─ExchangeReceiver_22(Probe)     | 5536577.67   | 5610951   | mpp[tiflash] |                | tiflash_task:{proc max:2.5s, min:0s, avg: 833.7ms, p80:2.5s, p95:2.5s, iters:669, tasks:3, threads:60}                                                                                                                                                                                                                                                |                                                                                                                                                                               | N/A    | N/A  |
20. |                   └─ExchangeSender_21            | 5536577.67   | 5610951   | mpp[tiflash] |                | tiflash_task:{proc max:5.93s, min:0s, avg: 1.98s, p80:5.93s, p95:5.93s, iters:2336, tasks:3, threads:60}                                                                                                                                                                                                                                              | ExchangeType: HashPartition, Hash Cols: [name: tpch_100.orders.o_orderkey, collate: binary]                                                                                   | N/A    | N/A  |
21. |                     └─Selection_20               | 5536577.67   | 5610951   | mpp[tiflash] |                | tiflash_task:{proc max:325.5ms, min:0s, avg: 108.5ms, p80:325.5ms, p95:325.5ms, iters:2336, tasks:3, threads:60}                                                                                                                                                                                                                                      | ge(tpch_100.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch_100.orders.o_orderdate, 1995-04-01 00:00:00.000000)                                                      | N/A    | N/A  |
22. |                       └─TableFullScan_19         | 150000000.00 | 150000000 | mpp[tiflash] | table:orders   | tiflash_task:{proc max:238.5ms, min:0s, avg: 79.5ms, p80:238.5ms, p95:238.5ms, iters:2336, tasks:3, threads:60}, tiflash_scan:{dtfile:{total_scanned_packs:18541, total_skipped_packs:186, total_scanned_rows:150000611, total_skipped_rows:1513328, total_rs_index_load_time: 75ms, total_read_time: 11454ms}, total_create_snapshot_time: 0ms}      | keep order:false                                                                                                                                                              | N/A    | N/A  |
23. +--------------------------------------------------+--------------+-----------+--------------+----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------+------+
24. 18 rows in set (6.00 sec)

聚合下推 Join 或 Union

将聚合操作下推到 Join 或 Union 之前执行,有可能能显著减少 Join 或 Union 需要处理的数据量,从而提升性能。

tidb_opt_agg_push_down 变量用来设置优化器是否执行聚合函数下推到 Join 之前的优化操作。当查询中聚合操作执行很慢时,可以尝试设置该变量为 ON。

1. set @@tidb_opt_agg_push_down = ON;

在以下示例中,tidb_opt_agg_push_down 开启前,HashAgg_58 在 HashJoin_41 之后执行。tidb_opt_agg_push_down 开启后,新生成的 HashAgg_21 和 HashAgg_32 在 HashJoin_76 之前执行,显著减少了 Join 需要处理的数据量。

tidb_opt_agg_push_down 开启前:

1. mysql> explain analyze select count(*) from t1 join t2 where t1.a = t2.b group by t1.a;
2. +------------------------------------------+--------------+-----------+--------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+--------+------+
3. | id                                       | estRows      | actRows   | task         | access object | execution info                                                                                                                                                                                                                                                                                                                                | operator info                                                                                      | memory | disk |
4. +------------------------------------------+--------------+-----------+--------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+--------+------+
5. | TableReader_66                           | 100450000.00 | 20        | root         |               | time:2.13s, loops:2, cop_task: {num: 21, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00}                                                                                                                                                                                                                                      | data:ExchangeSender_65                                                                             | N/A    | N/A  |
6. | └─ExchangeSender_65                      | 100450000.00 | 20        | mpp[tiflash] |               | tiflash_task:{proc max:2.13s, min:2.08s, avg: 2.11s, p80:2.13s, p95:2.13s, iters:768, tasks:3, threads:60}                                                                                                                                                                                                                                    | ExchangeType: PassThrough                                                                          | N/A    | N/A  |
7. |   └─Projection_60                        | 100450000.00 | 20        | mpp[tiflash] |               | tiflash_task:{proc max:2.13s, min:2.08s, avg: 2.11s, p80:2.13s, p95:2.13s, iters:768, tasks:3, threads:60}                                                                                                                                                                                                                                    | Column#43                                                                                          | N/A    | N/A  |
8. |     └─HashAgg_58                         | 100450000.00 | 20        | mpp[tiflash] |               | tiflash_task:{proc max:2.13s, min:2.08s, avg: 2.11s, p80:2.13s, p95:2.13s, iters:768, tasks:3, threads:60}                                                                                                                                                                                                                                    | group by:test.t1.a, funcs:count(1)->Column#43                                                      | N/A    | N/A  |
9. |       └─HashJoin_41                      | 600000000.00 | 600000000 | mpp[tiflash] |               | tiflash_task:{proc max:1.77s, min:1.67s, avg: 1.73s, p80:1.77s, p95:1.77s, iters:10955, tasks:3, threads:60}                                                                                                                                                                                                                                  | inner join, equal:[eq(test.t1.a, test.t2.b)], stream_count: 20                                     | N/A    | N/A  |
10. |         ├─ExchangeReceiver_22(Build)     | 100450000.00 | 99980000  | mpp[tiflash] |               | tiflash_task:{proc max:171ms, min:127ms, avg: 154.5ms, p80:171ms, p95:171ms, iters:10440, tasks:3, threads:60}                                                                                                                                                                                                                                | stream_count: 20                                                                                   | N/A    | N/A  |
11. |         │ └─ExchangeSender_21            | 100450000.00 | 99980000  | mpp[tiflash] |               | tiflash_task:{proc max:498.7ms, min:0s, avg: 166.2ms, p80:498.7ms, p95:498.7ms, iters:1653, tasks:3, threads:60}                                                                                                                                                                                                                              | ExchangeType: HashPartition, Hash Cols: [name: test.t1.a, collate: binary], stream_count: 20       | N/A    | N/A  |
12. |         │   └─Selection_20               | 100450000.00 | 99980000  | mpp[tiflash] |               | tiflash_task:{proc max:83.7ms, min:0s, avg: 27.9ms, p80:83.7ms, p95:83.7ms, iters:1653, tasks:3, threads:60}                                                                                                                                                                                                                                  | not(isnull(test.t1.a))                                                                             | N/A    | N/A  |
13. |         │     └─TableFullScan_19         | 100450000.00 | 99980000  | mpp[tiflash] | table:t1      | tiflash_task:{proc max:41.7ms, min:0s, avg: 13.9ms, p80:41.7ms, p95:41.7ms, iters:1653, tasks:3, threads:60}, tiflash_scan:{dtfile:{total_scanned_packs:12336, total_skipped_packs:5759, total_scanned_rows:100083566, total_skipped_rows:46786721, total_rs_index_load_time: 5ms, total_read_time: 1105ms}, total_create_snapshot_time: 0ms} | keep order:false                                                                                   | N/A    | N/A  |
14. |         └─ExchangeReceiver_26(Probe)     | 600000000.00 | 600000000 | mpp[tiflash] |               | tiflash_task:{proc max:373ms, min:71ms, avg: 253.2ms, p80:373ms, p95:373ms, iters:28135, tasks:3, threads:60}                                                                                                                                                                                                                                 |                                                                                                    | N/A    | N/A  |
15. |           └─ExchangeSender_25            | 600000000.00 | 600000000 | mpp[tiflash] |               | tiflash_task:{proc max:2.07s, min:0s, avg: 689.6ms, p80:2.07s, p95:2.07s, iters:9388, tasks:3, threads:60}                                                                                                                                                                                                                                    | ExchangeType: HashPartition, Hash Cols: [name: test.t2.b, collate: binary]                         | N/A    | N/A  |
16. |             └─Selection_24               | 600000000.00 | 600000000 | mpp[tiflash] |               | tiflash_task:{proc max:146.9ms, min:0s, avg: 49ms, p80:146.9ms, p95:146.9ms, iters:9388, tasks:3, threads:60}                                                                                                                                                                                                                                 | not(isnull(test.t2.b))                                                                             | N/A    | N/A  |
17. |               └─TableFullScan_23         | 600000000.00 | 600000000 | mpp[tiflash] | table:t2      | tiflash_task:{proc max:63.8ms, min:0s, avg: 21.3ms, p80:63.8ms, p95:63.8ms, iters:9388, tasks:3, threads:60}, tiflash_scan:{dtfile:{total_scanned_packs:73834, total_skipped_packs:439, total_scanned_rows:600007458, total_skipped_rows:3553131, total_rs_index_load_time: 12ms, total_read_time: 270ms}, total_create_snapshot_time: 0ms}   | keep order:false                                                                                   | N/A    | N/A  |
18. +------------------------------------------+--------------+-----------+--------------+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+--------+------+
19. 13 rows in set (2.15 sec)

开启 tidb_opt_agg_push_down:

1. mysql> set @@tidb_opt_agg_push_down = ON;
2. Query OK, 0 rows affected (0.00 sec)

开启 tidb_opt_agg_push_down 后:

``` 1. mysql> explain analyze select count(*) from t1 join t2 where t1.a = t2.b group by t1.a; 2. +------------------------------------------------------+--------------+-----------+--------------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+--------+------+ 3. | id | estRows | actRows | task | access object | execution info | operator info | memory | disk | 4. +------------------------------------------------------+--------------+-----------+--------------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------+--------+------+ 5. | TableReader_85 | 20.00 | 20 | root | | time:432.4ms, loops:2, cop_task: {num: 19, max: 0s, min: 0s, avg: 0s, p95: 0s, copr_cache_hit_ratio: 0.00} | data:ExchangeSender_84 | N/A | N/A | 6. | └─ExchangeSender_84 | 20.00 | 20 | mpp[tiflash] | | tiflash_task:{proc max:431.1ms, min:429.3ms, avg: 430.4ms, p80:431.1ms, p95:431.1ms, iters:16, tasks:3, threads:60} | ExchangeType: PassThrough | N/A | N/A | 7. | └─Projection_83 | 20.00 | 20 | mpp[tiflash] | | tiflash_task:{proc max:430.1ms, min:429.3ms, avg: 429.7ms, p80:430.1ms, p95:430.1ms, iters:16, tasks:3, threads:60} | Column#43 | N/A | N/A | 8. | └─HashAgg_82 | 20.00 | 20 | mpp[tiflash] | | tiflash_task:{proc max:430.1ms, min:429.3ms, avg: 429.7ms, p80:430.1ms, p95:430.1ms, iters:16, tasks:3, threads:60} | group by:test.t1.a, funcs:count(Column#44)->Column#43, stream_count: 20 | N/A | N/A | 9. | └─ExchangeReceiver_78 | 20.00 | 20 | mpp[tiflash] | | tiflash_task:{proc max:430.1ms, min:429.3ms, avg: 429.7ms, p80:430.1ms, p95:430.1ms, iters:16, tasks:3, threads:60} | stream_count: 20 | N/A | N/A | 10. | └─ExchangeSender_77 | 20.00 | 20 | mpp[tiflash] | | tiflash_task:{proc max:427ms, min:0s, avg: 142.3ms, p80:427ms, p95:427ms, iters:60, tasks:3, threads:60}

(本文超出站点单文档体积上限,已截断)