Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse and incremental index sorting optimizations #4041

Merged
merged 2 commits into from Apr 16, 2024

Conversation

katzyn
Copy link
Contributor

@katzyn katzyn commented Apr 14, 2024

  1. Indexes can now be scanned in reverse order. With these changes both ascending and descending indexes on the same column aren't needed any more for index sorting optimization, only one index is enough. Closes An available index is never used for ordering, when the requested order is DESC #701. Some limitations still exist. For nullable columns ASC NULLS FIRST index can be used for ASC NULLS FIRST and DESC NULLS LAST, but it cannot be used for ASC NULLS LAST or DESC NULLS FIRST. A multi-column index can be used for the same multi-column ORDER BY only 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.
  2. Index that covers only first one or few columns from the ORDER BY clause now may still be used for sorting with an index. It is important for queries with the FETCH clause, 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 for WITH TIES clause.
  3. An old bug with ORDER BY _ROWID_ DESC is fixed, now it really returns rows in descending order.

@katzyn katzyn merged commit 0f29221 into h2database:master Apr 16, 2024
2 checks passed
@katzyn katzyn deleted the index branch April 16, 2024 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

An available index is never used for ordering, when the requested order is DESC
1 participant