Index sizes in MySQL

核能气质少年 提交于 2019-12-23 08:58:59

问题


I am just starting to investigate optimization for my MySQL database. From what I'm reading, indexing seems like a good idea - so I am wanting to create an index on one of my VARCHAR columns, on a table using the MyISAM engine.

From what I'm reading, I understand that an index is limited to a size of 1,000 bytes. A VARCHAR character is 3 bytes in size, though. Does that mean that if I want to index a VARCHAR column with 50 rows, I need an index prefix of 6 characters? (1,000 bytes / 50 rows / 3 bytes per character = 6.66)

If so, that seems a little comiplicated - which is why I'm questioning my understanding. It seems pretty odd that you would only be able to index 333 rows in a VARCHAR column, using a prefix of 1 character.

Am I missing something?


回答1:


From what I've read, I understand that an index is limited to a size of 1000 bytes.

Index key length is limited to 1000 bytes in MyISAM, 767 bytes in InnoDB (per column).

This means that you cannot index a single UTF8 column more than 333 characters long in a MyISAM table (when calculating the max index size, MySQL assumes 3 bytes per character, though actual length may be much smaller)

You can create as many indexed records as you need.




回答2:


I think its meant the varchar width. If the index max size is 1000 bytes and a varchar is 3 bytes long then the max indexable size would be 1000/3.



来源:https://stackoverflow.com/questions/2599708/index-sizes-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!