日期:2014-05-16  浏览次数:20539 次

varchar(n)中的n为什么要设的尽量小
主要原因有两个:
1、MySQL的一个Row的不包含Text和Blob的最大长度是65535。
如:你建一个表,存在这样两个字段:varchar(35000), varchar(48000)是无法创建的。会得到如下提示:
错误代码: 1118
Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs。


2、在进行排序和创建临时表一类的内存操作时,会使用n的长度申请内存。

如:varchar(5)和varchar(100)相比,后者申请的内存近似是前者的20倍。