gokselk opened a new pull request, #13770: URL: https://github.com/apache/datafusion/pull/13770
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> 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? 1. Enhanced `with_reorder()` to preserve valid suffixes from existing orderings when they don't conflict with the new ordering 2. Added filtering of constant expressions from ordering considerations 3. Added `exprs_equal()` helper method to `EquivalenceGroup` for comparing expressions considering equivalence classes 4. Added comprehensive test suite covering: - Constant expression filtering - Suffix preservation - Equivalent expression handling - Incompatible prefix cases - Complex scenarios combining multiple features ## Are these changes tested? Yes, the PR includes extensive test coverage: - `test_with_reorder_constant_filtering`: Tests filtering of constant expressions - `test_with_reorder_preserve_suffix`: Verifies preservation of valid ordering suffixes - `test_with_reorder_equivalent_expressions`: Tests handling of equivalent expressions - `test_with_reorder_incompatible_prefix`: Ensures proper handling of incompatible orderings - `test_with_reorder_comprehensive`: Tests complex interactions between constants, equivalences, and multiple orderings ## Are 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org