Query: optimize non-nullable column information in CASE blocks

Open
#25,977 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp, sql
Domain
backend, databases

Research direction

The issue names no source file, test, or entry point. Begin by tracing EF Core's query translation handling for SQL CASE nullability, including nested CASE expressions; done means the optimization is applied only to later clauses without nested nullability information leaking outward.

Written by the indexing model from the issue text.

Description

area-query

We can optimize some case block for nullability. Namely, when in WHEN block we check for a column being null, we can guarantee that for any subsequent WHEN/THEN/ELSE clauses that column is not null.

CASE
    WHEN a = NULL 
        THEN f1(a, b) -- can't optimize here
    WHEN c = NULL 
        THEN f2(a, b, c) -- a can't be null here
    ELSE f3(a, b, c) -- a and c can't be null here
END

we need to make sure we properly handle the nullable column information in case of nested CASE blocks
e.g. if f2 is some complicated CASE block that itself checks for b == null we don't want that to bleed into the ELSE block that tests for f3

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.