Skip to content
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

[release/8.0] Fix to #33547 - Breaking Change in 8.0.4: System.InvalidOperationException: The data is NULL at ordinal 0. This method can't be called on NULL values. Check using IsDBNull before calling. #33692

Merged
merged 1 commit into from
May 9, 2024

Conversation

maumar
Copy link
Contributor

@maumar maumar commented May 9, 2024

Port of #33559
Fixes #33547

Description
Problem was that we changed the way that we store complex type information in the StructuralTypeProjectionExpression, specifically after performing pushdown. We used to extract all the properties from complex types into a flat list, along with regular properties, but that was wrong - we need to uphold the nested structure. If that STPE with flattened structure would be made nullable, we go through all the properties and mark the column expressions as nullable (which included properties of a complex type). However, in the new regime, we were not making those changes to columns representing complex type in the nested structure. As a result, if those columns were later projected (after pushdown), they would seem to be non-nullable, and could cause errors.
Fix is, during MakeNullable() operation for a complex type StructuralTypeProjectionExpression, to peek inside it's ValueBufferExpression and mark all the columns found there as nullable.

Customer impact

Queries projecting a non-optional property from an optional complex type via pushdown will fail. Workaround is to manually cast the property to nullable (which seems redundant) and is not always easy/possible without significant query rewrite.

How found
Customer reported on 8.

Regression
Yes, moreover, regression has been introduced in a patch 8.0.4 patch release. (by a high impact, medium risk fix - #33212)

Testing
Multiple tests added.

Risk
Low. Change is straightforward invoking an existing functionality of a StructuralTypeProjectionExpression to make it's subcomponents nullable (like we should have done already). We apply similar logic in other places of the code. Added quirk just to be safe.

…ption: The data is NULL at ordinal 0. This method can't be called on NULL values. Check using IsDBNull before calling.

Problem was that we changed the way that we store complex type information in the StructuralTypeProjectionExpression, specifically after performing pushdown. We used to extract all the properties from complex types into a flat list, along with regular properties, but that was wrong - we need to uphold the nested structure. If that STPE with flattened structure would be made nullable, we go through all the properties and mark the column expressions as nullable (which included properties of a complex type). However, in the new regime, we were not making those changes to columns representing complex type in the nested structure. As a result, if those columns were later projected (after pushdown), they would seem to be non-nullable, and could cause errors.

Fix is, during MakeNullable() operation for a complex type StructuralTypeProjectionExpression, to peek inside it's ValueBufferExpression and mark all the columns found there as nullable.

Fixes #33547
@maumar maumar requested review from a team and roji May 9, 2024 01:46
@maumar maumar added this to the 8.0.x milestone May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants