Paginate the query to reduce memory usage