Repository navigation
Propagate column nullability from failed CASE tests to later clauses - #39660
Merged
Merged
Conversation
When a WHEN test made of null checks fails, the checked columns' nullability is known for the following WHEN clauses and the ELSE result, so comparisons there no longer need the full null-semantics expansion. Also restore the null-value columns list with its own count after each clause. Fixes dotnet#36293
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A moderate nullability bug remains because failed IS NOT NULL facts are not propagated to later WHEN clauses, and the missing regression coverage leaves this behavior unverified.
2 open issues
What changed in this PR
This pull request improves relational SQL nullability propagation across searched CASE clauses, reducing redundant null-semantics compensation in later branches and updating affected query baselines. The failed IS NOT NULL propagation path still does not affect later clause processing and lacks regression coverage.
Changes:
- Propagates nullability facts from failed
WHENpredicates to subsequent clauses. - Corrects restoration of null-value column tracking between clauses.
- Adds shared regression tests and updates SQL Server, SQLite, temporal, and navigation query baselines.
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/Query/TemporalComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs | Updates temporal SQL Server baselines affected by simplified CASE nullability handling. |
| test/EFCore.SqlServer.FunctionalTests/Query/NullSemanticsQuerySqlServerTest.cs | Adds SQL Server baselines for new nullability propagation tests and updates affected null-semantics SQL. |
| test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsCollectionsSharedTypeQuerySqlServerTest.cs | Updates a complex-navigation SQL Server baseline affected by the CASE optimization. |
| test/EFCore.Sqlite.FunctionalTests/Query/SpatialQuerySqliteTest.cs | Updates the SQLite spatial CASE baseline to reflect the revised generated SQL. |
| test/EFCore.Relational.Specification.Tests/Query/NullSemanticsQueryTestBase.cs | Adds shared regression tests for propagating nullability facts through conditional expressions. |
| src/EFCore.Relational/Query/SqlNullabilityProcessor.cs | Propagates nullability facts across failed searched-CASE clauses and fixes restoration of null-value column tracking. |
Review effort: Lite
Null value columns are only consumed within the OrElse that added them, so recording them for a failed CASE test had no effect.
AndriySvyryd
approved these changes
Nov 19, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
Contributor
Author
|
Thanks @AndriySvyryd for the review! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes #36293
Problem
SqlNullabilityProcessor.VisitCasepasses what aWHENtest tells about column nullability to that clause'sTHENresult, but not to the clauses after it. When a test such asx IS NULLfails,xis known to be non-null in all the laterWHENtests, results and theELSEresult. Without that, comparisons there get the full null-semantics expansion, which SQL Server can't optimize away (see the plans in the issue):Before:
After:
Change
WHENclause of a searchedCASE, the null checks in its test are recorded as facts for the clauses that follow:x IS NULLmeansxis non-null;x IS NOT NULLmeansxis null;ORmeans every one of its operands failed.Tests
Added to
NullSemanticsQueryTestBase, with SQL Server baselines:Nullable_column_info_propagates_to_else_of_conditionalNullable_column_info_propagates_to_else_of_conditional_in_predicateNullable_column_info_propagates_to_later_clauses_of_conditionalExisting baselines that get simpler SQL as a result:
Is_null_on_column_followed_by_OrElse_optimizes_nullability_conditional(and its_multiple,_nested,_with_setupvariants)LeftJoin_with_Any_on_outer_source_and_projecting_collection_from_inner(SQL Server and temporal)