8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

18.2.2 键所需空间18.2.2 Space Needed for Keys

MyISAM 表使用 B 树索引。你可以大致计算索引文件的大小为 (key_length+4)/0.67,对所有键求和。这是最坏情况下的估算,即所有键按排序顺序插入且表没有压缩键时。MyISAM tables use B-tree indexes. You can roughly calculate the size for the index file as (key_length+4)/0.67, summed over all keys. This is for the worst case when all keys are inserted in sorted order and the table doesn't have any compressed keys.

字符串索引使用空格压缩。如果第一个索引部分是字符串,它也会使用前缀压缩。空格压缩使索引文件比最坏情况下更小,如果一个字符串列有很多尾随空格或者是VARCHAR列而不总是使用到其最大长度。前缀压缩用于以字符串开头的键。如果有许多字符串具有相同的前缀,前缀压缩会很有帮助。String indexes are space compressed. If the first index part is a string, it is also prefix compressed. Space compression makes the index file smaller than the worst-case figure if a string column has a lot of trailing space or is a VARCHAR column that is not always used to the full length. Prefix compression is used on keys that start with a string. Prefix compression helps if there are many strings with an identical prefix.

在MyISAM表中,你也可以通过在创建表时指定PACK_KEYS=1表选项来对数字进行前缀压缩。数字以高字节优先的方式存储,因此当你有许多整数键具有相同的前缀时,这会有帮助。In MyISAM tables, you can also prefix compress numbers by specifying the PACK_KEYS=1 table option when you create the table. Numbers are stored with the high byte first, so this helps when you have many integer keys that have an identical prefix.