Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 321
Anand Tripathi Avatar asked Oct 14 '25 03:10

Anand Tripathi


1 Answers

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

like image 77
Rick James Avatar answered Oct 18 '25 06:10

Rick James