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

Missing checks for predicate when simplifying JSON primitive collections #33932

Closed
roji opened this issue Jun 8, 2024 · 1 comment · Fixed by #33933
Closed

Missing checks for predicate when simplifying JSON primitive collections #33932

roji opened this issue Jun 8, 2024 · 1 comment · Fixed by #33933
Assignees
Labels
area-json area-primitive-collections area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@roji
Copy link
Member

roji commented Jun 8, 2024

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().

Corresponding issue for PG: npgsql/efcore.pg#3195

@roji roji self-assigned this Jun 8, 2024
@roji roji changed the title SQLite: Count() over JSON collection incorrectly translated to json_array_length when a predicate exists Missing checks for predicate when simplifying JSON primitive collections Jun 8, 2024
@roji roji removed the area-sqlite label Jun 8, 2024
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 8, 2024
@roji
Copy link
Member Author

roji commented Jun 9, 2024

Reopening to consider servicing (PR: #33939)

@roji roji reopened this Jun 9, 2024
roji added a commit to roji/efcore that referenced this issue Jun 9, 2024
roji added a commit to roji/efcore that referenced this issue Jun 9, 2024
AndriySvyryd pushed a commit that referenced this issue Jun 10, 2024
@roji roji closed this as completed Jun 10, 2024
@ajcvickers ajcvickers added this to the 8.0.7 milestone Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-json area-primitive-collections area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants