gokselk opened a new issue, #13769: URL: https://github.com/apache/datafusion/issues/13769
### Is your feature request related to a problem or challenge? When applying new orderings via `with_reorder()`, the current implementation discards all existing ordering information and replaces it with the new ordering. This is suboptimal because in many cases, parts of the existing ordering remain valid and could be preserved. For example, if we have data ordered by `[a ASC, b DESC]` and apply a new ordering `[a ASC]`, we currently lose the information that the data is also ordered by `b DESC`, even though this ordering is still valid and could be valuable for query optimization. This overly conservative approach can lead to unnecessary sorting operations in query execution, impacting query performance. ### Describe the solution you'd like Enhance `with_reorder()` to preserve valid ordering information by: 1. Filtering out constant expressions from ordering considerations (they don't affect physical ordering) 2. Preserving valid suffixes from existing orderings when they're compatible with the new ordering 3. Considering expression equivalences when comparing orderings For example: - When applying `[a ASC]` to existing `[a ASC, b DESC]`, preserve `b DESC` - When columns `a` and `b` are equivalent and applying `[b ASC]` to existing `[a ASC, c DESC]`, preserve `c DESC` - When column `a` is constant, applying `[a ASC, b ASC]` should only consider `[b ASC]` ### Describe alternatives you've considered Only preserve exact matching prefixes without considering equivalences ### Additional context This optimization is particularly important for complex queries with multiple ordering requirements and transformations, where maintaining ordering information can significantly reduce the number of required sort operations. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
