Bug #18494 Malformulation in 4.1 Reference Manual, chapter 11.4.2: BINARY type
Submitted: 24 Mar 2006 17:03 Modified: 4 Apr 2006 19:55
Reporter: Andreas Krueger Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:4.1 OS:Any (any)
Assigned to: Paul DuBois CPU Architecture:Any

[24 Mar 2006 17:03] Andreas Krueger
Description:
In chapter 11.4.2 of the 3.23,4.0,4.1 Reference Manual it says

"The handling of trailing spaces is the same for BINARY and VARBINARY as it is for CHAR and VARCHAR. When BINARY values are stored, they are right-padded with spaces to the specified length. When BINARY values are retrieved, trailing spaces are removed. For VARBINARY, trailing spaces are removed when values are stored."

In the example below it is shown that actually the BINARY is right-padded with hexadecimal zeroes, also called the null-byte from C. This is not in accordance with the above claim that this type is 'right-padded with spaces'.

I DON'T KNOW OF ANY CHARACTER-SET THAT USES '\0' AS AN ENCODING FOR SPACE. IN ASCII ' ' IS ENCODED AS '\20', IN EBCDIC AS '\40', IN UNICODE ...

THEREFORE I TAKE THE FORMULATION "traling spaces" for BINARY as incorrect, at least as misleading. From the Assembler or C programmer's point of view, definitely a mistake.

Suggestion:
---------------
"The handling of trailing spaces is similar for BINARY and VARBINARY as it is for CHAR and VARCHAR. With one difference: when BINARY values are stored, they are right-padded with binary zeroes (byte value of zero) to the specified length. When BINARY values are retrieved, trailing zeroes are removed. For VARBINARY, trailing zeroes are removed when values are stored."

How to repeat:
Read chapter 11.4.2 of the 3.23,4.0,4.1 Reference Manual under dev.mysql.com/doc

Especially http://dev.mysql.com/doc/refman/4.1/en/binary-varbinary.html

also found in the downloadable PDF version
[24 Mar 2006 17:23] Valeriy Kravchuk
Thank you for a bug report. That page in documetnation should be changed.
[24 Mar 2006 22:50] Andreas Krueger
Hi,
you may also want to have a look at my comment to the 5.0 MySQL server manual at http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html#c7391.
This is potentially a real bug.
Then also the referring chapter in the 4.1 manual should be updated. Only I don' t have 4.1 installed, so I don't bother with testing it especially.
[4 Apr 2006 19:55] Paul DuBois
Thank you for your bug report. This issue has been addressed in the
documentation. The updated documentation will appear on our website
shortly, and will be included in the next release of the relevant
product(s).

Additional info:

In 4.1, BINARY is space-padded, not 0x00-padded.
Trailing spaces are significant in comparisons.