Gradually replacing predicates with database queries (a lot faster)