Skip to content

Null semantics compensation missing for LIKE negation #26735

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

Closed
roji opened this issue Nov 18, 2021 · 2 comments · Fixed by #31482
Closed

Null semantics compensation missing for LIKE negation #26735

roji opened this issue Nov 18, 2021 · 2 comments · Fixed by #31482
Assignees
Milestone

Comments

@roji
Copy link
Member

roji commented Nov 18, 2021

When negating EF.Functions.Like, we don't add null compensation, so EF.Functions.Like || !EF.Functions.Like does not yield the full set of rows.

var blog = await ctx.Blogs.Where(b => EF.Functions.Like(b.Name, "f%")).SingleAsync();
Console.WriteLine($"Blog {blog.Id}: {blog.Name}");

var blogs = await ctx.Blogs.Where(b => !EF.Functions.Like(b.Name, "f%")).ToListAsync();
Console.WriteLine($"Blogs: {blogs.Count}");

blog = await ctx.Blogs.Where(b => b.Name == null || !EF.Functions.Like(b.Name, "f%")).SingleAsync();
Console.WriteLine($"Blog {blog.Id}: {blog.Name}");
@joakimriedel
Copy link
Contributor

Isn't this quite expected, since a "Name not like 'f%'" SQL statement will not returns rows where Name is null?

However, if I want the null rows to be returned the only workaround from C# world I've found is to do Where(b => !EF.Functions.Like(b.Name ?? '', "f%")) to translate to not (COALESCE(Name, '') like 'f%') (in MS SQL I believe ISNULL would be better since it has stricter nullability but it's not in EF.Functions)

@ajcvickers ajcvickers added this to the 7.0.0 milestone Nov 19, 2021
@ajcvickers ajcvickers assigned smitpatel and unassigned maumar Aug 29, 2022
@smitpatel
Copy link
Contributor

Looking at current processing, when ! is applied to any term we try to push it inside if the term is non-nullable (2-value logic). If the inner term is nullable then we leave the not operator as is. With that implementation, something OR !something may not give all results if something is nullable.
@maumar should know reason behind why we don't try to convert something to 2-value logic to apply ! operator over it.

@smitpatel smitpatel removed this from the 7.0.0 milestone Sep 7, 2022
@smitpatel smitpatel removed their assignment Sep 7, 2022
@ajcvickers ajcvickers added this to the Backlog milestone Sep 9, 2022
roji added a commit to roji/efcore that referenced this issue Aug 16, 2023
roji added a commit to roji/efcore that referenced this issue Aug 16, 2023
roji added a commit to roji/efcore that referenced this issue Aug 16, 2023
roji added a commit to roji/efcore that referenced this issue Aug 16, 2023
@roji roji closed this as completed in a07a1bd Aug 16, 2023
@roji roji self-assigned this Aug 16, 2023
@roji roji modified the milestones: Backlog, 8.0.0 Aug 16, 2023
roji added a commit to roji/efcore that referenced this issue Aug 17, 2023
roji added a commit that referenced this issue Aug 17, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0, 8.0.0-rc1 Aug 19, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-rc1, 8.0.0 Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants