-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: optimize database null-semantics propagation #34126
Comments
This could be a way to achieve database null semantics for some operations (see #33616 for an issue related to this). |
Related to #16050 |
Just noting that the original query is "badly written", i.e. the user could just write: db.Set<NullSemanticsEntity1>().Select(x => x.NullableStringA + x.NullableStringB) We generally don't go too far into "correcting" badly-written queries. We do go into this when there's good reason to believe that such a query could be a result of previous transformations that we do in the EF pipeline, of course. |
#33616 is about this... if the translation of string concatenation is not settled, I can use a different operation for the tests.
I believe some of these checks are added by the pipeline, but those in the tests are definitely introduced manually. |
Can you provide more context on what you're asking? I'm not sure I understand exactly. |
A simple example is getting the length of a (nullable) string:
Option 1 cannot be used at all (does not even compile). |
I am not sure if this is noteworthy, but on EFCore 8.0.6 db.Blogs.Select(x => x.NullableString == null ? default(int?) : x.NullableString.Length ).ToList(); translates to SELECT length("b"."NullableString")
FROM "Blogs" AS "b" while db.Blogs.Select(x => x.NullableString == null ? default(int?) : 1 + x.NullableString.Length ).ToList(); translates to SELECT CASE
WHEN "b"."NullableString" IS NULL THEN NULL
ELSE 1 + length("b"."NullableString")
END
FROM "Blogs" AS "b" |
We can optimize some case block for nullability by letting expressions take care of it instead of doing explicit checks.
translates to
but ideally it should translate to
This is in a sense the dual of pushing nullability information from clause test to clause result, but it also relies on clause/else matching; see #25977 for more cross-clause optimizations.
The text was updated successfully, but these errors were encountered: