Make subquery filtering fast