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

Navigation expansion rewrite - first draft #15383

Merged
merged 1 commit into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static IServiceCollection AddEntityFrameworkCosmos([NotNull] this IServic
.TryAdd<IEntityQueryModelVisitorFactory, CosmosEntityQueryModelVisitorFactory>()
.TryAdd<IEntityQueryableExpressionVisitorFactory, CosmosEntityQueryableExpressionVisitorFactory>()
.TryAdd<IMemberAccessBindingExpressionVisitorFactory, CosmosMemberAccessBindingExpressionVisitorFactory>()
.TryAdd<INavigationRewritingExpressionVisitorFactory, CosmosNavigationRewritingExpressionVisitorFactory>()
.TryAdd<ITypeMappingSource, CosmosTypeMappingSource>()
.TryAddProviderSpecificServices(
b => b
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ public override Expression Visit(Expression expression)
// Skip over Include and Correlated Collection methods
// This is checked first because it should not call base when there is not _targetSelectExpression
if (expression is MethodCallExpression methodCallExpression
&& (IncludeCompiler.IsIncludeMethod(methodCallExpression)
|| CorrelatedCollectionOptimizingVisitor.IsCorrelatedCollectionMethod(methodCallExpression)))
&& IncludeCompiler.IsIncludeMethod(methodCallExpression))
{
return expression;
}
Expand Down Expand Up @@ -279,7 +278,10 @@ var sqlExpression
// We bind with ValueBuffer in GroupByAggregate case straight away
// Since the expression can be some translation from [g].[Key] which won't bind with MemberAccessBindingEV
if (!_isGroupAggregate
&& sqlExpression is ColumnExpression)
&& sqlExpression is ColumnExpression
// if we have null conditional that propagates null, i.e. entity.Key != null ? entity.Property : null
// the result is also a ColumnExpression, but for this case we don't want to short-circuit
&& !(expression is ConditionalExpression))
{
var index = _targetSelectExpression.AddToProjection(sqlExpression);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.EntityFrameworkCore.Query.Expressions.Internal;
using Microsoft.EntityFrameworkCore.Query.ExpressionTranslators;
using Microsoft.EntityFrameworkCore.Query.Internal;
using Microsoft.EntityFrameworkCore.Query.NavigationExpansion;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using Remotion.Linq;
Expand Down Expand Up @@ -1147,11 +1148,8 @@ protected override Expression VisitExtension(Expression expression)

return new NullableExpression(newAccessOperation);

case NullSafeEqualExpression nullSafeEqualExpression:
var equalityExpression
= new NullCompensatedExpression(nullSafeEqualExpression.EqualExpression);

return Visit(equalityExpression);
case CorrelationPredicateExpression correlationPredicateExpression:
return Visit(new NullCompensatedExpression(correlationPredicateExpression.EqualExpression));

case NullCompensatedExpression nullCompensatedExpression:
newOperand = Visit(nullCompensatedExpression.Operand);
Expand Down
88 changes: 0 additions & 88 deletions src/EFCore.Relational/Query/RelationalQueryModelVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,34 +1246,6 @@ var sqlOrderingExpression
}
}

/// <summary>
/// Determines whether correlated collections (if any) can be optimized.
/// </summary>
/// <returns>True if optimization is allowed, false otherwise.</returns>
protected override bool CanOptimizeCorrelatedCollections()
{
if (!base.CanOptimizeCorrelatedCollections())
{
return false;
}

if (RequiresClientEval
|| RequiresClientFilter
|| RequiresClientJoin
|| RequiresClientOrderBy
|| RequiresClientSelectMany)
{
return false;
}

var injectParametersFinder
= new InjectParametersFindingVisitor(QueryCompilationContext.QueryMethodProvider.InjectParametersMethod);

injectParametersFinder.Visit(Expression);

return !injectParametersFinder.InjectParametersFound;
}

private class InjectParametersFindingVisitor : ExpressionVisitorBase
{
private readonly MethodInfo _injectParametersMethod;
Expand Down Expand Up @@ -1403,66 +1375,6 @@ public override void VisitResultOperator(ResultOperatorBase resultOperator, Quer
}
}

