Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query :: SelectMany-GroupJoin-DefaultIfEmpty isn't being lifted into SQL for some complex queries, resulting in extensive client-side evaluation #4588

Closed
maumar opened this issue Feb 17, 2016 · 5 comments
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Feb 17, 2016

This is mostly visible in scenarios with optional navigations, e.g.

from c in ctx.Customers
where c.Detail.Name == "Foo"
select c;

this gets translated into:

from c in ctx.Customers
join d in ctx.Details on c.Id equals d.CustomerId into grouping
from d in grouping.DefaultIfEmpty()
where d.Name == "Foo"
select c;

however the filter will be performed on the client resulting in unnecessary data being pulled from the database

@sheinema
Copy link

We are having a related problem. Even a single Left Outer Join results in the following warning and hundreds of additional calls to the db:

Ex:

var q = from a in context.Activities
                    from p in context.Places.Where(x => x.PlaceId == a.PlaceId).DefaultIfEmpty()
                    select new { a, p };

...

Microsoft.Data.Entity.Query.Internal.SqlServerQueryCompilationContextFactory: Warning: The LINQ expression 'DefaultIfEmpty()' could not be translated and will be evaluated locally.

Causes hundreds of additional queries (one call to Place for each Activity): 

Microsoft.Data.Entity.Storage.Internal.RelationalCommandBuilderFactory: Information: Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [x].[PlaceId]
FROM [Place] AS [x]

*Using EF 7.0.0-rc1-final; ASP.NET 1.0.0-rc1-final

@maumar
Copy link
Contributor Author

maumar commented Feb 23, 2016

@sheinema
The join pattern you are using is not recognized (this is being tracked by #3263)

However, alternative way to produce LOJ works in our nightly builds (available with the next release):

var q = from a in context.Activities
            join x in context.Places on a.PlaceId equals x.PlaceId into grouping
            from x in grouping.DefaultIfEmpty()
            select new { a, x }

This should yield only one query with LOJ, however DefaultIfEmpty and everything after it will still be evaluated on the client.

@jazzonaut
Copy link

Will this be implemented in the RTM release?

@kapsiR
Copy link

kapsiR commented Jun 29, 2016

Do you have any roadmap for the 1.1.0 milestone release especially for this issue? (maybe a roadmap for any patch?)

@rowanmiller
Copy link
Contributor

Nothing public yet, we'll share as soon as we do. Prior to undertaking the major EF Core 1.0.0 we were releasing stable updates every 3-4 months (with previews in between). I expect our cadence to be similar.

anpete added a commit that referenced this issue Sep 22, 2016
… being lifted into SQL for some complex queries, resulting in extensive client-side evaluation.

Adds relational GroupJoin/DefaultIfEmpty elimination.
anpete added a commit that referenced this issue Sep 23, 2016
… being lifted into SQL for some complex queries, resulting in extensive client-side evaluation.

Adds relational GroupJoin/DefaultIfEmpty elimination.
@anpete anpete closed this as completed in 757e6d4 Sep 23, 2016
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

7 participants