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 #30273 - EF7 generating incorrect SQL for the Concat/Union All #30451

Merged
merged 1 commit into from
Mar 14, 2023

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Mar 9, 2023

Port of #30452
Fixes #30273

Description

Projecting subset of properties from a set operation where one of the sources has distinct (but other doesn't) generates invalid sql.

Customer impact

Affected queries result in invalid sql.

How found

Customer report on 7.0

Regression

Yes. This scenario worked correctly in previous version of EF Core.

Testing

Added regression tests for affected scenario and similar types of queries.

Risk

Low: Fix is isolated - only affects pruning logic for set operators. Fix disables the optimization (pruning of redundant columns), that was being applied too aggressively. Worst case, the change results is uglier sql (i.e. optimization is not applied where it should), but it should never have functional impact. Added quirk to revert to old behavior if necessary.

…, The same code was working fine for EF6.4.4

Problem was that during SelectExpression pruning for set operations we would try to prune both sources independently. However, if a source is Distinct we can't prune (that could affect the result). So the problematic case is where we prune one source but can't prune the second due to Distinct, and we end up with both sources having not matching projections.
Fix is to check if either source has Distinct before attempting to prune them.

Fixed #30273
@maumar maumar requested review from roji and ajcvickers March 9, 2023 23:40
@maumar maumar added this to the 7.0.x milestone Mar 10, 2023
@leecow leecow modified the milestones: 7.0.x, 7.0.5 Mar 14, 2023
@ajcvickers ajcvickers changed the base branch from main to release/7.0 March 14, 2023 17:30
@ajcvickers ajcvickers merged commit edeb38f into release/7.0 Mar 14, 2023
@ajcvickers ajcvickers deleted the fix30273_70 branch March 14, 2023 18:45
@ajcvickers ajcvickers changed the title [release/7.0] Fix to #30273 - EF7 generating incorrect SQL for the Concat/Union All, The same code was working fine for EF6.4.4 [release/7.0] Fix to #30273 - EF7 generating incorrect SQL for the Concat/Union All Mar 16, 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.

EF7 generating incorrect SQL for the Concat/Union All
4 participants