-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Preserve ordering equivalencies on with_reorder
#13770
Preserve ordering equivalencies on with_reorder
#13770
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one comment, looks good after we address it (and add a test)
Is this PR ready to merge? I triggered the CI checks again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, @berkaysynnada feel free to merge after you take a final look
resolved the conflicts, will be merged once CI passes |
Which issue does this PR close?
Closes #13769.
Rationale for this change
The current implementation of
with_reorder
discards all existing ordering information when applying a new ordering. This is overly conservative since in many cases, parts of the existing ordering remain valid and could be preserved. Preserving valid orderings is important for query optimization as it allows the optimizer to avoid unnecessary sorting operations.What changes are included in this PR?
with_reorder()
to preserve valid suffixes from existing orderings when they don't conflict with the new orderingexprs_equal()
helper method toEquivalenceGroup
for comparing expressions considering equivalence classesAre these changes tested?
Yes, the PR includes extensive test coverage:
test_with_reorder_constant_filtering
: Tests filtering of constant expressionstest_with_reorder_preserve_suffix
: Verifies preservation of valid ordering suffixestest_with_reorder_equivalent_expressions
: Tests handling of equivalent expressionstest_with_reorder_incompatible_prefix
: Ensures proper handling of incompatible orderingstest_with_reorder_comprehensive
: Tests complex interactions between constants, equivalences, and multiple orderingsAre there any user-facing changes?
This change is an internal optimization that preserves more ordering information. While there are no direct API changes, users may notice improved query performance in scenarios where ordering information is better preserved through operations that modify sort orders.