Home >Database >Mysql Tutorial >How Does MySQL Handle VARCHAR Index Length for UTF-8 Columns?
Understanding MySQL varchar Index Length for UTF-8 Columns
In MySQL, the index length for a varchar(n) column is specified in characters, not bytes. However, MySQL assumes that each UTF-8 character occupies 3 bytes. This means that for a varchar column with a specified index length of n, the actual maximum number of bytes that can be indexed is 3n.
To break it down:
Impact on Index Size for UTF-8 Columns
Based on the assumption of 3 bytes per character, MySQL imposes a practical limit on the index size for varchar columns with the UTF-8 character set.
Consideration for Dynamic and Compressed Row Formats
In MySQL versions 8.0 and above, you can potentially increase the maximum index size for varchar columns in InnoDB tables using the DYNAMIC or COMPRESSED row formats. These row formats allow for longer prefix lengths, effectively increasing the index size limit. However, this optimization is not supported for earlier MySQL versions, including 5.5.27.
Recommendation for Index Design
When designing indexes for varchar columns with the UTF-8 character set, it's recommended to:
The above is the detailed content of How Does MySQL Handle VARCHAR Index Length for UTF-8 Columns?. For more information, please follow other related articles on the PHP Chinese website!