dotnet / dotnet/efcore

Stop subquery pushdown for OrderBy over Distinct

Open
#34,121 0 comments 1 reaction 0 assignees View on GitHub
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

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.