Skip to content

Zero-pad fixed-length binary fields #401

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

Merged
merged 1 commit into from
Jun 3, 2023

Conversation

oseemann
Copy link
Contributor

MySQL is zero-padding fixed-length binary fields [1], but is not storing trailing zeros to the binlog. Consequently, when reading values of fixed-length binary fields, the value must be padded with zeros up to the specified length.

The test_fixed_length_binary test case exemplifies the issue. varbinary columns are not padded and not affected.

This commit extends the information_schema query in __get_table_information to fetch information about the length limitation of the field and stores this information in the fixed_binary_length attribute of Column instances.

Upon decoding of binary fields (which share the same binlog field type value of 254 as strings), the value is zero padded at the end, when it does not meet the specified length as retrieved from the information schema.

I've been running a fork with the fix against our fleet of ~100 mysql servers (5.7 and 8.0) for over a week now, with countless transactions. There are no indications of problems and the trailing whitespace problem is indeed fixed. Most frequent case are UUID fields that are stored as binary(16) and where 1 out of ~256 records would miss the trailing zero. Those cases are all fixed with this patch.

Fixes #400.

[1] https://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html

MySQL is zero-padding fixed-length binary fields [1], but is not storing
trailing zeros to the binlog. Consequently, when reading values of
fixed-length binary fields, the value must be padded with zeros up to
the specified length.

The `test_fixed_length_binary` test case exemplifies the issue.
`varbinary` columns are not padded and not affected.

This commit extends the `information_schema` query in
`__get_table_information` to fetch information about the length
limitation of the field and stores this information in the
`fixed_binary_length` attribute of `Column` instances.

Upon decoding of binary fields (which share the same binlog field type
value of `254` as strings), the value is zero padded at the end, when it
does not meet the specified length as retrieved from the information
schema.

Fixes julien-duponchelle#400.

[1] https://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html
@julien-duponchelle
Copy link
Owner

Thanks I 'm going to merge that !

@julien-duponchelle julien-duponchelle merged commit d215ee7 into julien-duponchelle:main Jun 3, 2023
@oseemann oseemann deleted the issue-400 branch June 3, 2023 20:44
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.

Trailing zeros in fixed-length binary fields are dropped
2 participants