[Feature proposal] Batching across a composite index

Hi all! I’m a new (potential) contributor to RoR. Feel free to put me in my place if I am not following protocol / community guidelines!

I have a feature I’d like to add/propose, and have created some pull requests with a working implementation. My company has a use case for which it would be beneficial to be able to process in batches across composite, non-primary indexes. Specifically, we host a database with many terabytes of timeseries data compressed with ZFS. Efficient iteration is important. Although we have a working implementation to process data this way, we lack many of the niceities of a native active record implementation. Therefore, I’ve created pull requests! Perhaps others can benefit from merging this upstream.

The syntax is up for grabs… part of me would like to see syntax like the following, though backwards compatibility / expectations would need to be kept in mind:

Name.in_batches(order: { last_name: :asc, first_name: :desc })

Here are the three current pull requests:

The first PR is ready for review. I’d appreciate feedback before submitting the latter two. Documentation is currently lackluster since community feedback could change a lot.

Thanks in advance for your input!