Make sure to select at most $batch rows each time