Skip to content

Stop subquery pushdown for OrderBy over Distinct #34121

Open

Description

For the following query:

_ = await context.Blogs.Distinct().OrderBy(b => b.Id).ToListAsync()

We currently produce:

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):

SELECT DISTINCT [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
ORDER BY [t].[Id]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions