Given a table
for following sql :
Intuitively, the above OrderBy statement order by a.ak3,a.av1 should be compiled out because it match the group by statement, but in fact it is not.
The problem is caused by the QueryCompiler.compileSingleQuery and QueryCompiler.compileSingleFlatQuery,for QueryCompiler.compileSingleQuery method,because the inner query has order by, so in line 520, local variable isInRowKeyOrder is false:
In QueryCompiler.compileSingleFlatQuery,when OrderByCompiler.compile method is invoked, the last parameter isInRowKeyOrder is false:
So in following line 156 for OrderByCompiler.compile,even though the tracker.isOrderPreserving is true, the OrderBy statement could not be compiled out.
In my opinion, with GroupBy, in following line 563 for QueryCompiler.compileSingleFlatQuery method, when we call
OrderByCompiler.compile method, we no need to conside the isInRowKeyOrder, just like the previous parameter tupleProjector does.