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

[release/7.0] Fix to #30575 - Multiple LeftJoins (GroupJoins) lead to GroupJoin Exception when the same where is used twice #30794

Merged
merged 1 commit into from
May 2, 2023

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Apr 28, 2023

Ported from #30594
Fixes #30575

Description

Query with more multiple GroupJoin-SelectMany-DefaultIfEmpty (i.e. LEFT JOIN pattern), which use a variable, produces incorrect query.

Customer impact

Query with more multiple GroupJoin-SelectMany-DefaultIfEmpty (i.e. LEFT JOIN pattern), which use a variable, produces incorrect query. Workaround is to not use variable (i.e. constant) which is easy, when possible, but often not realistic.

How found

Customer report on 7.0.

Regression

No.

Testing

Added regression tests.

Risk

Minimal; Fix is very simple (1 line change) - an improved way to identify lambda arguments vs user variables (by looking at the name prefix). We use this strategy in other places in the code base already, so the approach has been thoroughly tested. As always, added quirk just in case.

…eption when the same where is used twice

Problem is in QueryableMethodNormalizingExpressionVisitor and specifically part where we convert from GroupJoin-SelectMany-DefaultIfEmpty into left join (SelectManyVerifyingExpressionVisitor). We check if the collection selector is correlated, and we do that by looking at parameters in that lambda. Problem is that the affected queries reference outside variable that gets parameterized and that breaks the correlation finding logic. Fix is to add a step that scans entire query and identifies external parameters before we try to normalize GJSMDIE into LeftJoins, so that those external parameters are not counted as correlated.

Fixes #30575
@maumar
Copy link
Contributor Author

maumar commented Apr 29, 2023

@ajcvickers - yea or nay?

@ajcvickers ajcvickers added this to the 7.0.x milestone May 1, 2023
@rbhanda rbhanda modified the milestones: 7.0.x, 7.0.7 May 2, 2023
@wtgodbe wtgodbe merged commit 03541ad into release/7.0 May 2, 2023
@wtgodbe wtgodbe deleted the fix30575_70 branch May 2, 2023 20:02
@ajcvickers ajcvickers removed this from the 7.0.7 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants