Still the fourth component giving grief: SELECT BugTask.assignee, BugTask.bug, BugTask.bugwatch, BugTask.date_assigned, BugTask.date_closed, BugTask.date_confirmed, BugTask.date_fix_committed, BugTask.date_fix_released, BugTask.date_incomplete, BugTask.date_inprogress, BugTask.date_left_closed, BugTask.date_left_new, BugTask.date_triaged, BugTask.datecreated, BugTask.distribution, BugTask.distroseries, BugTask.id, BugTask.importance, BugTask.milestone, BugTask.OWNER, BugTask.product, BugTask.productseries, BugTask.sourcepackagename, BugTask.status, BugTask.statusexplanation, BugTask.targetnamecache FROM BugTask LEFT JOIN Product ON BugTask.product = Product.id AND Product.active, Bug WHERE Bug.id = BugTask.bug AND ((BugTask.status = 10) OR (BugTask.status = 15) OR (BugTask.status = 20) OR (BugTask.status = 21) OR (BugTask.status = 22) OR (BugTask.status = 25)) AND Bug.duplicateof IS NULL AND (Bugtask.product IS NULL OR Product.active = TRUE) AND BugTask.id IN (SELECT DISTINCT BugTask.id FROM BugTask, BugMessage, Message WHERE Message.OWNER = 100 AND Message.id = BugMessage.message AND BugTask.bug = BugMessage.bug AND BugMessage.INDEX > 0) AND Bug.private = FALSE; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Nested Loop (cost=305503.56..378400.41 rows=182 width=276) (actual time=5005.584..5307.435 rows=2032 loops=1) -> Nested Loop Left Join (cost=305503.56..378026.51 rows=182 width=276) (actual time=5005.239..5286.484 rows=2722 loops=1) Filter: ((public.bugtask.product IS NULL) OR product.active) -> Hash Semi Join (cost=305503.56..377964.46 rows=200 width=276) (actual time=5005.231..5279.653 rows=2728 loops=1) Hash Cond: (public.bugtask.id = public.bugtask.id) -> Bitmap Heap Scan on bugtask (cost=8513.27..80064.62 rows=276215 width=276) (actual time=117.865..262.118 rows=308733 loops=1) Recheck Cond: ((status = 10) OR (status = 15) OR (status = 20) OR (status = 21) OR (status = 22) OR (status = 25)) -> BitmapOr (cost=8513.27..8513.27 rows=308734 width=0) (actual time=96.118..96.118 rows=0 loops=1) -> Bitmap Index Scan on bugtask__status__idx (cost=0.00..4829.87 rows=184328 width=0) (actual time=58.207..58.207 rows=184491 loops=1) Index Cond: (status = 10) -> Bitmap Index Scan on bugtask__status__idx (cost=0.00..466.01 rows=17680 width=0) (actual time=6.039..6.039 rows=17642 loops=1) Index Cond: (status = 15) -> Bitmap Index Scan on bugtask__status__idx (cost=0.00..1479.89 rows=56464 width=0) (actual time=16.298..16.298 rows=56538 loops=1) Index Cond: (status = 20) -> Bitmap Index Scan on bugtask__status__idx (cost=0.00..794.52 rows=30282 width=0) (actual time=9.207..9.207 rows=30304 loops=1) Index Cond: (status = 21) -> Bitmap Index Scan on bugtask__status__idx (cost=0.00..142.56 rows=5354 width=0) (actual time=1.767..1.767 rows=5351 loops=1) Index Cond: (status = 22) -> Bitmap Index Scan on bugtask__status__idx (cost=0.00..386.11 rows=14627 width=0) (actual time=4.592..4.592 rows=14653 loops=1) Index Cond: (status = 25) -> Hash (cost=295746.16..295746.16 rows=99531 width=4) (actual time=4886.657..4886.657 rows=29835 loops=1) -> HashAggregate (cost=293755.54..294750.85 rows=99531 width=4) (actual time=4865.202..4876.609 rows=29835 loops=1) -> Nested Loop (cost=142973.14..293506.71 rows=99531 width=4) (actual time=131.203..4804.818 rows=84427 loops=1) -> Hash Join (cost=142973.14..256158.69 rows=75294 width=4) (actual time=131.176..4500.855 rows=32134 loops=1) Hash Cond: (bugmessage.message = message.id) -> Seq Scan on bugmessage (cost=0.00..70798.85 rows=3027910 width=8) (actual time=0.028..1278.061 rows=3026226 loops=1) Filter: (index > 0) -> Hash (cost=142031.96..142031.96 rows=75294 width=4) (actual time=131.071..131.071 rows=75175 loops=1) -> Bitmap Heap Scan on message (cost=1205.51..142031.96 rows=75294 width=4) (actual time=35.400..101.930 rows=75175 loops=1) Recheck Cond: (owner = 100) -> Bitmap Index Scan on message_owner_idx (cost=0.00..1186.69 rows=75294 width=0) (actual time=26.443..26.443 rows=75175 loops=1) Index Cond: (owner = 100) -> Index Scan using bugtask__bug__idx on bugtask (cost=0.00..0.48 rows=1 width=8) (actual time=0.006..0.008 rows=3 loops=32134) Index Cond: (public.bugtask.bug = bugmessage.bug) -> Index Scan using product_pkey on product (cost=0.00..0.30 rows=1 width=5) (actual time=0.001..0.002 rows=0 loops=2728) Index Cond: (public.bugtask.product = product.id) Filter: product.active -> Index Scan using bug_pkey on bug (cost=0.00..2.04 rows=1 width=4) (actual time=0.007..0.007 rows=1 loops=2722) Index Cond: (bug.id = public.bugtask.bug) Filter: ((bug.duplicateof IS NULL) AND (NOT bug.private)) Total runtime: 5308.785 ms