minor optimization for Query.count method