QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Unique (cost=13987.87..14042.86 rows=4399 width=23) (actual time=93406.457..93409.135 rows=577 loops=1) -> Sort (cost=13987.87..13998.87 rows=4399 width=23) (actual time=93406.452..93407.334 rows=577 loops=1) Sort Key: m.surname, (COALESCE(m.givenname, ''::character varying)), (COALESCE(m.midname, ''::character varying)), m.id Sort Method: quicksort Memory: 69kB -> Hash Join (cost=9977.51..13721.67 rows=4399 width=23) (actual time=93347.321..93404.790 rows=577 loops=1) Hash Cond: (ms.marinerid = m.id) -> Hash Join (cost=26.46..3671.64 rows=4399 width=4) (actual time=1.040..52.180 rows=2630 loops=1) Hash Cond: (ms.vslid = vsl.id) -> Seq Scan on marinerstates ms (cost=0.00..3579.82 rows=5698 width=8) (actual time=0.012..42.739 rows=2630 loops=1) Filter: (((state)::text = 'Active'::text) AND ((starttime)::date <= '2007-01-11'::date) AND ((COALESCE(endtime, now()))::date >= '2006-07-15'::date)) -> Hash (cost=22.87..22.87 rows=287 width=4) (actual time=1.014..1.014 rows=287 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 11kB -> Seq Scan on vessels vsl (cost=0.00..22.87 rows=287 width=4) (actual time=0.003..0.539 rows=287 loops=1) -> Hash (cost=9851.59..9851.59 rows=7957 width=23) (actual time=93346.204..93346.204 rows=14466 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 790kB -> Seq Scan on mariner m (cost=9185.74..9851.59 rows=7957 width=23) (actual time=93288.927..93321.136 rows=14466 loops=1) Filter: ((NOT (hashed SubPlan 1)) AND ((marinertype)::text = 'Mariner'::text)) SubPlan 1 -> Unique (cost=3390.49..9185.74 rows=1 width=4) (actual time=279.920..93285.790 rows=1448 loops=1) -> Nested Loop (cost=3390.49..9185.73 rows=1 width=4) (actual time=279.916..93280.499 rows=1824 loops=1) Join Filter: (msold.marinerid = mold.id) -> Index Scan using mariner_pkey on mariner mold (cost=0.00..1957.89 rows=15914 width=4) (actual time=0.009..38.449 rows=15914 loops=1) Filter: ((marinertype)::text = 'Mariner'::text) -> Materialize (cost=3390.49..6989.13 rows=1 width=8) (actual time=0.013..2.881 rows=1888 loops=15914) -> Nested Loop (cost=3390.49..6989.13 rows=1 width=8) (actual time=189.468..267.483 rows=1888 loops=1) -> Hash Semi Join (cost=3390.49..6988.83 rows=1 width=12) (actual time=189.452..248.136 rows=1888 loops=1) Hash Cond: (msold.marinerid = msold2.marinerid) Join Filter: ((msold2.id <> msold.id) AND (msold2.starttime < msold.starttime) AND ((msold.starttime - msold2.endtime) <= '1 year 6 mons'::interval)) -> Seq Scan on marinerstates msold (cost=0.00..3579.82 rows=5698 width=20) (actual time=0.004..42.507 rows=2630 loops=1) Filter: (((state)::text = 'Active'::text) AND ((starttime)::date <= '2007-01-11'::date) AND ((COALESCE(endtime, now()))::date >= '2006-07-15'::date)) -> Hash (cost=2749.41..2749.41 rows=51286 width=24) (actual time=189.351..189.351 rows=51391 loops=1) Buckets: 8192 Batches: 1 Memory Usage: 2798kB -> Seq Scan on marinerstates msold2 (cost=0.00..2749.41 rows=51286 width=24) (actual time=0.003..102.133 rows=51391 loops=1) Filter: ((state)::text = 'Active'::text) -> Index Scan using vessels_pkey on vessels vslold (cost=0.00..0.28 rows=1 width=4) (actual time=0.002..0.004 rows=1 loops=1888) Index Cond: (vslold.id = msold.vslid) Total runtime: 93410.498 ms (37 rows)