read db in chunks, since millions of result rows can exceed memory