[release/10.0] Correct COALESCE logic for DefaultIfEmpty (#37233) #37237
+341
−5
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.
Backports #37233
Closes #37178
Description
10.0 contained various bug fixes to EF's DefaultIfEmpty() LINQ operator translation. One of these bugfixes required making changes to how COALESCE() is added for non-nullable value types, where we need to return the CLR default (e.g. zero for int) rather than NULL. Unfortunately, to determine whether the return value is a non-nullable value type, an incorrect type was consulted in the SQL tree, which indicates a non-nullable value type even when the returned value is in fact a nullable value type.
Customer impact
In cases where DefaultIfEmpty() is used over a nullable value type, NULL is not returned as expected, but rather than CLR default.
This is a data corruption bug, indicating that there's data in the database (zero), where in fact there's no data (and NULL should be returned).
How found
Customer reported on 10.0.0
Regression
Yes, from 9.0.
Testing
Added.
Risk
Low, very targeted fix (most code in this PR only flows information in, actual behavioral change is a one-liner). Quirk added.