TagCloud

Tuesday, October 23, 2012

MySQL innodb_large_prefix




 innodb_large_prefix
Version Introduced5.5.14
Command-Line Format--innodb_large_prefix
Option-File Formatinnodb_large_prefix
Option Sets VariableYes, innodb_large_prefix
Variable Nameinnodb_large_prefix
Variable ScopeGlobal
Dynamic VariableYes
Permitted Values
Typeboolean
DefaultOFF


Enable this option to allow index key prefixes longer than 767 bytes (up to 3072 bytes), for InnoDB tables that use the DYNAMIC and COMPRESSED row formats. (Creating such tables also requires the option valuesinnodb_file_format=barracuda and innodb_file_per_table=true.) See Section 14.2.8, “Limits on InnoDBTables” for the relevant maximums associated with index key prefixes under various settings.
For tables using the REDUNDANT and COMPACT row formats, this option does not affect the allowed key prefix length. It does introduce a new error possibility. When this setting is enabled, attempting to create an index prefix with a key length greater than 3072 for a REDUNDANT or COMPACT table causes an errorER_INDEX_COLUMN_TOO_LONG (1727).

mysql innodb 에서 varchar() 타입의 컬럼에 PK를 지정할 경우 인덱스길이의 제한으로 인하여 최대 길이는 latin1 일때 767, euckr일때 383(한글의 경우 2바이트), utf8일때 255(3바이트) 의 제약이 존재한다.

innodb_large_prefix 를 ON 할 경우, 최대 3072 길이까지 사용이 가능하지만 테이블 생성시 row formats 을 DYNAMIC , COMPRESSED 로 지정헤야 한다. (테이블 생성시 innodb_file_format=barracuda, innodb_file_per_table=true 로 지정해야함)

nutch 2.x 에서 mysql 사용시 reversed url 이 PK 컬럼인 id 로 사용되는데 utf8 로 컬럼을 사용할 경우 길이제약 문제가 해결됨

관련하여  my.cnf 파일의 설정은 아래와 같다.

character-set-server = utf8
collation-server = utf8_unicode_ci
innodb_large_prefix = true
innodb_file_format = Barracuda
innodb_file_per_table = true

아래와 같이 확인

show variables like "innodb_file%";
show variables like "innodb_large%";





참고 :
http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_large_prefix
http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_file_format
http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_file_per_table