dotnet / dotnet/efcore

Review our shaper expression visitation in visitors

Open
#32,979 0 comments 0 reactions 0 assignees View on GitHub
area-query consider-for-next-release
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Bug #32976 was filed because SqlServerJsonPostprocessor visited only the QueryExpression part of ShapedQueryExpression; however, when split query is enabled, the split query is actually stored on the shaper side, and ShapedQueryExpression.QueryExpression represents only the main/first query.

Review other post-processing visitors to see where we have similar issues. For example, the recently-introduced SqlTreePruner and the visitors inside SqlAliasManager also visit only ShapedQueryExpression.QueryExpression (these affect only 9.0).

Another more subtle problem that affects previous versions: SqlExpressionSimplifyingExpressionVisitor does the following for ShapedQueryExpression:

```c#
var newQueryExpression = Visit(shapedQueryExpression.QueryExpression);
var newShaperExpression = Visit(shapedQueryExpression.ShaperExpression);

return shapedQueryExpression.Update(newQueryExpression, newShaperExpression);
```

This indeed visits both the query and the shaper, but note that the shaper contains references to the query (in ProjectionBindingExpression); this means that replacing the query as above causes us to lose referential integrity, since the shaper still points to the old query. Note that ShapedQueryExpression.UpdateQueryExpression() does a recursive replace instead the shaper to update it for the new query, but ShapedQueryExpression.Update(query, shaper) does not do this.

For thoughts on changing the query architecture to improve this, see #32980.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.