v.23.1Improvement

Remove Redundant Sorting in Subqueries

Remove redundant sorting, for example, sorting related ORDER BY clauses in subqueries. Implemented on top of query plan. It does similar optimization as optimize_duplicate_order_by_and_distinct regarding ORDER BY clauses, but more generic, since it's applied to any redundant sorting steps (not only caused by ORDER BY clause) and applied to subqueries of any depth. Related to #42648. #43905 (Igor Nikonov).
Remove redundant sorting operations in query plans, including sorting ORDER BY clauses within subqueries, to optimize query execution.

Why it matters

This feature eliminates unnecessary sorting steps that can occur in subqueries or other parts of a query plan. By removing redundant sorting, it improves query performance and reduces resource consumption. It generalizes the optimization performed by optimize_duplicate_order_by_and_distinct and applies it to sorting redundancies at any depth in subqueries.

How to use it

This optimization is implemented at the query plan level and is applied automatically by ClickHouse during query execution. Users do not need to enable it manually.