dotnet / dotnet/efcore

Query: optimize database null-semantics propagation

Open
#34,126 7 comments 1 reaction 0 assignees View on GitHub
area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

We can optimize some case block for nullability by letting expressions take care of it instead of doing explicit checks.

```csharp
db.Set().Select(
x => x.NullableStringA != null && x.NullableStringB != null
? x.NullableStringA + x.NullableStringB
: default)
```

translates to
```sql
SELECT CASE
WHEN "e"."NullableStringA" IS NOT NULL AND "e"."NullableStringB" IS NOT NULL
THEN "e"."NullableStringA" || "e"."NullableStringB"
ELSE NULL
END
FROM "Entities1" AS "e"
```

but ideally it should translate to

```sql
SELECT "e"."NullableStringA" || "e"."NullableStringB"
FROM "Entities1" AS "e"
```

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.

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.