Bug #66493 description about length-coded-binary of MySQL Protocol
Submitted: 22 Aug 2012 8:05 Modified: 30 Aug 2012 15:15
Reporter: huihua zhang Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Stefan Hinz CPU Architecture:Any

[22 Aug 2012 8:05] huihua zhang
Description:
http://dev.mysql.com/doc/internals/en/elements.html

Value Of     # Of Bytes  Description
  First Byte   Following
  ----------   ----------- -----------
  0-250        0           = value of first byte
  251          0           column value = NULL
                           only appropriate in a Row Data Packet
  252          2           = value of following 16-bit word
  253          4           = value of following 32-bit word
  254          8           = value of following 64-bit word

when First Byte is 253 length-coded-binary should be followed by 3 bytes, which description should be "value of following 24-bit word".

As "The relevant MySQL source program is sql/protocol.cc net_store_length()." says, net_store_length() defined as follows, which is actually defined in sql-common/pack.c:97:

uchar *net_store_length(uchar *packet, ulonglong length)
{
  if (length < (ulonglong) LL(251))
  {
    *packet=(uchar) length;
    return packet+1;
  }
  /* 251 is reserved for NULL */
  if (length < (ulonglong) LL(65536))
  {
    *packet++=252;
    int2store(packet,(uint) length);
    return packet+2;
  }
  if (length < (ulonglong) LL(16777216))
  {
    *packet++=253;
    int3store(packet,(ulong) length);
    return packet+3;
  }
  *packet++=254;
  int8store(packet,length);
  return packet+8;
}

ps. 16777216= 2^24

How to repeat:
the wrong description about length-coded-binary is here at http://dev.mysql.com/doc/internals/en/elements.html

Suggested fix:
http://dev.mysql.com/doc/internals/en/elements.html

Value Of     # Of Bytes  Description
  First Byte   Following
  ----------   ----------- -----------
  0-250        0           = value of first byte
  251          0           column value = NULL
                           only appropriate in a Row Data Packet
  252          2           = value of following 16-bit word
  253          3           = value of following 24-bit word
  254          8           = value of following 64-bit word
[22 Aug 2012 8:27] Valeriy Kravchuk
Thank you for the documentation request.
[30 Aug 2012 15:15] Stefan Hinz
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 products.