Bug #6604 | mysql Error: 1071 (Specified key was too long; max key length is 1000 bytes) | ||
---|---|---|---|
Submitted: | 13 Nov 2004 12:28 | Modified: | 14 Nov 2004 18:54 |
Reporter: | Bent Vangli | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: MyISAM storage engine | Severity: | S2 (Serious) |
Version: | 4.1.7 | OS: | Linux (Linux (Fedora Core 2)) |
Assigned to: | Matthew Lord | CPU Architecture: | Any |
[13 Nov 2004 12:28]
Bent Vangli
[14 Nov 2004 18:54]
Matthew Lord
Hi, Thanks for your bug report! This is not a bug, it is a stated limitation. From the manual page: http://dev.mysql.com/doc/mysql/en/CREATE_INDEX.html "Prefixes can be up to 255 bytes long (or 1000 bytes for MyISAM and InnoDB tables as of MySQL 4.1.2). Note that prefix limits are measured in bytes, whereas the prefix length in CREATE INDEX statements is interpreted as number of characters. Take this into account when specifying a prefix length for a column that uses a multi-byte character set." You are correct, it is the utf8 that is causing the extra bytes. Try creating the table this way: CREATE TABLE phpgw_lang ( lang varchar(5) NOT NULL DEFAULT '', app_name varchar(100) NOT NULL DEFAULT 'common', message_id varchar(255) NOT NULL DEFAULT '', content text, PRIMARY KEY(lang,app_name(75),message_id(100)) ); This will index the first 75 and 100 chars from the columns which should work and be faster in general as well. Best Regards
[15 Nov 2004 19:19]
Bent Vangli
Hi Mattthew Thanks a lot. When I see your answer, it is so obvious that it's a shame I didn't see it my self. :-}. It is then very easy to adjust the length of the prefix field taking into account the length of UTF8 characters. MySQL rocks :-)) Best regards Bent Vangli Oslo, Norway
[24 Dec 2007 15:09]
Bruno Leon
Hi, I think quotes around the PRIMARY KEY are needed if we specify a number of characters. Something like CREATE TABLE phpgw_lang ( lang varchar(5) NOT NULL DEFAULT '', app_name varchar(100) NOT NULL DEFAULT 'common', message_id varchar(255) NOT NULL DEFAULT '', content text, PRIMARY KEY(lang,`app_name`(75),`message_id`(100)) );