Skip to content

Commit

Permalink
Move all pruning code to the pruner and make it an immutable visitor
Browse files Browse the repository at this point in the history
Fixes #31276
  • Loading branch information
roji committed Jan 20, 2024
1 parent 19c30d6 commit 0091907
Show file tree
Hide file tree
Showing 10 changed files with 280 additions and 296 deletions.

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);
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

0 comments on commit 0091907

Please sign in to comment.