UUID and database primary key

UUID

uuid is a string randomly generated by network card MAC address, timestamp, namespace, random or pseudo-random number, timing and other factors. There are 128 bits, and the coincidence probability is 2 to the 128th power.

Unique

I suddenly thought of using uuid as the primary key of the database.

  • Can guarantee global uniqueness
  • Can be generated in a distributed manner
  • Unordered insertion can avoid lock contention
  • You can't guess it, it's safe
  • Easy to merge and migrate

But there are also some problems

  • Large storage overhead
  • The performance is not as high as the auto-increment ID
  • Manually searching data based on id is difficult
  • The generation efficiency may be poor
  • Creation order cannot be determined by id

Guess you like

Origin blog.csdn.net/majiayu000/article/details/132491114