Fixes #2409: Added support for fetching data from database in batches