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

gordon chung gord at live.ca
Wed Apr 5 15:02:14 UTC 2017



On 05/04/17 09:00 AM, Monty Taylor wrote:
>
> Please do NOT use uuid as a primary key in MySQL:
>
> * UUID has 36 characters which makes it bulky.

you can store it as a binary if space is a concern.

> * 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.

can store a ordered uuid (uuid1) for performance but arguably not much 
diff from just autoincrement

>
> 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.

very good points. i guess ultimately should probably just test to the 
scale you hope for

cheers,

-- 
gord


More information about the OpenStack-dev mailing list