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

fix order by optimization #2251

Merged
merged 5 commits into from
Jan 11, 2024
Merged

fix order by optimization #2251

merged 5 commits into from
Jan 11, 2024

Conversation

jycor
Copy link
Contributor

@jycor jycor commented Jan 10, 2024

This hopefully fixes 24 sqllogictests.

We introduced an optimization where we would drop Sort nodes for queries that included ORDER BYs if there were IndexLookups that were a matching prefix over the sortfields. The idea was that since indexes are already in order there was no need to sort.

However, there is a case when that isn't necessarily true. If the index is created from a filter over multiple columns, specifically when that filter contains an OR expression, it is possible to iterate over columns in a non-sorted order. During analysis, the filters are converted into several non-overlapping ranges; it is possible for a range expression in the range to overlap with another range's range expression, but for the two ranges to not overlap. It's clearer to look at the test.

We didn't catch this bug earlier, as it only affects queries in dolt. We iterate over rows in the in-memory tables in such a way that the rows will still appear in order.

Copy link
Contributor

@max-hoffman max-hoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just the one comment

sql/analyzer/replace_sort.go Outdated Show resolved Hide resolved
@jycor jycor merged commit 70f6fac into main Jan 11, 2024
7 checks passed
@jycor jycor deleted the james/order branch January 11, 2024 00:12
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.

None yet

2 participants