This is the optimizer rule that is run after query parsing and planning, but before query execution (when the processor objects are created). This looks for SORT plan nodes to ensure that the sort columns are included in the descendant PROJECT plan nodes. However, to prevent the sort columns from being visible to the rest of the query, it is wrapped with another PROJECT plan node that excludes the recently-added sort columns.

Given the following query:

    SELECT y.* FROM [nt:unstructured] AS x INNER JOIN [nt:unstructured] AS y ON x.somethingElse = y.propC ORDER BY x.propC

the resulting query plan will now be:

    Project [y] <PROJECT_COLUMNS=[y.[jcr:primaryType] AS [y.jcr:primaryType], y.[jcr:mixinTypes] AS [y.jcr:mixinTypes], y.[jcr:path] AS [y.jcr:path], y.[jcr:name] AS [y.jcr:name], y.[jcr:score] AS [y.jcr:score], y.[mode:localName] AS [y.mode:localName], y.[mode:depth] AS [y.mode:depth]], PROJECT_COLUMN_TYPES=[STRING, STRING, STRING, STRING, DOUBLE, STRING, LONG]>
          Sort [x] <SORT_ORDER_BY=[x.propC ASC]>
            Project [y] <PROJECT_COLUMNS=[y.[jcr:primaryType] AS [y.jcr:primaryType], y.[jcr:mixinTypes] AS [y.jcr:mixinTypes], y.[jcr:path] AS [y.jcr:path], y.[jcr:name] AS [y.jcr:name], y.[jcr:score] AS [y.jcr:score], y.[mode:localName] AS [y.mode:localName], y.[mode:depth] AS [y.mode:depth], x.propC AS [x.propC]], PROJECT_COLUMN_TYPES=[STRING, STRING, STRING, STRING, DOUBLE, STRING, LONG, STRING]>
              Join [y,x] <JOIN_TYPE=INNER JOIN, JOIN_CONDITION=x.somethingElse = y.propC, JOIN_ALGORITHM=NESTED_LOOP>
                Access [x]
                  Project [x] <PROJECT_COLUMNS=[x.[jcr:primaryType], x.[jcr:mixinTypes], x.[jcr:path], x.[jcr:name], x.[jcr:score], x.[mode:localName], x.[mode:depth], x.somethingElse, x.propC AS [x.propC]], PROJECT_COLUMN_TYPES=[STRING, STRING, STRING, STRING, DOUBLE, STRING, LONG, STRING, STRING]>
                    Select [x] <SELECT_CRITERIA=x.[jcr:primaryType] IN ('fincayra.UnstrUser','car:Car','fincayra.UnstrPost','nt:unstructured','notion:typed')>
                      Source [x] <SOURCE_COLUMNS=[jcr:frozenUuid(STRING), mode:sharedUuid(REFERENCE), mode:sessionScope(BOOLEAN), car:msrp(STRING), fieldA(STRING), jcr:defaultValues(STRING), mode:projectedNodeKey(STRING), jcr:frozenPrimaryType(STRING), jcr:mixinTypes(STRING), jcr:defaultPrimaryType(STRING), car:wheelbaseInInches(DOUBLE), text(STRING), notion:booleanAutoCreatedPropertyWithDefault(BOOLEAN), car:model(STRING), jcr:statement(STRING), jcr:lastModifiedBy(STRING), jcr:mimeType(STRING), jcr:hasOrderableChildNodes(BOOLEAN), jcr:etag(STRING), jcr:encoding(STRING), jcr:root(REFERENCE), jcr:supertypes(STRING), car:alternateModels(REFERENCE), jcr:successors(REFERENCE), name(STRING), jcr:primaryItemName(STRING), jcr:hold(STRING), jcr:workspace(STRING), jcr:description(STRING), jcr:primaryType(STRING), mode:initializationState(STRING), fieldB(STRING), mode:externalNodeKey(STRING), notion:booleanProperty(BOOLEAN), mode:derivedFrom(STRING), mode:isHeldBySession(BOOLEAN), jcr:baseVersion(REFERENCE), jcr:lastModified(DATE), jcr:mergeFailed(REFERENCE), jcr:requiredPrimaryTypes(STRING), mode:derivedAt(DATE), jcr:multiple(BOOLEAN), mode:generated(BOOLEAN), jcr:activityTitle(STRING), jcr:lifecyclePolicy(REFERENCE), jcr:isMixin(BOOLEAN), notion:multipleReferences(REFERENCE), jcr:availableQueryOperators(STRING), jcr:childVersionHistory(REFERENCE), car:userRating(LONG), user(STRING), jcr:autoCreated(BOOLEAN), jcr:content(REFERENCE), car:mpgHighway(LONG), mode:alias(STRING), notion:booleanProperty2(BOOLEAN), jcr:createdBy(STRING), jcr:isFullTextSearchable(BOOLEAN), jcr:uuid(STRING), jcr:onParentVersion(STRING), notion:longProperty(LONG), mode:expirationDate(DATE), jcr:lockIsDeep(BOOLEAN), notion:stringProperty(STRING), jcr:isDeep(BOOLEAN), jcr:copiedFrom(REFERENCE), car:engine(STRING), jcr:title(STRING), notion:stringAutoCreatedPropertyWithDefault(STRING), notion:stringPropertyWithDefault(STRING), jcr:isAbstract(BOOLEAN), jcr:versionHistory(REFERENCE), jcr:versionableUuid(STRING), jcr:predecessors(REFERENCE), car:maker(STRING), jcr:lockOwner(STRING), car:mpgCity(LONG), mode:sha1(STRING), jcr:repository(STRING), jcr:created(DATE), jcr:frozenMixinTypes(STRING), car:lengthInInches(DOUBLE), mode:lockedKey(STRING), jcr:text(STRING), jcr:host(STRING), jcr:configuration(REFERENCE), jcr:port(STRING), mode:workspace(STRING), notion:singleReference(REFERENCE), car:valueRating(LONG), jcr:nodeTypeName(STRING), email(STRING), jcr:isQueryable(BOOLEAN), jcr:data(BINARY), jcr:language(STRING), jcr:isQueryOrderable(BOOLEAN), jcr:isCheckedOut(BOOLEAN), jcr:mandatory(BOOLEAN), jcr:protected(BOOLEAN), jcr:protocol(STRING), jcr:sameNameSiblings(BOOLEAN), jcr:requiredType(STRING), mode:lockingSession(STRING), notion:booleanCreatedPropertyWithDefault(BOOLEAN), jcr:messageId(STRING), jcr:id(REFERENCE), mode:uri(STRING), jcr:valueConstraints(STRING), car:year(STRING), jcr:retentionPolicy(REFERENCE), jcr:activity(REFERENCE), jcr:currentLifecycleState(STRING), jcr:path(STRING), jcr:name(STRING), jcr:score(DOUBLE), mode:localName(STRING), mode:depth(LONG)], SOURCE_ALIAS=x, SOURCE_NAME=__ALLNODES__>
                Access [y]
                  Project [y] <PROJECT_COLUMNS=[y.[jcr:primaryType], y.[jcr:mixinTypes], y.[jcr:path], y.[jcr:name], y.[jcr:score], y.[mode:localName], y.[mode:depth], y.propC], PROJECT_COLUMN_TYPES=[STRING, STRING, STRING, STRING, DOUBLE, STRING, LONG, STRING]>
                    Select [y] <SELECT_CRITERIA=y.[jcr:primaryType] IN ('fincayra.UnstrUser','car:Car','fincayra.UnstrPost','nt:unstructured','notion:typed')>
                      Source [y] <SOURCE_COLUMNS=[jcr:frozenUuid(STRING), mode:sharedUuid(REFERENCE), mode:sessionScope(BOOLEAN), car:msrp(STRING), fieldA(STRING), jcr:defaultValues(STRING), mode:projectedNodeKey(STRING), jcr:frozenPrimaryType(STRING), jcr:mixinTypes(STRING), jcr:defaultPrimaryType(STRING), car:wheelbaseInInches(DOUBLE), text(STRING), notion:booleanAutoCreatedPropertyWithDefault(BOOLEAN), car:model(STRING), jcr:statement(STRING), jcr:lastModifiedBy(STRING), jcr:mimeType(STRING), jcr:hasOrderableChildNodes(BOOLEAN), jcr:etag(STRING), jcr:encoding(STRING), jcr:root(REFERENCE), jcr:supertypes(STRING), car:alternateModels(REFERENCE), jcr:successors(REFERENCE), name(STRING), jcr:primaryItemName(STRING), jcr:hold(STRING), jcr:workspace(STRING), jcr:description(STRING), jcr:primaryType(STRING), mode:initializationState(STRING), fieldB(STRING), mode:externalNodeKey(STRING), notion:booleanProperty(BOOLEAN), mode:derivedFrom(STRING), mode:isHeldBySession(BOOLEAN), jcr:baseVersion(REFERENCE), jcr:lastModified(DATE), jcr:mergeFailed(REFERENCE), jcr:requiredPrimaryTypes(STRING), mode:derivedAt(DATE), jcr:multiple(BOOLEAN), mode:generated(BOOLEAN), jcr:activityTitle(STRING), jcr:lifecyclePolicy(REFERENCE), jcr:isMixin(BOOLEAN), notion:multipleReferences(REFERENCE), jcr:availableQueryOperators(STRING), jcr:childVersionHistory(REFERENCE), car:userRating(LONG), user(STRING), jcr:autoCreated(BOOLEAN), jcr:content(REFERENCE), car:mpgHighway(LONG), mode:alias(STRING), notion:booleanProperty2(BOOLEAN), jcr:createdBy(STRING), jcr:isFullTextSearchable(BOOLEAN), jcr:uuid(STRING), jcr:onParentVersion(STRING), notion:longProperty(LONG), mode:expirationDate(DATE), jcr:lockIsDeep(BOOLEAN), notion:stringProperty(STRING), jcr:isDeep(BOOLEAN), jcr:copiedFrom(REFERENCE), car:engine(STRING), jcr:title(STRING), notion:stringAutoCreatedPropertyWithDefault(STRING), notion:stringPropertyWithDefault(STRING), jcr:isAbstract(BOOLEAN), jcr:versionHistory(REFERENCE), jcr:versionableUuid(STRING), jcr:predecessors(REFERENCE), car:maker(STRING), jcr:lockOwner(STRING), car:mpgCity(LONG), mode:sha1(STRING), jcr:repository(STRING), jcr:created(DATE), jcr:frozenMixinTypes(STRING), car:lengthInInches(DOUBLE), mode:lockedKey(STRING), jcr:text(STRING), jcr:host(STRING), jcr:configuration(REFERENCE), jcr:port(STRING), mode:workspace(STRING), notion:singleReference(REFERENCE), car:valueRating(LONG), jcr:nodeTypeName(STRING), email(STRING), jcr:isQueryable(BOOLEAN), jcr:data(BINARY), jcr:language(STRING), jcr:isQueryOrderable(BOOLEAN), jcr:isCheckedOut(BOOLEAN), jcr:mandatory(BOOLEAN), jcr:protected(BOOLEAN), jcr:protocol(STRING), jcr:sameNameSiblings(BOOLEAN), jcr:requiredType(STRING), mode:lockingSession(STRING), notion:booleanCreatedPropertyWithDefault(BOOLEAN), jcr:messageId(STRING), jcr:id(REFERENCE), mode:uri(STRING), jcr:valueConstraints(STRING), car:year(STRING), jcr:retentionPolicy(REFERENCE), jcr:activity(REFERENCE), jcr:currentLifecycleState(STRING), jcr:path(STRING), jcr:name(STRING), jcr:score(DOUBLE), mode:localName(STRING), mode:depth(LONG)], SOURCE_ALIAS=y, SOURCE_NAME=__ALLNODES__>