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

Query: null semantics visitor incorrectly classifies subquery returning single scalar value as non-nullable #15778

Closed
maumar opened this issue May 22, 2019 · 1 comment
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented May 22, 2019

This yields incorrect results for cases where such a scalar subquery is compared to null (or other scalar subquery) like:

ctx.Entities1.Where(e1 => ctx.Entities2.Where(e2 => e2.Id == e1.Id && e2.Id != 7).FirstOrDefault().StringA != null)
@maumar maumar self-assigned this May 22, 2019
@maumar maumar added this to the 3.0.0 milestone May 22, 2019
maumar added a commit that referenced this issue May 24, 2019
…subquery returning single scalar value as non-nullable

Problem was that when we compared scalar subquery to null, we would assume the subquery is never null so we would never return any results. Scalar subqueries can be null when using entities.Where(e => false).Select(e => e.Name).FirstOrDefault() pattern.

Fix is to always assume SubSelectExpression is nullable.
Also fixed a bug in subquery member pushdown that was exposed by the null semantics fix - because now subqueries are treated as nullable, null semantics applies on them and in some cases of collection pushdown we would match null == null as true and returning results where nothing should be returned.
Fix is to add null check for one of the keys, so that we only match outer and inner when they are not null - this is for case of navigation chaining so its always correct to do it. We never expect a child entity when it's parent is null, or where the FK to that entity is null
@maumar maumar assigned smitpatel and maumar and unassigned maumar and smitpatel May 24, 2019
maumar pushed a commit that referenced this issue May 24, 2019
…subquery returning single scalar value as non-nullable

Problem was that when we compared scalar subquery to null, we would assume the subquery is never null so we would never return any results. Scalar subqueries can be null when using entities.Where(e => false).Select(e => e.Name).FirstOrDefault() pattern.

Fix is to always assume SubSelectExpression is nullable.
maumar added a commit that referenced this issue May 24, 2019
…subquery returning single scalar value as non-nullable

Problem was that when we compared scalar subquery to null, we would assume the subquery is never null so we would never return any results. Scalar subqueries can be null when using entities.Where(e => false).Select(e => e.Name).FirstOrDefault() pattern.

Fix is to always assume SubSelectExpression is nullable.
@maumar
Copy link
Contributor Author

maumar commented May 24, 2019

fixed in ca37ebe

@maumar maumar closed this as completed May 24, 2019
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 24, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview6 Jun 5, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview6, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants