[openstack-dev] [Zun]Use 'uuid' instead of 'id' as object ident in data model

Monty Taylor mordred at inaugust.com
Wed Apr 5 13:00:24 UTC 2017


On 02/21/2017 07:28 AM, gordon chung wrote:
>
>
> On 21/02/17 01:28 AM, Qiming Teng wrote:
>>> in mysql[2].
>> Can someone remind me the benefits we get from Integer over UUID as
>> primary key? UUID, as its name implies, is meant to be an identifier for
>> a resource. Why are we generating integer key values?
>
> this ^. use UUID please. you can google why auto increment is a probably
> not a good idea.
>
> from a selfish pov, as gnocchi captures data on all resources in
> openstack, we store everything as a uuid anyways. even if your id
> doesn't clash in zun, it has a higher chance of clashing when you
> consider all the other resources from other services.
>
> cheers,
>

sorry - I just caught this.

Please do NOT use uuid as a primary key in MySQL:

* UUID has 36 characters which makes it bulky.
* InnoDB stores data in the PRIMARY KEY order and all the secondary keys 
also contain PRIMARY KEY. So having UUID as PRIMARY KEY makes the index 
bigger which can not be fit into the memory
* Inserts are random and the data is scattered.

In cases where data has a large natural key (like a uuid) It is 
considered a best practice to use an auto-increment integer as the 
primary key and to put a second column in the table to store the uuid, 
potentially with a unique index applied to it for consistency.

That way the external identifier for things like gnocchi can still be 
the UUID, but the internal id for the database can be an efficient 
auto-increment primary key.




More information about the OpenStack-dev mailing list