-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Redo SQL table alias management #32785
Conversation
/// <returns>An expression representing a SELECT in a SQL tree.</returns> | ||
SelectExpression Select(SqlExpression? projection); | ||
[EntityFrameworkInternal] | ||
SelectExpression Select(SqlExpression? projection, SqlAliasManager sqlAliasManager); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the longer-term plan, these are temporary - Select shouldn't be constructing tables within itself as it's doing now, but those tables should rather be constructed outside, i.e. in RelationalQueryableMethodTranslatingEV.
query = new SqlExpressionSimplifyingExpressionVisitor(RelationalDependencies.SqlExpressionFactory, _useRelationalNulls) | ||
.Visit(query); | ||
query = new RelationalValueConverterCompensatingExpressionVisitor(RelationalDependencies.SqlExpressionFactory).Visit(query); | ||
var query5 = new SqlExpressionSimplifyingExpressionVisitor(RelationalDependencies.SqlExpressionFactory, _useRelationalNulls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to make it easier to debug and compare multiple versions of the tree in the various phases.
/// doing so can result in application failures when updating to a new Entity Framework Core release. | ||
/// </summary> | ||
[EntityFrameworkInternal] | ||
public void ChangeTableAlias(int tableIndex, string newAlias, HashSet<TableReferenceExpression> visitedTableReferences) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very temporary hack to allow SqlAliasManager to change the alias during post-processing. The subsequent PR will remove TableReferenceExpression altogether and this will go away.
new SelectExpressionMutableVerifyingExpressionVisitor().Visit(query); | ||
// Verifies that all table aliases are uniquely assigned without skipping over | ||
// Which points to possible mutation of a SelectExpression being used in multiple places. | ||
new TableAliasVerifyingExpressionVisitor().Visit(query); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This verification visitor no longer makes sense, but I'll be introducing something better to check correct table/column scoping, after TableReferenceExpression is gone.
a7c0ab5
to
ec44934
Compare
test/EFCore.SqlServer.FunctionalTests/Query/JsonQuerySqlServerTest.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/SqlExpressions/SelectExpression.Helper.cs
Outdated
Show resolved
Hide resolved
src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs
Outdated
Show resolved
Hide resolved
Closees dotnet#32784 Fixes dotnet#32757 Part of dotnet#32778 Fixes dotnet#26104
They were fixed by dotnet#32785.
Note to reviewers: since we now generate unique aliases early - before constructing the table - and not later in a separate visitation, the alias ordering is changing (deeper nested tables have lower numbers); that's why so many SQL baselines are changing in this PR.
Closes #32784
Fixes #32757
Part of #32778
Fixes #26104