Reverse and incremental index sorting optimizations #4041
Merged
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.
ASC NULLS FIRSTindex can be used forASC NULLS FIRSTandDESC NULLS LAST, but it cannot be used forASC NULLS LASTorDESC NULLS FIRST. A multi-column index can be used for the same multi-columnORDER BYonly if all column are specified with the same order as in the index, or all columns are specified in reverse order. Due to (2) some indexes where not all columns have the same order can still be used.ORDER BYclause now may still be used for sorting with an index. It is important for queries with theFETCHclause, because such queries can stop their execution earlier. We need to read additional rows only until a change in the matched indexed columns, all remaining rows aren't needed. This is similar to existing optimization forWITH TIESclause.ORDER BY _ROWID_ DESCis fixed, now it really returns rows in descending order.