简体   繁体   中英

Right choice of data type for UUID as primary key

Prior Conditions are

  1. Table will have data in billions
  2. Table will have secondary indexes
  3. Table's primary key will be a foreign key of another table.
  4. Table will have a heavy data (another column may be Text).

Primary Key must be Unique, cause my database is replicated over machine's that's why I am choosing UUID.

PS: space is also a concern so I guess Varchar(36) might be the bad idea

I agree with BINARY(16) . (16 bytes is better than 37.)

But UUIDs are hopelessly inefficient for huge tables. (I assume your billion-row table will not fit in RAM.)

I discuss those and more issues in http://mysql.rjweb.org/doc.php/uuid

I would go for BINARY(16). If you want to use CHAR then CHAR(32) is large enough without the hyphens, but BINARY is smaller and faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM