1、當(dāng)innodb_large_prefix為off活玲,單列索引的長度限制為767涣狗。
show variables like 'innodb_large_prefix';
| innodb_large_prefix | OFF |
字符集為utf8,單列varchar(255)是可以創(chuàng)建索引的上限舒憾,256即報(bào)錯(cuò)镀钓。
create table t2(name varchar(255));
alter table t2 add index n1(name);
create table t3(name varchar(256));
alter table t3 add index n1(name);
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
2、修改innodb_large_prefix為on镀迂。
set global innodb_large_prefix=1;
show variables like 'innodb_large_prefix';
| innodb_large_prefix | ON |
3丁溅、varchar(256)是否能夠建索引與表的row_format有關(guān)。
當(dāng)表的row_format為Compact,單列索引的上限仍然是767。
alter table t3 add index n1(name);
ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.
當(dāng)表的row_format為Compressed僚楞,單列索引的上限是3072偎行。
alter table t3 row_format=compressed key_block_size=8;
alter table t3 add index n1(name);
4、一張表的FILE_FORMAT和ROW_FORMAT
更改一張表的row_format同時(shí)也更改了這張表的file_format领虹。Compact必定是Antelope(羚羊)规哪,dynamic和Compressed必定是Barracuda(梭魚)。
select * from information_schema.innodb_sys_tables where name like '%t1%';