UUID performance in MySQL?

前端 未结 9 1456
猫巷女王i
猫巷女王i 2020-11-27 10:14

We\'re considering using UUID values as primary keys for our MySQL database. The data being inserted is generated from dozens, hundreds, or even thousands of remote computer

9条回答
  •  余生分开走
    2020-11-27 10:46

    Something to take into consideration is that Autoincrements are generated one at a time and cannot be solved using a parallel solution. The fight for using UUIDs eventually comes down to what you want to achieve versus what you potentially sacrifice.

    On performance, briefly:

    A UUID like the one above is 36 characters long, including dashes. If you store this VARCHAR(36), you're going to decrease compare performance dramatically. This is your primary key, you don't want it to be slow.

    At its bit level, a UUID is 128 bits, which means it will fit into 16 bytes, note this is not very human readable, but it will keep storage low, and is only 4 times larger than a 32-bit int, or 2 times larger than a 64-bit int. I will use a VARBINARY(16) Theoretically, this can work without a lot of overhead.

    I recommend reading the following two posts:

    • Brian "Krow" Aker's Idle Thoughts - Myths, GUID vs Autoincrement
    • To UUID or not to UUID ?

    I reckon between the two, they answer your question.

提交回复
热议问题