Postgresql计数(*)在大表上非常慢

时间:2014-06-06 05:58:58

标签: count postgresql-9.3

SELECT
T . ID,
T . DATE,
T . TIME,
T .i_want,
T .i_want_date,
T .i_want_date_to,
T . ACTION,
T .country,
T .url,
T .user_agent,
(
    SELECT
        client. NAME
    FROM
        client client
    WHERE
        client. ID = T .client_id
) AS client_name,
(
    SELECT
        segment. NAME
    FROM
        segment segment
    WHERE
        segment. ID = T .segment_id
) AS segment_name
   FROM
analytics_visitors T 
   WHERE
(1 = 1)
   AND (T .site_id = 3)

当我将其用于分页目的时,如

SELECT "count"(*) FROM analytics_visitors T WHERE (1 = 1) AND (T .site_id = 3)

它太慢了,请给出任何解决方案我如何优化它甚至更改我的主查询,我的postgresql是版本9.3,它包含20000000+行并且它也被编入索引。

0 个答案:

没有答案