After column rename projection, the ProjectExec's outputOrdering and outputPartitioning should reflect the projected columns as well. For example,
The inner query is ordered on a1 as well. If we had a rule to eliminate Sort on sorted result, together with this fix, the order-by in the outer query could have been optimized out.
Similarly, the below query
is equivalent to
, so the unnecessary sorting and hash-partitioning that have been optimized out for the second query should have be eliminated in the first query as well.