You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query: correlated collection optimization is broken for queries containing top level First/FirstOrDefault/Single/SingleOrDefault #10813
var result = ctx.Parents.Select(p =>
new
{
Children = p.Children
}).FirstOrDefault();
Problem here is that when we rewrite QM to create query that fetches inner elements, we produce join between inner elements and cloned parent query model. However, if parent model contains result operators that change cardinality, we would clone it also and hence produce invalid QM.
In the presence of Single value from sequence result operator, we should not be doing any optimization. Rather than we should just use N+1 mode of evaluation since it would run 2 queries anyway. It gives us benefit that 2nd query is filtered based on a parameter rather than a join (also no order by is needed in 2nd query) which would be efficient than running a normal collection query.
@smitpatel correlated collections optimization doesn't work if the outer is using outer parameter, so in case of multi-level correlation we would be producing inefficient queries. We could make the optimization you suggest once/if #10877 is addressed
Re-opening this. This is partially fixed. We need tracking issue to do outer parameter injection for single record collection query. Either we use this or file a new one. For include pipeline (perhaps older one) #2182
Activity
Fix to #10813 - Query: correlated collection optimization is broken f…
smitpatel commentedon Feb 2, 2018
In the presence of Single value from sequence result operator, we should not be doing any optimization. Rather than we should just use N+1 mode of evaluation since it would run 2 queries anyway. It gives us benefit that 2nd query is filtered based on a parameter rather than a join (also no order by is needed in 2nd query) which would be efficient than running a normal collection query.
maumar commentedon Feb 5, 2018
@smitpatel correlated collections optimization doesn't work if the outer is using outer parameter, so in case of multi-level correlation we would be producing inefficient queries. We could make the optimization you suggest once/if #10877 is addressed
Fix to #10813 - Query: correlated collection optimization is broken f…
maumar commentedon Feb 5, 2018
fixed in d787c13
smitpatel commentedon Feb 11, 2018
Re-opening this. This is partially fixed. We need tracking issue to do outer parameter injection for single record collection query. Either we use this or file a new one. For include pipeline (perhaps older one) #2182
maumar commentedon Feb 12, 2018
@smitpatel #10877 is already tracking this (see one of the comments)
maumar commentedon Feb 28, 2018
Workaround:
First/FirstOrDefault:
Single/SingleOrDefault: