dotnet / dotnet/efcore

Query: consider pruning orderby from subquery projection if we don't end up using it on the outside

Open
#30,143 0 comments 0 reactions 0 assignees View on GitHub
area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Issue pointed out by @roji

Example query:

```cs
ss.Set().OrderBy(x => x.FullName).Take(10)
```

result sql:

```sql
@__p_0='10'

SELECT COUNT(*)
FROM (
SELECT TOP(@__p_0) [g].[Nickname], [g].[SquadId], [g].[FullName]
FROM [Gears] AS [g]
ORDER BY [g].[FullName]
) AS [t]
```

we don't end up needing the order by FullName anywhere (because count), so we technically don't need it in the subquery projection

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.