this seems to perform tolerably to also filter on product active SELECT DISTINCT ON (BugTask.id) BugTask.*
FROM BugTask left join product on (bugtask.product = product.id and product.active), Bug, BugMessage, Message
WHERE
Bug.id = BugTask.bug
AND Bug.id = BugMessage.bug
AND BugMessage.message = Message.id
AND BugTask.status in (10, 15, 20, 21, 22, 25)
AND Bug.duplicateof IS NULL
AND Bug.private = FALSE
AND BugMessage.index > 0
AND Message.owner = 931129
and (bugtask.product is null or product.active)
ORDER BY BugTask.id;
this seems to perform tolerably to also filter on product active SELECT DISTINCT ON (BugTask.id) BugTask.*
FROM BugTask left join product on (bugtask.product = product.id and product.active), Bug, BugMessage, Message
WHERE
Bug.id = BugTask.bug
AND Bug.id = BugMessage.bug
AND BugMessage.message = Message.id
AND BugTask.status in (10, 15, 20, 21, 22, 25)
AND Bug.duplicateof IS NULL
AND Bug.private = FALSE
AND BugMessage.index > 0
AND Message.owner = 931129
and (bugtask.product is null or product.active)
ORDER BY BugTask.id;