Github user JamesRTaylor commented on a diff in the pull request: https://github.com/apache/phoenix/pull/314#discussion_r205982004 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java --- @@ -559,8 +559,16 @@ protected QueryPlan compileSingleFlatQuery(StatementContext context, SelectState groupBy = groupBy.compile(context, innerPlanTupleProjector); context.setResolver(resolver); // recover resolver RowProjector projector = ProjectionCompiler.compile(context, select, groupBy, asSubquery ? Collections.<PDatum>emptyList() : targetColumns, where); - OrderBy orderBy = OrderByCompiler.compile(context, select, groupBy, limit, offset, projector, - groupBy == GroupBy.EMPTY_GROUP_BY ? innerPlanTupleProjector : null, isInRowKeyOrder); + OrderBy orderBy = OrderByCompiler.compile( + context, + select, + groupBy, + limit, + offset, + projector, + groupBy == GroupBy.EMPTY_GROUP_BY ? innerPlanTupleProjector : null, + groupBy == GroupBy.EMPTY_GROUP_BY ? isInRowKeyOrder : true, + where); --- End diff -- Would be ideal if the change could be isolated to OrderByCompiler being aware of its inner plan to determine correctly whether the OrderBy can be compiled out. Any ideas, @maryannxue?
---