LKLK
(Lklk)
1
为提高效率,请提供以下信息,问题描述清晰能够更快得到解决:
【 TiDB 使用环境】
【问题】
线上一个600多万的表group by 执行时间要11多秒,有走tiflash,有走组合索引,请问还能优化吗?
【TiDB 版本】 v5.1.1
【应用软件及版本】
【附件】 相关日志及配置信息
- TiUP Cluster Display 信息
- TiUP CLuster Edit config 信息
监控(https://metricstool.pingcap.com/)
- TiDB-Overview Grafana监控
- TiDB Grafana 监控
- TiKV Grafana 监控
- PD Grafana 监控
- 对应模块日志(包含问题前后 1 小时日志)
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出的打印结果,请务必全选并复制粘贴上传。
1 个赞
QBin
(Bin)
2
辛苦提供一下完整的 explain analyze select ....
的查询结果。(不要加 \G 另存为 TXT 上传)
1 个赞
LKLK
(Lklk)
3
好的,请看explain.txt
explain.txt (14.3 KB)
1 个赞
QBin
(Bin)
4
看起来是 tidb 这边 hash agg 这边执行得比较慢,执行一下 set session tidb_executor_concurrency = 10
再执行一下 explain analyze 看看结果。
1 个赞
LKLK
(Lklk)
5
执行了set session tidb_executor_concurrency = 10,但速度还是跟之前差不多
explain.txt (16.0 KB)
1 个赞
QBin
(Bin)
6
也给一下 show variables like 'tidb%concurrency';
看看执行这个 SQL 的 session 的变量情况。
LKLK
(Lklk)
7
±-----------------------------------±------+
| Variable_name | Value |
±-----------------------------------±------+
| tidb_build_stats_concurrency | 4 |
| tidb_checksum_table_concurrency | 4 |
| tidb_distsql_scan_concurrency | 15 |
| tidb_executor_concurrency | 1 |
| tidb_gc_concurrency | -1 |
| tidb_hash_join_concurrency | 1 |
| tidb_hashagg_final_concurrency | 1 |
| tidb_hashagg_partial_concurrency | 1 |
| tidb_index_lookup_concurrency | 1 |
| tidb_index_lookup_join_concurrency | 1 |
| tidb_index_serial_scan_concurrency | 1 |
| tidb_merge_join_concurrency | 1 |
| tidb_projection_concurrency | 1 |
| tidb_streamagg_concurrency | 1 |
| tidb_window_concurrency | -1 |
±-----------------------------------±------+
QBin
(Bin)
8
set session tidb_executor_concurrency = 10 没有生效。试一下调整 global variables ,确认tidb_hashagg_final_concurrency 、tidb_hashagg_partial_concurrency 、tidb_executor_concurrency 调整过来之后,再执行试一下。
LKLK
(Lklk)
9
大佬,谢谢,现在速度从11多秒变成1秒多了。
还有一个查询能否帮忙看下哈?是在这个group by 基础上left join 3个表的
explain.txt (44.3 KB)
±-----------------------------------±------+
| Variable_name | Value |
±-----------------------------------±------+
| tidb_build_stats_concurrency | 4 |
| tidb_checksum_table_concurrency | 4 |
| tidb_distsql_scan_concurrency | 15 |
| tidb_executor_concurrency | 50 |
| tidb_gc_concurrency | -1 |
| tidb_hash_join_concurrency | -1 |
| tidb_hashagg_final_concurrency | -1 |
| tidb_hashagg_partial_concurrency | -1 |
| tidb_index_lookup_concurrency | -1 |
| tidb_index_lookup_join_concurrency | -1 |
| tidb_index_serial_scan_concurrency | 50 |
| tidb_merge_join_concurrency | 1 |
| tidb_projection_concurrency | -1 |
| tidb_streamagg_concurrency | 1 |
| tidb_window_concurrency | -1 |
±-----------------------------------±------+
15 rows in set (0.00 sec)
system
(system)
关闭
10
此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。