2016-10-04 22 views
0

對heroku postgres我的組通過查詢超過2秒鐘,這是正常嗎?我怎樣才能進一步優化呢?兩列都被索引所以我假設它應該運行得更快。heroku postgres Group通過對索引列進行查詢需要2秒以上的時間才能執行

的查詢,

EXPLAIN ANALYZE(SELECT COUNT(*), context, call_type FROM call_tasks GROUP BY call_tasks.context, call_tasks.call_type); 

查詢計劃和分析:

GroupAggregate (cost=0.08..11500.84 rows=12 width=11) (actual time=35.395..2545.426 rows=7 loops=1) 
    Group Key: context, call_type 
    -> Index Only Scan using index_call_tasks_on_context_and_call_type on call_tasks (cost=0.08..10338.79 rows=774677 width=11) (actual time=0.022..1480.729 rows=781076 loops=1) 
     Heap Fetches: 43682 
Planning time: 0.085 ms 
Execution time: 2545.464 ms 
(6 rows) 

我使用的愛好基本的數據庫。 https://elements.heroku.com/addons/heroku-postgresql

回答

0

這是你能得到最好的,進一步的改進只能通過提高硬件製造:

  • 更快的CPU更快的聚集。
  • 更多內存將所有內容保存在RAM中。

除此之外,如果您對近似結果滿意,則可以使用定期更新的實例化視圖。