private class GroupByPreProcessor : QueryModelVisitorBase
{
private readonly QueryCompilationContext _queryCompilationContext;

public GroupByPreProcessor(QueryCompilationContext queryCompilationContext)
{
_queryCompilationContext = queryCompilationContext;
}

public override void VisitQueryModel(QueryModel queryModel)
{
queryModel.TransformExpressions(new TransformingQueryModelExpressionVisitor<GroupByPreProcessor>(this).Visit);

if (queryModel.ResultOperators.Any(o => o is GroupResultOperator)
&& _queryCompilationContext.IsIncludeQuery
&& !queryModel.ResultOperators.Any(
o => o is SkipResultOperator || o is TakeResultOperator || o is ChoiceResultOperatorBase || o is DistinctResultOperator))
{
base.VisitQueryModel(queryModel);
}
}

protected override void VisitResultOperators(ObservableCollection<ResultOperatorBase> resultOperators, QueryModel queryModel)
{
var groupResultOperators = queryModel.ResultOperators.OfType<GroupResultOperator>().ToList();
if (groupResultOperators.Count > 0)
{
var orderByClause = queryModel.BodyClauses.OfType<OrderByClause>().FirstOrDefault();
if (orderByClause == null)
{
orderByClause = new OrderByClause();
queryModel.BodyClauses.Add(orderByClause);
}

var firstGroupResultOperator = groupResultOperators[0];

var groupKeys = firstGroupResultOperator.KeySelector is NewExpression compositeGroupKey
? compositeGroupKey.Arguments.Reverse()
: new[] { firstGroupResultOperator.KeySelector };

foreach (var groupKey in groupKeys)
{
orderByClause.Orderings.Insert(0, new Ordering(groupKey, OrderingDirection.Asc));
}
}
}
}

/// <summary>
/// Pre-processes query model before we rewrite its navigations.
/// </summary>
/// <param name="queryModel">Query model to process. </param>
protected override void OnBeforeNavigationRewrite(QueryModel queryModel)
{
Check.NotNull(queryModel, nameof(queryModel));

var groupByPreProcessor = new GroupByPreProcessor(QueryCompilationContext);
groupByPreProcessor.VisitQueryModel(queryModel);
}

/// <summary>
/// Applies optimizations to the query.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/EFCore/EFCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Microsoft.EntityFrameworkCore.DbSet
<MinClientVersion>3.6</MinClientVersion>
<AssemblyName>Microsoft.EntityFrameworkCore</AssemblyName>
<RootNamespace>Microsoft.EntityFrameworkCore</RootNamespace>
<NoWarn>$(NoWarn);CS1591</NoWarn>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disabled for now, too much work to put those in, and the codebase is in flux

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CodeAnalysisRuleSet>..\..\EFCore.ruleset</CodeAnalysisRuleSet>
<LangVersion>8.0</LangVersion>
Expand Down
2 changes: 0 additions & 2 deletions src/EFCore/Infrastructure/EntityFrameworkServicesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public static readonly IDictionary<Type, ServiceCharacteristics> CoreServices
{ typeof(IEntityTrackingInfoFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(ITaskBlockingExpressionVisitor), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IMemberAccessBindingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(INavigationRewritingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IEagerLoadingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IQuerySourceTracingExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
{ typeof(IProjectionExpressionVisitorFactory), new ServiceCharacteristics(ServiceLifetime.Singleton) },
Expand Down Expand Up @@ -258,7 +257,6 @@ public virtual EntityFrameworkServicesBuilder TryAddCoreServices()
TryAdd<ITaskBlockingExpressionVisitor, TaskBlockingExpressionVisitor>();
TryAdd<IEntityResultFindingExpressionVisitorFactory, EntityResultFindingExpressionVisitorFactory>();
TryAdd<IMemberAccessBindingExpressionVisitorFactory, MemberAccessBindingExpressionVisitorFactory>();
TryAdd<INavigationRewritingExpressionVisitorFactory, NavigationRewritingExpressionVisitorFactory>();
TryAdd<IEagerLoadingExpressionVisitorFactory, EagerLoadingExpressionVisitorFactory>();
TryAdd<IQuerySourceTracingExpressionVisitorFactory, QuerySourceTracingExpressionVisitorFactory>();
TryAdd<IRequiresMaterializationExpressionVisitorFactory, RequiresMaterializationExpressionVisitorFactory>();
Expand Down
Loading