Why do so many developers set varchar to 254 and not 255 when creating MySQL tables?
为什么许多开发人员在创建MySQL表时将varchar设置为254而不是255 ?
Proof that this happens: mysql varchar 254
这一点的证明:mysql varchar 254
2 个解决方案
#1
6
varchar fields require n+1 bytes for fields less than or equal to 255 and required n+2 bytes for fields > 255
varchar字段对于小于或等于255的字段需要n+1字节,对于字段> 255需要n+2字节
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
It should be set to 255, I'm assuming developers think they will save an extra byte from 254, but 255 is the standard
它应该设置为255,我假设开发人员认为他们会从254节省一个字节,但是255是标准
#2
12
Your Google query gave you the hints already. One of the first hits is this:
您的谷歌查询已经给出了提示。第一个热门话题是:
https://www.vbulletin.com/forum/project.php?issueid=32655
https://www.vbulletin.com/forum/project.php?issueid=32655
It basically says, that FULLTEXT
indexes on VARCHAR(255)
require twice the space of a VARCHAR(254)
FULLTEXT index. And some more other bloat on top of that.
它基本上说,VARCHAR(255)上的全文索引需要VARCHAR(254)的两倍空间。除此之外,还有一些其他的膨胀。
I think this is far more important than saving one byte in the data table.
我认为这比在数据表中保存一个字节要重要得多。
#1
6
varchar fields require n+1 bytes for fields less than or equal to 255 and required n+2 bytes for fields > 255
varchar字段对于小于或等于255的字段需要n+1字节,对于字段> 255需要n+2字节
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
It should be set to 255, I'm assuming developers think they will save an extra byte from 254, but 255 is the standard
它应该设置为255,我假设开发人员认为他们会从254节省一个字节,但是255是标准
#2
12
Your Google query gave you the hints already. One of the first hits is this:
您的谷歌查询已经给出了提示。第一个热门话题是:
https://www.vbulletin.com/forum/project.php?issueid=32655
https://www.vbulletin.com/forum/project.php?issueid=32655
It basically says, that FULLTEXT
indexes on VARCHAR(255)
require twice the space of a VARCHAR(254)
FULLTEXT index. And some more other bloat on top of that.
它基本上说,VARCHAR(255)上的全文索引需要VARCHAR(254)的两倍空间。除此之外,还有一些其他的膨胀。
I think this is far more important than saving one byte in the data table.
我认为这比在数据表中保存一个字节要重要得多。