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

[6.0.2] Query: Update column expression correctly when lifting joins from group by aggregate subquery #27109

Merged
merged 1 commit into from
Jan 10, 2022

Conversation

smitpatel
Copy link
Contributor

@smitpatel smitpatel commented Jan 5, 2022

When replacing columns, we used the outer select expression which had additional joins from previous term whose aliases match tables in current join and it got updated with wrong table.
The fix is to utilize the original tables when replacing columns. These column replacement is to map the columns from initial tables of group by from subquery to outer group by query.

Resolves #27083

This PR is targeting another PR in release/6.0. If the earlier PR is not approved, I will rebase this PR direct on 6.0. The dependency between PR related to group by is to avoid unintentional side-effects between different patch fixes.

Description

When expanding navigation in aggregate operation in projection after GroupBy operator, we lift the joins generated from navigation to main group by query. In certain conditions we end up generating SQL referencing wrong tables which could generate incorrect results.

Customer impact

Customer will get incorrect results without any exception.

How found

Customer reported on 6.0.1

Regression

No. The scenario of navigations inside aggregate operation was not supported prior to 6.0

Testing

Added test for user mentioned scenario which covers the root cause of the issue. (matching alias)

Risk

Low risk. Change only affects above scenario. Also added quirk to revert back to earlier behavior in case working scenario breaks.

var columnExpressionReplacingExpressionVisitor =
new ColumnExpressionReplacingExpressionVisitor(subquery, _selectExpression);
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue27083", out var enabled2) && enabled2
Copy link
Contributor

@maumar maumar Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe we should switch to enabled27083 convention for these? (same with useOldBehavior in other places)

Base automatically changed from smit/newyearnewme to release/6.0 January 10, 2022 19:07
…up by aggregate subquery

When replacing columns, we used the outer select expression which had additional joins from previous term whose aliases match tables in current join and it got updated with wrong table.
The fix is to utilize the original tables when replacing columns. These column replacement is to map the columns from initial tables of group by from subquery to outer group by query.

Resolves #27083
@smitpatel smitpatel merged commit 8a7bf4b into release/6.0 Jan 10, 2022
@smitpatel smitpatel deleted the smit/snowisbad branch January 10, 2022 20:06
@smitpatel smitpatel removed this from the 6.0.2 milestone Jan 10, 2022
@ajcvickers ajcvickers changed the title [release/6.0] Query: Update column expression correctly when lifting joins from group by aggregate subquery [6.0.2] Query: Update column expression correctly when lifting joins from group by aggregate subquery Jan 13, 2022
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.

4 participants