QUERY PLAN Sort (cost=553657.66..553662.57 rows=1963 width=218) (actual time=133036.73..133036.75 rows=27 loops=1) Sort Key: medianame, status InitPlan -> Seq Scan on mediatype (cost=0.00..1.29 rows=1 width=8) (actual time=0.12..0.14 rows=1 loops=1) Filter: (medianame = 'Audio'::character varying) -> Index Scan using media_mtype_index on media m (cost=0.00..553550.28 rows=1963 width=218) (actual time=5153.36..133036.00 rows=27 loops=1) Index Cond: (mediatype = $0) Filter: (subplan) SubPlan -> Limit (cost=138.92..138.93 rows=1 width=24) (actual time=2.92..2.92 rows=0 loops=44876) -> Subquery Scan a1 (cost=138.92..138.93 rows=1 width=24) (actual time=2.92..2.92 rows=0 loops=44876) -> Unique (cost=138.92..138.93 rows=1 width=24) (actual time=2.91..2.91 rows=0 loops=44876) -> Sort (cost=138.92..138.93 rows=2 width=24) (actual time=2.91..2.91 rows=0 loops=44876) Sort Key: mediaid -> Append (cost=0.00..138.91 rows=2 width=24) (actual time=2.80..2.81 rows=0 loops=44876) -> Subquery Scan "*SELECT* 1" (cost=0.00..5.11 rows=1 width=8) (actual time=0.06..0.06 rows=0 loops=44876) -> Index Scan using media_pkey on media (cost=0.00..5.11 rows=1 width=8) (actual time=0.05..0.05 rows=0 loops=44876) Index Cond: (objectid = $1) Filter: (activity = 347667::bigint) -> Subquery Scan "*SELECT* 2" (cost=24.25..133.80 rows=1 width=24) (actual time=2.73..2.73 rows=0 loops=44876) -> Hash Join (cost=24.25..133.80 rows=1 width=24) (actual time=2.72..2.72 rows=0 loops=44876) Hash Cond: ("outer"."set" = "inner".objectid) -> Index Scan using intsetmedia_media_index on intsetmedia ism (cost=0.00..109.26 rows=38 width=16) (actual time=0.04..0.04 rows=1 loops=44876) Index Cond: (media = $1) -> Hash (cost=24.24..24.24 rows=6 width=8) (actual time=0.14..0.14 rows=0 loops=44876) -> Index Scan using set_act_index on "set" s (cost=0.00..24.24 rows=6 width=8) (actual time=0.11..0.13 rows=2 loops=44876) Index Cond: (activity = 347667::bigint) Total runtime: 133037.49 msec