Skip to content

Cleanup | Remove unused UDT serialization code #3462

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

edwardneal
Copy link
Contributor

Description

This sits alongside #3423. Where the earlier PR widens test coverage of the UDT serialization logic, this one simplifies conditions which are constant at runtime. The two primary variables here are _isTopLevelUdt and _skipNormalize.

_isTopLevelUdt is a readonly variable, which is set in the sole BinaryOrderedUdtNormalizer constructor to a hardcoded value of true. There are then a set of if conditions which test if the variable is false, and which will thus never be called. This PR removes these. The ripple effects of these result in the _padBuffer and _nullInstance variables never being set (and the IsNullable property never being referenced.) These members are also removed.

_skipNormalize is another variable, this time defined on the Normalizer base class. It is only ever set to false, and thus every condition which tests if it is false will succeed. This PR removes the test and runs the code unconditionally.

This accounts for the bulk of the changes. There is one parameter on the constructor to BinaryOrderedUdtNormalizer which is never used, a comment which is incorrect, a call to GetFormat which discards the result, and several fields on SqlUdtInfo which are written to, but never read.

Review of the wider area will highlight some code paths (such as the Size property) which remain unused. There are also quirks such as the use of a per-thread type cache, the implementation of the non-generic IComparable interface, significant numbers of heap allocations, and likely others. The next set/sets of changes will resolve these, so I've deliberately left these alone to keep this PR focused on the removal of dead code paths.

Issues

None.

Testing

All tests pass. I've also tested against the new tests in #3423, and these also pass.

This always holds the constant value of true. Code paths which rely on it being false will never be called.
IsNullable and _padBuffer were only referenced when _isTopLevelUdt was false.
_nullInstance was only referenced from IsNullable
This was always set to false
These fields are assigned to, but never used
SqlConnection.GetBytes output a Format parameter which was never used at its call sites
@edwardneal edwardneal requested a review from a team as a code owner July 6, 2025 20:36
@cheenamalhotra
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.

Project coverage is 60.16%. Comparing base (dc75c40) to head (528ca00).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...c/Microsoft/Data/SqlClient/Server/SqlNormalizer.cs 0.00% 41 Missing ⚠️
.../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs 0.00% 1 Missing ⚠️
...nt/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs 0.00% 1 Missing ⚠️
...ient/src/Microsoft/Data/SqlClient/Server/SqlSer.cs 0.00% 1 Missing ⚠️
...Client/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (dc75c40) and HEAD (528ca00). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (dc75c40) HEAD (528ca00)
addons 1 0
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3462      +/-   ##
==========================================
- Coverage   65.44%   60.16%   -5.28%     
==========================================
  Files         280      274       -6     
  Lines       62386    62007     -379     
==========================================
- Hits        40828    37308    -3520     
- Misses      21558    24699    +3141     
Flag Coverage Δ
addons ?
netcore 63.34% <0.00%> (-3.68%) ⬇️
netfx 62.34% <0.00%> (-6.86%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants