Skip to content

Commit

Permalink
Fix to 10733 - Query: we inject redundant MaterializeCollectionNaviga…
Browse files Browse the repository at this point in the history
…tion calls into some queries that take advantage of correlated collection optimizations

Removing MaterializeCollectionNavigation call if we apply correlated collection optimizations inside. CorrelateCollection method already materializes the collection so there is no need to do it second time.
  • Loading branch information
maumar committed Jan 24, 2018
1 parent 6e803a5 commit 53dbe80
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ public CorrelatedCollectionOptimizingVisitor(
/// </summary>
public virtual IReadOnlyList<Ordering> ParentOrderings => _parentOrderings.AsReadOnly();

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method.MethodIsClosedFormOf(CollectionNavigationSubqueryInjector.MaterializeCollectionNavigationMethodInfo)
&& methodCallExpression.Arguments[1] is SubQueryExpression subQueryExpression)
{
if (_queryCompilationContext.CorrelatedSubqueryMetadataMap.TryGetValue(subQueryExpression.QueryModel.MainFromClause, out var correlatedSubqueryMetadata))
{
var parentQsre = new QuerySourceReferenceExpression(correlatedSubqueryMetadata.ParentQuerySource);
var result = Rewrite(
correlatedSubqueryMetadata.Index,
subQueryExpression.QueryModel,
correlatedSubqueryMetadata.CollectionNavigation,
correlatedSubqueryMetadata.TrackingQuery,
parentQsre);

return result;
}

return methodCallExpression;
}

return base.VisitMethodCall(methodCallExpression);
}

/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
Expand Down

0 comments on commit 53dbe80

Please sign in to comment.