I am trying to add UUIDs to some tables in some of my MySQL databases (MySQL 5.7.9). First of all, I start by adding a column to get the UUID:
ALTER TABLE `mytable` ADD COLUMN `Uuid` BINARY(16) DEFAULT NULL;
Then, for all records that are already in the table, I generate a UUID (since each record in the database will receive a NULL value in this UUID field.
UPDATE `mytable` SET Uuid= unhex(replace(uuid(),'-','')) WHERE Uuid IS NULL;
Now the thing is, I get very strange behavior by doing this; in some of my databases, each generated UUID is unique (as expected). However, in other databases, all generated UUIDs are identical (not similar, identical).
I suspect this is due to the MySQL query optimizer, as the behavior is incompatible between different database instances (all in MySQL 5.7.9). However, I do not know how to solve this problem.
So, MySQL guru, am I doing something wrong?
source
share