Bug #117736 varchar length prefix plus data description is not correct
Description:
Regarding the prefix plus data of varchar(https://dev.mysql.com/doc/refman/8.0/en/char.html) in the document:
> In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
There is data in the following table:
create table t20250318_varchar(c1 varchar(300) primary key);
insert into t20250318_varchar values('1234567890');
parse IBD file, VARCHAR values are stored as a 1-byte length prefix plus data. (10<128)
example:
>>> import struct
>>> f = open('/data/db1/t20250318_varchar.ibd','rb')
>>> f.seek(4*16384,0)
65536
>>> data = f.read(16384)
>>> offset = struct.unpack('>h',data[97:99])[0] + 99
>>> data[offset-5-2:offset]
b'm\n\x00\x00\x10\xff\xf2'
>>> data[offset:offset+10]
b'1234567890'
>>> struct.unpack('>B',b'\n')[0]
10
How to repeat:
-- SQL
create table t20250318_varchar(c1 varchar(300) primary key);
insert into t20250318_varchar values('1234567890');
-- python
import struct
f = open('/data/db1/t20250318_varchar.ibd','rb')
f.seek(4*16384,0)
data = f.read(16384)
offset = struct.unpack('>h',data[97:99])[0] + 99
data[offset-5-2:offset]
data[offset:offset+10]
Suggested fix:
So, I think it should be described as:
In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, 1-byte or 2-byte if values may require more than 255 bytes.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.