postresql按查询分组时间过长

时间:2019-05-27 14:32:34

标签: postgresql query-performance

我正在运行以下查询,它持续了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

0 个答案:

没有答案