QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Unique (cost=860732.31..860761.51 rows=2336 width=22) (actual time=221.113..221.472 rows=577 loops=1) -> Sort (cost=860732.31..860738.15 rows=2336 width=22) (actual time=221.110..221.220 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=856660.40..860601.61 rows=2336 width=22) (actual time=169.164..220.490 rows=577 loops=1) Hash Cond: (ms.vslid = vsl.id) -> Hash Join (cost=856620.20..860526.95 rows=2958 width=26) (actual time=168.871..219.793 rows=577 loops=1) Hash Cond: (ms.marinerid = m.id) -> Seq Scan on marinerstates ms (cost=0.00..3793.75 rows=6067 width=8) (actual time=0.012..48.267 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=856509.66..856509.66 rows=8843 width=22) (actual time=168.810..168.810 rows=14518 loops=1) -> Index Scan using mariner_pkey on mariner m (cost=854253.06..856509.66 rows=8843 width=22) (actual time=144.906..162.369 rows=14518 loops=1) Filter: ((NOT (hashed subplan)) AND ((marinertype)::text = 'Mariner'::text)) SubPlan -> Unique (cost=0.00..854247.22 rows=2336 width=4) (actual time=0.079..143.656 rows=1448 loops=1) -> Merge Join (cost=0.00..854241.38 rows=2336 width=4) (actual time=0.078..142.634 rows=1824 loops=1) Merge Cond: (msold.marinerid = mold.id) -> Nested Loop (cost=0.00..851962.29 rows=2396 width=4) (actual time=0.065..122.789 rows=1888 loops=1) -> Index Scan using marinerstates_marinerid on marinerstates msold (cost=0.00..850980.53 rows=3034 width=8) (actual time=0.059..116.367 rows=1888 loops=1) Filter: (((state)::text = 'Active'::text) AND ((starttime)::date <= '2007-01-11'::date) AND ((COALESCE(endtime, now()))::date >= '2006-07-15'::date) AND (subplan)) SubPlan -> Bitmap Heap Scan on marinerstates msold2 (cost=4.28..12.14 rows=1 width=0) (actual time=0.007..0.007 rows=1 loops=2630) Recheck Cond: ((marinerid = $0) AND (starttime < $2)) Filter: ((id <> $1) AND ((state)::text = 'Active'::text) AND (($2 - endtime) <= '1 year 6 mons'::interval)) -> Bitmap Index Scan on marinerstates_marinerid_starttime (cost=0.00..4.28 rows=2 width=0) (actual time=0.004..0.004 rows=6 loops=2630) Index Cond: ((marinerid = $0) AND (starttime < $2)) -> Index Scan using vessels_pkey on vessels vslold (cost=0.00..0.31 rows=1 width=4) (actual time=0.002..0.002 rows=1 loops=1888) Index Cond: (vslold.id = msold.vslid) -> Index Scan using mariner_pkey on mariner mold (cost=0.00..2211.26 rows=17687 width=4) (actual time=0.007..15.142 rows=14619 loops=1) Filter: ((mold.marinertype)::text = 'Mariner'::text) -> Hash (cost=35.09..35.09 rows=409 width=4) (actual time=0.284..0.284 rows=288 loops=1) -> Seq Scan on vessels vsl (cost=0.00..35.09 rows=409 width=4) (actual time=0.012..0.173 rows=288 loops=1) Total runtime: 221.846 ms (33 rows)