Skip to content

Conversation

roji
Copy link
Member

@roji roji commented May 24, 2025

Backports #36110 (see #36138 for identical 9.0 backport PR)
Fixes #36105
Fixes #36112

Description
When generating SQL for multiple set operators (UNION, INTERSECT, EXCEPT), EF omitted adding parentheses in certain combinations, leading to the LINQ evaluation order not being preserved in the generated SQL. In addition, the SQLite provider didn't generate parentheses at all, since the SQLite syntax is non-standard and we originally thought no form of parentheses was possible.

Customer impact
The missing parentheses could cause the SQL set operators to be evaluated in an incorrect order (compared to the user's specified evaluation order in the LINQ query). This could lead to incorrect results getting returned from the database (data corruption).

How found
Reported by a user.

Regression
No

Testing
Added.

Risk
Very low. This is a minimal, targeted fix which only adds parentheses to preserve the LINQ evaluation order. A quirk was added just in case.

@roji roji merged commit cda1db5 into dotnet:release/8.0-staging May 29, 2025
7 checks passed
@roji roji deleted the SetOperations8 branch May 29, 2025 11:56
@roji
Copy link
Member Author

roji commented May 29, 2025

Approved via email.

This was referenced Jul 23, 2025
This was referenced Aug 28, 2025
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.

2 participants