Skip to content
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

Fix expression cloning when table changes in SelectExpression.VisitChildren #32456

Merged
merged 1 commit into from
Dec 3, 2023

Conversation

roji
Copy link
Member

@roji roji commented Nov 29, 2023

When a table is changed in SelectExpression.VisitChildren() (on an immutable SelectExpression), visit the entire SelectExpression and replace ColumnExpressions to have them properly point to the new SelectExpression, without sharing TableReferenceExpression. This allows us to mutate the TableReferenceExpression later (i.e. alias uniquification) without affecting two queries in the tree.

There's a bit of added complexity here to prevent infinite recursion where the new ColumnTableReferenceUpdater that we call also uses SelectExpression.VisitChildren, but we don't want/need that to go into ColumnTableReferenceUpdater again.

This should be a temporary fix; I believe we should revisit the general design around tables, ColumnExpression and TableReferenceExpression.

Finally, this isn't a super trivial fix - would appreciate a deep review (especially as we may consider this for patching).

Fixes #32234

Note that I ran into #26104 as well while testing this, which is a debug-only issue that's very related to this one (same SelectExpression instance referenced from multiple parts of the query).

@roji roji requested a review from maumar November 29, 2023 16:37
@roji roji force-pushed the DuplicateSelect branch 2 times, most recently from 2ac3090 to cee4b79 Compare November 29, 2023 17:17
@roji roji merged commit cf5ec40 into dotnet:main Dec 3, 2023
7 checks passed
@roji roji deleted the DuplicateSelect branch December 3, 2023 10:32
roji added a commit to roji/efcore that referenced this pull request Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants