| Bug #23069 | Too long UNIQUE indices allowed in InnoDB | ||
|---|---|---|---|
| Submitted: | 7 Oct 2006 10:46 | Modified: | 6 Dec 2006 14:31 |
| Reporter: | Oli Sennhauser | Email Updates: | |
| Status: | Verified | Impact on me: | |
| Category: | MySQL Server: DDL | Severity: | S3 (Non-critical) |
| Version: | 5.0.18, 5.0.24, 5.0.27-BK | OS: | Linux (Linux) |
| Assigned to: | CPU Architecture: | Any | |
[7 Oct 2006 10:46]
Oli Sennhauser
[7 Oct 2006 11:59]
Valeriy Kravchuk
Thank you for a bug report. Verified just as described with 5.0.27-BK on Linux.
mysql> CREATE TABLE `test` (
-> `id` int(11) NOT NULL auto_increment,
-> `data` varchar(255) default NULL,
-> PRIMARY KEY (id, data)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.12 sec)
mysql> insert into test values(1, rpad('a', 255, 'a'));
Query OK, 1 row affected (0.01 sec)
mysql> drop table test;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE `test` ( `id` int(11) NOT NULL auto_increment, `data` v
archar(256) default NULL, PRIMARY KEY (id, data) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 765 bytes
The reason may be default COMPACT format for InnoDB rows (http://dev.mysql.com/doc/refman/5.0/en/innodb-physical-record.html), where NULL columns are not stored, but as ID is declared as NOT NULL, it is still a bug (or, at least, requires proper documentation).
[9 Oct 2006 13:58]
Heikki Tuuri
Oli,
InnoDB does allow keys up to 3500 bytes in length. But the MySQL interpreter restricts the maximum key length.
The question is why MySQL does allow a unique key longer than a primary key.
I am reclassifying this as a Server bug.
Regards,
Heikki
ha_innodb.h:
uint max_supported_key_length() const { return 3500; }
uint max_supported_key_part_length() const;
##################################
dict0mem.h in 5.0:
/* DICT_MAX_INDEX_COL_LEN is measured in bytes and is the max index column
length + 1. Starting from 4.1.6, we set it to < 3 * 256, so that one can
create a column prefix index on 255 characters of a TEXT field also in the
UTF-8 charset. In that charset, a character may take at most 3 bytes. */
#define DICT_MAX_INDEX_COL_LEN 768
########################
ha_innodb.cc in 5.0:
uint
ha_innobase::max_supported_key_part_length() const
{
return(DICT_MAX_INDEX_COL_LEN - 1);
}
