optimised query count