rendered paste bodyprelude=> SHOW default_statistics_target ; default_statistics_target--------------------------- 300prelude=> EXPLAIN ANALYZE SELECT t0.address, t1.address, COUNT(t2.time), MAX(t2.time) FROM Prelude_Alert AS top_table LEFT JOIN Prelude_Address AS t0 ON (t0._parent_type='S' AND t0._message_ident=top_table._ident AND t0._parent0_index = 0 AND t0._index != -1) LEFT JOIN Prelude_Address AS t1 ON (t1._parent_type='T' AND t1._message_ident=top_table._ident AND t1._parent0_index = 0 AND t1._index != -1) LEFT JOIN Prelude_CreateTime AS t2 ON (t2._parent_type='A' AND t2._message_ident=top_table._ident) WHERE t2.time >= '2007-03-09 10:52:13' AND t2.time < '2007-03-09 11:52:13' GROUP BY 1, 2 ORDER BY 4 DESC LIMIT 50; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=1477730.84..1477730.96 rows=50 width=42) (actual time=273560.989..273561.015 rows=50 loops=1) -> Sort (cost=1477730.84..1477732.35 rows=604 width=42) (actual time=273560.987..273560.998 rows=50 loops=1) Sort Key: max(t2."time") -> HashAggregate (cost=1477693.88..1477702.94 rows=604 width=42) (actual time=273560.583..273560.713 rows=133 loops=1) -> Merge Join (cost=1374841.90..1477676.16 rows=1772 width=42) (actual time=185917.302..273558.368 rows=1556 loops=1) Merge Cond: ("outer"._ident = "inner"._message_ident) -> Merge Left Join (cost=1371650.71..1469556.61 rows=1960612 width=42) (actual time=183416.523..272896.577 rows=1947114 loops=1) Merge Cond: ("outer"._ident = "inner"._message_ident) -> Merge Left Join (cost=682394.59..753756.76 rows=1960612 width=25) (actual time=90345.508..144142.370 rows=1947114 loops=1) Merge Cond: ("outer"._ident = "inner"._message_ident) -> Index Scan using prelude_alert_pkey on prelude_alert top_table (cost=0.00..45385.73 rows=1960612 width=8) (actual time=0.015..21448.606 rows=1947032 loops=1) -> Sort (cost=682394.59..685907.45 rows=1405144 width=25) (actual time=90345.480..120326.794 rows=1943115 loops=1) Sort Key: t0._message_ident -> Bitmap Heap Scan on prelude_address t0 (cost=32113.33..516758.87 rows=1405144 width=25) (actual time=44973.475..78815.998 rows=1953299 loops=1) Recheck Cond: (((_parent_type)::text = 'S'::text) AND (_parent0_index = 0)) Filter: (_index <> -1) -> Bitmap Index Scan on prelude_address_index_address (cost=0.00..32113.33 rows=2654888 width=0) (actual time=44814.655..44814.655 rows=3906516 loops=1) Index Cond: (((_parent_type)::text = 'S'::text) AND (_parent0_index = 0)) -> Sort (cost=689256.12..692863.54 rows=1442967 width=25) (actual time=93070.999..126460.013 rows=1944996 loops=1) Sort Key: t1._message_ident -> Bitmap Heap Scan on prelude_address t1 (cost=32977.11..518873.27 rows=1442967 width=25) (actual time=44788.924..81435.309 rows=1958487 loops=1) Recheck Cond: (((_parent_type)::text = 'T'::text) AND (_parent0_index = 0)) Filter: (_index <> -1) -> Bitmap Index Scan on prelude_address_index_address (cost=0.00..32977.11 rows=2726352 width=0) (actual time=44645.966..44645.966 rows=3916974 loops=1) Index Cond: (((_parent_type)::text = 'T'::text) AND (_parent0_index = 0)) -> Sort (cost=3191.19..3195.75 rows=1821 width=16) (actual time=130.760..131.145 rows=1556 loops=1) Sort Key: t2._message_ident -> Index Scan using prelude_createtime_index on prelude_createtime t2 (cost=0.00..3092.58 rows=1821 width=16) (actual time=91.182..128.873 rows=1556 loops=1) Index Cond: (((_parent_type)::text = 'A'::text) AND ("time" >= '2007-03-09 10:52:13'::timestamp without time zone) AND ("time" < '2007-03-09 11:52:13'::timestamp without time zone)) Total runtime: 273674.921 ms