Remove redundant ORDER BY from subqueries

Proprietary

An ORDER BY inside a subquery or CTE without a LIMIT, OFFSET, or FETCH does not affect the rows the outer query returns, so the database either discards the sort or pays for ordering that nothing observes. Remove the clause, leaving the rest of the statement untouched. Sort in the outermost query if a specific order is required.

org.openrewrite.sql.antipattern.RemoveOrderByInSubquery

Optional

markSourceBoolean

Whether to mark each occurrence in source, and apply the fix where the rule remediates. Defaults to true; set to false to leave source untouched and report only to the data table, as an analysis-only pipeline requires.

mod run . --recipe=org.openrewrite.sql.antipattern.RemoveOrderByInSubquery

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.