All pastes #625082 Raw Edit

Something

public sql v1 · immutable
·published 2007-07-18 19:04 UTC
rendered paste body
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 50explain analyze output:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit  (cost=1771864.90..1771864.94 rows=16 width=42) (actual time=231233.299..231233.338 rows=50 loops=1)   ->  Sort  (cost=1771864.90..1771864.94 rows=16 width=42) (actual time=231233.297..231233.315 rows=50 loops=1)         Sort Key: max(t2."time")         ->  HashAggregate  (cost=1771864.34..1771864.58 rows=16 width=42) (actual time=231232.670..231232.853 rows=133 loops=1)               ->  Merge Join  (cost=1668080.32..1771845.15 rows=1919 width=42) (actual time=143418.179..231230.540 rows=1556 loops=1)                     Merge Cond: ("outer"._ident = "inner"._message_ident)                     ->  Merge Left Join  (cost=1664600.77..1763435.02 rows=1960612 width=42) (actual time=140815.174..230531.083 rows=1947114 loops=1)                           Merge Cond: ("outer"._ident = "inner"._message_ident)                           ->  Merge Left Join  (cost=830777.20..902806.18 rows=1960612 width=25) (actual time=71583.365..127267.700 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=11.919..20127.718 rows=1947032 loops=1)                                 ->  Sort  (cost=830777.20..834400.82 rows=1449448 width=25) (actual time=71571.434..104661.819 rows=1943115 loops=1)                                       Sort Key: t0._message_ident                                       ->  Bitmap Heap Scan on prelude_address t0  (cost=32246.36..517087.41 rows=1449448 width=25) (actual time=25295.354..61881.225 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..32246.36 rows=2666060 width=0) (actual time=25265.752..25265.752 rows=3906516 loops=1)                                                   Index Cond: (((_parent_type)::text = 'S'::text) AND (_parent0_index = 0))                           ->  Sort  (cost=833823.57..837474.20 rows=1460249 width=25) (actual time=69231.799..101040.433 rows=1944996 loops=1)                                 Sort Key: t1._message_ident                                 ->  Bitmap Heap Scan on prelude_address t1  (cost=32486.56..517675.26 rows=1460249 width=25) (actual time=21513.229..59289.124 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..32486.56 rows=2685926 width=0) (actual time=21466.907..21466.907 rows=3916974 loops=1)                                             Index Cond: (((_parent_type)::text = 'T'::text) AND (_parent0_index = 0))                     ->  Sort  (cost=3479.56..3484.49 rows=1972 width=16) (actual time=126.249..126.599 rows=1556 loops=1)                           Sort Key: t2._message_ident                           ->  Index Scan using prelude_createtime_index on prelude_createtime t2  (cost=0.00..3371.63 rows=1972 width=16) (actual time=85.597..123.163 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: 231399.145 ms