0

query実行時間が長いという問題に出くわしたのは初めてです。クエリが 20 秒以上実行されているため、問題は実際にはかなり大きく、エンドポイント ユーザーにとっては非常に目立ちます。

topics私は(〜8k)の非常に大きなデータベースを持っており、トピックにはパラメーターがあります(これは辞書化されています-8kのトピックには113の異なるパラメーターがあります)。

それらの話題の繰り返し回数についてのレポートを示したいと思います。

topic table:
----------------+---------+-----------------------------------------------------
 id             | integer | nextval('topic_id_seq'::regclass)
 topicengine_id | integer |
 description    | text    |
 topicparam_id  | integer |
 date           | date    |

topicparam table:
----------------+---------+----------------------------------------------------------
 id             | integer | nextval('topicparam_id_seq'::regclass)
 name           | text    |

と私のクエリ:

select distinct tp.id as tpid, tp.name as desc, (select count(*) from topic where topic.topicparam_id = tp.id) as count, t.date
from topicparam tp, topic t where t.topicparam_id =tp.id

Total runtime: 22372.699 ms

結果のフラグメント:

 tpid |                     topicname               | count |    date
------+---------------------------------------------+-------+---------
 3823 | Topic1                                      |     6 | 2014-03-01
 3756 | Topic2                                      |    14 | 2014-03-01
 3803 | Topic3                                      |    28 | 2014-04-01
 3780 | Topic4                                      |  1373 | 2014-02-01

このクエリの実行時間を最適化する方法はありますか?

4

3 に答える 3