The question might sound a bit general. Still. We have a table with hundreds of millions of records. To make the report, several other smaller tables are being joined with it. Indexes are created for all appropriate columns. The client wants to get a report for a year+, that might be up to 100mil rows.
In order to secure the process, say if the script dies, or if the connection to the DB drops, the report must be extracted in chunks, so the next process picks up the report where the previous died.
The problem is that the report can be sorted by varchar/int columns, which can contain client names, account numbers, various personal data in different formats etc etc, and i haven't sorted out how to get a reasonable amount of rows for each chunk (say ~50k) in these cases.
Using limit x,y will take way too long with this amount of data. There are no archived tables, no partitioning, data is not aggregated to separate tables. Just a huge chunk of data in one table.
Is there an established (magic?) way to deal with this kind of problem?