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.
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.
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.
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.
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
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