-
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
Make TableExpressionBase.Alias immutable #32815
Conversation
c2b8510
to
341241f
Compare
341241f
to
02f0a42
Compare
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.
@maumar @dotnet/efteam here's the next PR in the query architecture stack, rebased on latest main and ready for review. This is a really simple one.
@@ -34,7 +34,7 @@ public sealed class TpcTablesExpression : TableExpressionBase | |||
string? alias, | |||
IEntityType entityType, | |||
IReadOnlyList<SelectExpression> subSelectExpressions, | |||
IEnumerable<IAnnotation>? annotations) | |||
IReadOnlyDictionary<string, IAnnotation>? annotations) |
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.
@maumar the changes around annotations are to stop duplicating/copying them every time we copy/clone the table expression node; since they're immutable we just reuse the existing dictionary, as is standard with expressions.
// TODO: Either add a mandatory, abstract non-destructive ChangeAlias to TableExpressionBase, or ideally, | ||
// TODO: refactor things to split the alias out of TableExpressionBase altogether. | ||
table.Alias = newAlias; | ||
table = table.WithAlias(newAlias); |
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 was the one point left actually mutating aliases - an immutable copy of the table is now produced instead.
02f0a42
to
4973e9b
Compare
And do some cleanup around table annotations Continues work from dotnet#32558
4973e9b
to
078b677
Compare
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.
Make sure that the TODO comments you added earlier have a tracking issue
NOTE: THIS IS BASED ON TOP OF #32812, REVIEW ONLY THE LAST COMMIT ONLYThis completes the immutability work done in #32812; that PR got rid of the mutable TableReferenceExpression, and this one makes TableExpressionBase.TableAlias immutable. After this, the only mutability we have in our SQL query tree is SelectExpression itself being in temporary mutable mode during translation.
Also did some cleanup around table annotations.
Note: as an alternative design, I considered extracting Alias out of TableExpressionBase altogether, and moving it out to a TableAliasExpression (or AsExpression) which would wrap the table, adding the
AS x
part; this is very similar to what we do in the prjection with ProjectionExpression. However, this would make it considerably harder to work with tables when not caring about their aliases - which is the majority of the time.