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

Move all pruning code to the pruner and make it an immutable visitor #32817

Merged
merged 1 commit into from
Jan 20, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,9 @@
<data name="SetOperationOverDifferentStructuralTypes" xml:space="preserve">
<value>Set operations over different entity or complex types are not supported ('{type1}' and '{type2}').</value>
</data>
<data name="SelectExpressionUpdateNotSupportedWhileMutable" xml:space="preserve">
<value>SelectExpression.Update() is not supported while the expression is in mutable state.</value>
</data>
<data name="SetOperationsNotAllowedAfterClientEvaluation" xml:space="preserve">
<value>Unable to translate set operation after client projection has been applied. Consider moving the set operation before the last 'Select' call.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,55 +77,15 @@ private Expression VisitCase(CaseExpression caseExpression)

private Expression VisitSelect(SelectExpression selectExpression)
{
var changed = false;
var projections = new List<ProjectionExpression>();
foreach (var item in selectExpression.Projection)
{
var updatedProjection = (ProjectionExpression)Visit(item);
projections.Add(updatedProjection);
changed |= updatedProjection != item;
}

var tables = new List<TableExpressionBase>();
foreach (var table in selectExpression.Tables)
{
var newTable = (TableExpressionBase)Visit(table);
changed |= newTable != table;
tables.Add(newTable);
}

var projections = this.VisitAndConvert(selectExpression.Projection);
Copy link
Member Author

Choose a reason for hiding this comment

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

This both switches to using VisitAndConvert (which visits lists and returns the original if it didn't change), and removes tracking of whether anything changed; SelectExpression.Update() does that now - as is standard with expressions - and returns the original SelectExpression if nothing changed.

var tables = this.VisitAndConvert(selectExpression.Tables);
var predicate = TryCompensateForBoolWithValueConverter((SqlExpression?)Visit(selectExpression.Predicate));
changed |= predicate != selectExpression.Predicate;

var groupBy = new List<SqlExpression>();
foreach (var groupingKey in selectExpression.GroupBy)
{
var newGroupingKey = (SqlExpression)Visit(groupingKey);
changed |= newGroupingKey != groupingKey;
groupBy.Add(newGroupingKey);
}

var groupBy = this.VisitAndConvert(selectExpression.GroupBy);
var having = TryCompensateForBoolWithValueConverter((SqlExpression?)Visit(selectExpression.Having));
changed |= having != selectExpression.Having;

var orderings = new List<OrderingExpression>();
foreach (var ordering in selectExpression.Orderings)
{
var orderingExpression = (SqlExpression)Visit(ordering.Expression);
changed |= orderingExpression != ordering.Expression;
orderings.Add(ordering.Update(orderingExpression));
}

var orderings = this.VisitAndConvert(selectExpression.Orderings);
var offset = (SqlExpression?)Visit(selectExpression.Offset);
changed |= offset != selectExpression.Offset;

var limit = (SqlExpression?)Visit(selectExpression.Limit);
changed |= limit != selectExpression.Limit;

return changed
? selectExpression.Update(
projections, tables, predicate, groupBy, having, orderings, limit, offset)
: selectExpression;
return selectExpression.Update(projections, tables, predicate, groupBy, having, orderings, limit, offset);
}

private Expression VisitInnerJoin(InnerJoinExpression innerJoinExpression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public TpcTableExpressionRemovingExpressionVisitor(SqlAliasManager sqlAliasManag
CreateColumnExpression(projection, setOperationAlias), projection.Alias));
}

generatedSelectExpression._mutable = false;
generatedSelectExpression.IsMutable = false;
result = generatedSelectExpression;
}

Expand Down
Loading
Loading