postgresql - postresql group by 查询耗时太长
问题描述
我正在运行以下查询,它需要 5 分钟,
SELECT "DID"
FROM location_signals
GROUP BY "DID";
我在 DID 上有一个索引,变量 char 100,表有大约 1.5 亿条记录,如何进一步改进和优化?有没有可以添加的其他索引或建议?谢谢
编辑:以下解释分析查询的结果:
Finalize GroupAggregate (cost=23803276.36..24466411.92 rows=179625 width=44) (actual time=285577.900..321360.237 rows=4833061 loops=1)
Group Key: DID
-> Gather Merge (cost=23803276.36..24462819.42 rows=359250 width=44) (actual time=285577.874..320018.354 rows=10825153 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Partial GroupAggregate (cost=23802276.33..24420353.03 rows=179625 width=44) (actual time=281580.548..310818.137 rows=3608384 loops=3)
Group Key: DID
-> Sort (cost=23802276.33..24007703.15 rows=82170727 width=36) (actual time=281580.535..303887.638 rows=65736579 loops=3)
Sort Key: DID
Sort Method: external merge Disk: 2987656kB
Worker 0: Sort Method: external merge Disk: 3099408kB
Worker 1: Sort Method: external merge Disk: 2987648kB
-> Parallel Seq Scan on location_signals (cost=0.00..6259493.27 rows=82170727 width=36) (actual time=0.043..13460.990 rows=65736579 loops=3)
Planning Time: 1.332 ms
Execution Time: 322686.767 ms
解决方案
推荐阅读
- python-3.x - 当我使用熊猫阅读 excel 时,如何删除上标?
- r - data.table 为唯一观察赋值
- sql - 字母数字排序
- excel - 如何修复 Excel-VBA 中的“运行时错误 '13':类型不匹配”错误?
- r - R将包含日期的列名转换为“月年”格式
- python - 简化 z3 位向量表达式,但避免提取和连接
- python - 在 Keras 顺序模型中使用的 epoch 数
- amazon-web-services - CloudTrail - CloudTrail 管理事件中的 sourceIPAddress 字段
- deployment - git通过arm模板集成Azure数据工厂的部署场景
- python - 如何找到特定第 3 方(例如 NumPy)API 的 cpython 源代码文件?