Bug #20618 Last four parts are same between UUID() function calls
Submitted: 22 Jun 2006 2:55 Modified: 27 Jun 2006 13:45
Reporter: Hiten Pandya Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:MySQL 5.0.11 OS:Windows (Windows XP SP2)
Assigned to: CPU Architecture:Any

[22 Jun 2006 2:55] Hiten Pandya
Description:
It seems that the value of the last four parts of a UUID are ending up same between two or more calls to the UUID() function.

I have looked into the source code for MySQL 5.0.22 (yes, I know I run 5.0.11) and I am not sure why this is happening; only thing that rang a bell was the check for if (! uuid_time) in Item_uuid_func().

By that, I mean whether this is an intended feature (!) or something that needs to be corrected.  I have not tried this on my freebsd or linux box so I am not sure what the consequence is on those operating systems.

As you can see from the 'How to repeat' section, the first part remains unique, however the last part is retained through three consecutive calls to that function.

HOWEVER, the last part changes if I restart the MySQL service on my Windows machine.  This makes me think that the last four are possibly kept cached somewhere in memory; however this seems to defeat the point of having UUIDs, if I am not mistaken? :-)

How to repeat:
mysql> select uuid();
| d6a99999-52e9-1029-a716-accdfe92e0ab |
1 row in set (0.00 sec)
mysql> select uuid();
| d7599758-52e9-1029-a716-accdfe92e0ab |
1 row in set (0.00 sec)
mysql> select uuid();
| d8195498-52e9-1029-a716-accdfe92e0ab |
1 row in set (0.00 sec)
[22 Jun 2006 2:56] Hiten Pandya
Note, the last four parts change only when the Windows 'mysql' service is restarted or started/stopped; otherwise they remain the same.
[22 Jun 2006 7:55] Sveta Smirnova
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

Please, read how MySQL generates uuid here: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html
[27 Jun 2006 9:56] Hiten Pandya
Thanks for the response Sveta, however what I don't seem to understand, please do not hesitate to shed light, is that why should the fifth number remain the same when the documentation is saying that only FreeBSD and Linux are supported platforms for using the 802.1 node number?  My platform is Windows so I am expecting this 48-bit random generated number to change at all times; the only possible explanation I can come up with in my head is that the reason why MySQL is generating this 48-number only once per server start/restart is to give us more combinations?  Please don't hesitate to shed more light wherever possible, I may not be understanding the *why* fully.

I did reach the documentation as instructed, before and after I submitted this bug however it doesn't provide me with a clear explanation of the reasoning.

Thanks in advance.
[27 Jun 2006 13:28] Sergei Golubchik
Yes, a random number is generated once, when you call UUID() for the first time.
[27 Jun 2006 13:37] Sergei Golubchik
it's not really to give more combinations, but to provide compatible behaviour on all platforms. This part of the uuid is not supposed to change all the time, it is to provide spatial uniqueness, not temporal uniqueness. That is, it is constant on every single computer, but it's different on two different computers.
[27 Jun 2006 13:45] Hiten Pandya
Sergei, thanks for the update.  That's what I figured when I looked at the 5.0.22 code and init_uuid variable in Item_uuid.  However, when you say spatial uniqueness, does that mean I am guaranteed that my UUIDs will not clash?

I know I am probably about to drive everyone up the wall with this, but I seriously do require this confirmation as I am going to use this functionality of MySQL for quite a critical component of a system via stored functions.
[28 Jun 2006 20:38] Sveta Smirnova
Dear Hiten, bug database is not for support, but for resolving bugs. In page link to I provided described all steps of uuid generation. If you think documentation is not full or is not having a single meaning, please, open documentation bug.

Thank you for the interest in MySQL.