MySQL multicolumn primary key

后端 未结 2 569
故里飘歌
故里飘歌 2021-01-17 21:36

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

2条回答
  •  一整个雨季
    2021-01-17 22:05

    I found this:

    someone tried to create a PK with 2 columns and received this error:
    "Specified key was too long; max key length is 1024 bytes" so it looks that the maximum it's 1024 bytes, it doesn't matter the columns number what really matter is the var type and the space assign it.

    I have seen some examples like this:

    create table OS_PROPERTYENTRY (entity_name VARCHAR(125) not null, entity_id BIGINT not null,
    
    entity_key VARCHAR(255) not null date_val DATETIME, primary key (entity_name, entity_id, entity_key))
    

    where

    125 * (3 bytes) + 255 * (3 bytes) + 1 * (8 bytes) = 1148 bytes. So it's not possible to create a PK.

    take a look here, they talk about it: https://jira.atlassian.com/browse/CONF-2783

提交回复
热议问题