Olga
Olga

Reputation: 13

MySQL: how uuid_short is generated?

I have MySQL 5.5.24. Сalling uuid_short() few times I get just an incremented values:

mysql> select uuid_short();
+-------------------+
| uuid_short()      |
+-------------------+
| 22851044396498953 |
+-------------------+
1 row in set (0.00 sec)

mysql> select uuid_short();
+-------------------+
| uuid_short()      |
+-------------------+
| 22851044396498954 |
+-------------------+
1 row in set (0.00 sec)

But manual says:

The UUID_SHORT() return value is constructed this way:
  (server_id & 255) << 56
+ (server_startup_time_in_seconds << 24)
+ incremented_variable++;

Seems like neither "server_startup_time_in_seconds" or "server_id" changes. (I changed @@global.server_id system variable and it took no effect).

Does anyone know why?

Upvotes: 1

Views: 2007

Answers (1)

Philipp Sch
Philipp Sch

Reputation: 348

Seems to me like the function does return what's specified. The server Id and the start up time are server specific values and (usually) do not change as long as the server is running. The least significant part of the short UUID is an incremented value. So I assume after the server start up a seed for UUIDs is created taken the left-shifted server id and the left-shifted start up time. This value is incremented and returned on every creation of an UUID. This explains why changing the @@global.server_id variable has no effect.

Upvotes: 1

Related Questions