Skip to content

[release/8.0] Add missing check for predicate in primitive collection simplifications#33939

Merged
AndriySvyryd merged 1 commit intodotnet:release/8.0from
roji:MissingPredicateChecks8.0
Jun 10, 2024
Merged

[release/8.0] Add missing check for predicate in primitive collection simplifications#33939
AndriySvyryd merged 1 commit intodotnet:release/8.0from
roji:MissingPredicateChecks8.0

Conversation

@roji
Copy link
Member

@roji roji commented Jun 9, 2024

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.

@AndriySvyryd AndriySvyryd added this to the 8.0.7 milestone Jun 10, 2024
@AndriySvyryd AndriySvyryd merged commit 67fd137 into dotnet:release/8.0 Jun 10, 2024
@roji roji deleted the MissingPredicateChecks8.0 branch June 10, 2024 10:16
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