13

UUID Primary IDs and MySQL

 3 years ago
source link: https://nixmash.com/mysql/uuid-primary-ids-and-mysql/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

UUID Primary IDs and MySQL – NixMashSkip to content

NixMash

NixMash

WordPress Site Management for Small Business

UUID Primary IDs and MySQL

This post from the MySQL Server Team is an interesting approach to handling UUIDs in MySQL. The primary takeaway is to convert the UUID to a binary data type by removing the "-" characters and performing unhex() on the UUID. Here is another post on storing UUIDs in MySQL from percona.com, emphasizing the memory savings of using the UUID-to-Binary approach.

I recently added visitor logging which I described in this post and wanted to use UUID Primary Keys. I liked the unhex() / binary approach but felt that retrieving binary values isn't as straightforward as I liked. So I simply removed the UUID "-" characters and saved the field as a char(32) data type. You could have used a binary(32) data type here, but storage requirements are essentially the same.

My IDs then look like this.

uuid0327a.png

And insert statement like this.

uuid0327b.png

I didn't end up saving any memory, but I think this is a cleaner approach and I can retrieve records the old fashioned way.

select * from client_info where id = '065b4ef72c7411e89af710feed849ea9';

CategoriesMySQLTagsLinks, MySQL


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK