[release/8.0] Add missing check for predicate in primitive collection simplifications#33939
Merged
AndriySvyryd merged 1 commit intodotnet:release/8.0from Jun 10, 2024
Merged
Conversation
… simplifications (dotnet#33933) Fixes dotnet#33932 (cherry picked from commit b84707f)
AndriySvyryd
approved these changes
Jun 9, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #33932, backports #33933
Description
In the query pipeilne, we pattern match specific LINQ operators to translate to specialized functions/operators. For example, on SQLite, the query fragment Where(b => b.Ints.Count() == 8) is translated to json_array_length(b.Ints) = 8, rather than the full subquery translation (SELECT COUNT(*) FROM json_each(b.Ints)) == 8).
Unfortunately, in many of the sites where this sort of pattern matching occurs, I left out checking the predicate. As a result, we perform these simplifications even when we shouldn't. For example, Where(b => b.Ints.Where(i => i > 3).Count() == 8) also translates to json_array_length(b.Ints) = 8, effectively ignoring the Where().
Customer impact
When a customer composes certain LINQ operators on a JSON query that already has a Where(), incorrect SQL is generated (without the WHERE) and incorrect results are returned (data corruption).
How found
Found while working on unrelated query pipeline improvements.
Regression
No, JSON collection querying is a new feature in EF8.
Testing
Test added.
Risk
Very low - one-line, very straightforward fix (in multiple sites). Quirk added.