Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL multicolumn primary key

Tags:

mysql

What is the maximum columns number for a multicolumn primary key (MySQL)? Does it depend on column data type or engine?

like image 216
Maksym Polshcha Avatar asked Oct 11 '12 11:10

Maksym Polshcha


1 Answers

Yes, it depends on storage engine.

  • MyISAM:

    The maximum number of columns per index is 16. The maximum key length is 1000 bytes. This can also be changed by changing the source and recompiling. For the case of a key longer than 250 bytes, a larger key block size than the default of 1024 bytes is used.

  • InnoDB:

    The InnoDB internal maximum key length is 3500 bytes, but MySQL itself restricts this to 3072 bytes. This limit applies to the length of the combined index key in a multi-column index.

like image 119
Devart Avatar answered Oct 22 '22 21:10

Devart