UUID performance in MySQL?

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

    I tend to avoid UUID simply because it is a pain to store and a pain to use as a primary key but there are advantages. The main one is they are UNIQUE.

    I usually solve the problem and avoid UUID by using dual key fields.

    COLLECTOR = UNIQUE ASSIGNED TO A MACHINE

    ID = RECORD COLLECTED BY THE COLLECTOR (auto_inc field)

    This offers me two things. Speed of auto-inc fields and uniqueness of data being stored in a central location after it is collected and grouped together. I also know while browsing the data where it was collected which is often quite important for my needs.

    I have seen many cases while dealing with other data sets for clients where they have decided to use UUID but then still have a field for where the data was collected which really is a waste of effort. Simply using two (or more if needed) fields as your key really helps.

    I have just seen too many performance hits using UUID. They feel like a cheat...

提交回复
热议问题