You can't fetch more than 50 million records because there is a platform governor limit. If you have more than 50 million I think it'll throw a limit exception. The workaround around would be to specify a filter condition that allows you to query it in the multiple batches. So it'd would look something like this.
String query1 = 'select id from account where recordCount__c <= :5000000'; String query2 = 'select id from account where recordCount__c > :500000' and <= :1000000';
then use query1 and query2 with queryLocator. Note that recordCount__c is a custom field that you can auto-populate using a trigger or workflow.
String query1 = 'select id from account where recordCount__c <= :5000000';
String query2 = 'select id from account where recordCount__c > :500000' and <= :1000000';
then use query1 and query2 with queryLocator. Note that recordCount__c is a custom field that you can auto-populate using a trigger or workflow.
Regards,
Anup