ModeShape/modeshape — pull request #505 by rhauch (2012-09-01 13:24:00+00:00)
Title: MODE-1095 Fix support for ORDER BY using a column that isn't in the SELECT

The query framework was changed to ensure all columns used in the ORDER BY clauses are automatically included in the results. Because the query processing engine requires the columns to be in the (intermediate/internal) results, including the columns in the user's result set does not make the query system less efficient. (In fact, changing the result set to contain/expose only those columns included in the SELECT clause would actually require additional resources and could be potentially less efficient.)

This change implements the functionality by adding a new optimizer rule that rewrites part of the query plan. In particular, the new rule looks for SORT query plan nodes, processes the Ordering instances to extract the property references, and adds corresponding columns to all the appropriate PROJECT nodes that are below the SORT node.

This change altered the query plans for queries with orderings, so the expected results needed to be changed in several test cases.