Multiple left joins cause client side eval
Steps to reproduce
Alpha1-22262, should be after several left-join related fixes, such as #4588. I was going to wait to post since this is on the edge of whats being worked on, but I couldn't find anything tracking this. Removing the comments causes the query to fail. With the comments, a single query is correctly executed. I encountered the problem through a large variety of queries, but the one common factor seems to be more than one left join, which this simplified example shows.
var q3 = from i in items
join innerD0 in values on i.Id equals innerD0.SparseItemId into d0g
from d0pv in d0g.DefaultIfEmpty()
//join innerD1 in values on i.Id equals innerD1.SparseItemId into d1g
//from d1pv in d1g.DefaultIfEmpty()
select new { SparseItemId = i.Id };
Queries executed:
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory:Information: Executed DbCommand (3ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [i].[Id], [innerD0].[SparseItemId], [innerD0].[PropertyId], [innerD0].[Data], [innerD0].[DateTimeOffsetValue], [innerD0].[DecimalValue], [innerD0].[DoubleValue], [innerD0].[StringValue]
FROM [SparseItem] AS [i]
LEFT JOIN [PropertyValue] AS [innerD0] ON [i].[Id] = [innerD0].[SparseItemId]
ORDER BY [i].[Id]
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory:Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [innerD1].[SparseItemId], [innerD1].[PropertyId], [innerD1].[Data], [innerD1].[DateTimeOffsetValue], [innerD1].[DecimalValue], [innerD1].[DoubleValue], [innerD1].[StringValue]
FROM [PropertyValue] AS [innerD1]
The query shaper pulls the second join source from a new query, causing the entire table to be selected.
@anpete should this be fixed by the fix for #4588?
@divega @anpete The alpha I pulled was only 4 hrs old when i tried it again this morning from ci feed, so I think that was already in it?
@EricABC Thanks for reporting. When you say "fail" do you mean that an exception is raised, or do you just mean that it client evals?
BTW should //from d1pv in d0g.DefaultIfEmpty() be //from d1pv in d1g.DefaultIfEmpty() ?
Sorry, I just mean the client eval.
I heard from @smitpatel that the fix hasn't made it to nightly builds yet.
Just to be sure, I pulled dev and verified the issue still occurs using dev branch locally.
Also if it helps, the first group join will get to here. If you comment out the second one, it gets inside. Otherwise the value will be 2 and it will proceed to generate a new RelationalQueryModelVisitor and go client-side. Hacking on it to force it to process the first left join shows that several things get out of alignment when there is a tree of left joins. It's either not getting back to the original query source joined on, or its not able to perceive the previous source as the new effective flattened query after the first join.
@EricABC That's why I was asking the question above. It looks like a typo in the query that d0g is referenced twice.
Woops, sorry for the typo (edited now), but I verified the issue persists.
OK, thanks for checking.
One other note, it might be nice to have QueryClientEvaluationWarning fire when we end up resolving another main from-clause in a separate visitor, or perhaps add a RelationalEventId.MultipleQueriesExecutedWarning? Seems like this would be the spot where that would be considered.
@anpete we wanted to get your thoughts on putting this in 1.1.0-preview1. If that's not feasible, then we should punt to 1.2.0.
Confirmed and trying to get this into preview1
@anpete It seems like this is fixed in 1.1, if we are using LTS release, does it have any workaround to have multiple left outer join in single query?