Best way to handle large (UUID) as a MySQL table primary key

前端 未结 3 1872
后悔当初
后悔当初 2020-12-16 01:48

I have a UUID string that I want to use as my MySQL tables primary key, the UUID is a 32 character hexadecimal string (after \'-\' characters are stripped). Due to the fact

相关标签:
3条回答
  • 2020-12-16 02:08

    For most cases it is best to store UUIDs/GUIDs as BINARY(16). See these related StackOverflow questions:

    • UUID Performance in MySQL
    • How to Store UUID as Number

    The conversion can (and probably should) be done in MySQL instead of PHP so whether you're using a 32bit PHP client or 64bits doesn't matter a bit (pun intended :P)

    0 讨论(0)
  • 2020-12-16 02:08

    It depends on storage engine also. TokuDB should handle all these problems.

    0 讨论(0)
  • 2020-12-16 02:17

    Use a string type, not an integer. Better is only better if it solves a problem.

    If you're really concerned about lookup speed, use a synthetic (auto increment) primary key. You can place a unique constraint on the UUID column, and use it only once to look up the synthetic key which is subsequently used for your joins etc.

    0 讨论(0)
提交回复
热议问题