src/Shared/EntityFramework/Core/Query/PlanCompiler/SortOpRules.cs
// <summary>
// If the SortOp's input is guaranteed to produce at most 1 row, remove the node with the SortOp:
// Sort(X) => X, if X is guaranteed to produce no more than 1 row
// </summary>
// <param name="context"> Rule processing context </param>
// <param name="n"> current subtree </param>
// <param name="newNode"> transformed subtree </param>
// <returns> transformation status </returns>
If the SortOp's input is guaranteed to produce at most 1 row, remove the node with the SortOp:
Sort(X) => X, if X is guaranteed to produce no more than 1 row
If the SortOp ' s input is guaranteed to produce at most 1 row remove the node with the SortOp : Sort ( X ) = > X if X is guaranteed to produce no more than 1 row
private static bool ProcessSortOpOverAtMostOneRow(RuleProcessingContext context, Node n, out Node newNode)
        {
            var nodeInfo = (context).Command.GetExtendedNodeInfo(n.Child0);
            if (nodeInfo.MaxRows == RowCount.Zero
                || nodeInfo.MaxRows == RowCount.One)
            {
                newNode = n.Child0;
                return true;
            }
            newNode = n;
            return false;
        }
private static bool ProcessSortOpOverAtMostOneRow ( RuleProcessingContext context , Node n , out Node newNode ) { var nodeInfo = ( context ) . Command . GetExtendedNodeInfo ( n . Child0 ) ; if ( nodeInfo . MaxRows == RowCount . Zero || nodeInfo . MaxRows == RowCount . One ) { newNode = n . Child0 ; return true ; } newNode = n ; return false ; }
If the SortOp's input is guaranteed to produce at most 1 row, remove the node with the SortOp:
Sort(X) => X, if X is guaranteed to produce no more than 1 row
If the SortOp ' s input is guaranteed to produce at most 1 row remove the node with the SortOp : Sort ( X ) = > X if X is guaranteed to produce no more than 1 row
//If the input has at most one row, omit the SortOp //Otherwise return the node as is
None
context
RuleProcessingContext
Rule processing context
Rule processing context
n
Node
None
Node
out
newNode
None