dotnet / dotnet/efcore

Optimize translation of comparison of two nullables without both being null

Open
#32,464 0 comments 2 reactions 0 assignees View on GitHub
area-perf area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

Currently, if a user wants to filter where two nullables are equal **except** when both are null, they need to write `.Where(b => b.X == b.Y && b.X != null && b.Y != null`); this generates lots of needless SQL (the situation is between if the null checks are to the left of the equality, but still not ideal).

Because of relational null semantics, it's enough to just do `x = y`; we could detect the LINQ null checks and optimize the translation.

Note: think about negated context when designing for this.

Scenario raised by @GertArnold in #32453

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.