UUID performance in MySQL?

前端 未结 9 1483
猫巷女王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:59

    The short answer is that many databases have performance problems (in particular with high INSERT volumes) due to a conflict between their indexing method and UUIDs' deliberate entropy in the high-order bits. There are several common hacks:

    • choose a different index type (e.g. nonclustered on MSSQL) that doesn't mind it
    • munge the data to move the entropy to lower-order bits (e.g. reordering bytes of V1 UUIDs on MySQL)
    • make the UUID a secondary key with an auto-increment int primary key

    ... but these are all hacks--and probably fragile ones at that.

    The best answer, but unfortunately the slowest one, is to demand your vendor improve their product so it can deal with UUIDs as primary keys just like any other type. They shouldn't be forcing you to roll your own half-baked hack to make up for their failure to solve what has become a common use case and will only continue to grow.

提交回复
热议问题