Each table has an .frm file that contains the table definition. The server uses the following expression to check some of the table information stored in the file against upper limit of 64KB.
which is then followed by an ad-hoc equation expressing the approximate size of a table definition.
For a simple test, in a table with a couple fields already, I got my enum up to 63136 characters long, and the .frm was 71775 bytes big (slightly larger than 70KB), so the limit is approximate. At that point, MySQL complained #1117 - Too many columns, which is misleading to say the least.
Interestingly/oddly/worthwhile to note, the character set of the enum will change the maximum length. -- even if you're using normal characters which should only require 1 byte each.
An ENUM column can have a maximum of 65,535 distinct elements. (The practical limit is less than 3000.) A table can have no more than 255 unique element list definitions among its ENUM and SET columns considered as a group.
发布评论
评论(2)
限制不在于文字字符串的长度,而在于表定义。
MySQL 文档指出
然后是一个表示表定义的近似大小的临时方程。
对于一个简单的测试,在已经有几个字段的表中,我的枚举长度达到 63136 个字符,并且 .frm 大小为 71775 字节(略大于 70KB),因此限制是近似的。此时,MySQL 抱怨
#1117 - Too much columns
,这至少可以说是具有误导性的。有趣/奇怪/值得注意的是,枚举的字符集会改变最大长度。 -- 即使您使用的是普通字符,每个字符只需要 1 个字节。
The limit isn't on the length of the literal string, but rather on the table definition.
The MySQL documentation states that
which is then followed by an ad-hoc equation expressing the approximate size of a table definition.
For a simple test, in a table with a couple fields already, I got my enum up to 63136 characters long, and the .frm was 71775 bytes big (slightly larger than 70KB), so the limit is approximate. At that point, MySQL complained
#1117 - Too many columns
, which is misleading to say the least.Interestingly/oddly/worthwhile to note, the character set of the enum will change the maximum length. -- even if you're using normal characters which should only require 1 byte each.
ENUM 列最多可以有 65,535 个不同元素。 (实际限制小于 3000。)表的 ENUM 和 SET 列(被视为一个组)之间最多可以有 255 个唯一元素列表定义。
An ENUM column can have a maximum of 65,535 distinct elements. (The practical limit is less than 3000.) A table can have no more than 255 unique element list definitions among its ENUM and SET columns considered as a group.