Stop subquery pushdown for OrderBy over Distinct
Open
area-perf
area-query
consider-for-next-release
customer-reported
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
For the following query:
```c#
_ = await context.Blogs.Distinct().OrderBy(b => b.Id).ToListAsync()
```
We currently produce:
```sql
SELECT [t].[Id], [t].[Name]
FROM (
SELECT DISTINCT [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
) AS [t]
ORDER BY [t].[Id]
```
But the pushdown isn't needed, we can generate this instead (note that ORDER BY is processed after DISTINCT in SQL):
```sql
SELECT DISTINCT [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
ORDER BY [t].[Id]
```
Contributor guide
Assessment
This issue has not been assessed yet.