feat(utils): Support multiple order_by columns in RangeQuerySetWrapper #101507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to allow
ORDER BYwhile usingRangeQuerySetWrapper. This allows to iterate more efficiently when filtering large datasets with existing indexes.We still require a unique column at the very end to ensure consistent iteration, usually the PK. We also do support
min_valueandresult_value_getterbut only on the unique column.This uses tuple comparison to create a concise filter for the cursor queries, which also works if it includes nullable columns. Since Django I could not find native support for tuples in Django ORM, this uses a workaround with a custom
Tupletype based onFuncto reuse as much serialization logic as possible, along with a manualLookupexpression to render the comparison. This creates queries like this:The alternative would be unrolling the tuple comparsion. However, I've read that this often leads to suboptimal use of existing indexes in postgres. Apart from that, it would create rather large expressions that grow with the number of fields:
Ref FS-105