MariaDB UUID_SHORT() Function

In MariaDB, UUID_SHORT() is a built-in function that returns a short, conditionally unique Universal Identifier (UUID).

You can also use UUID() and SYS_GUID() to get unique identifiers.

UUID_SHORT() is different from UUID() and has a different uniqueness property.

MariaDB UUID_SHORT() Syntax

Here is the syntax of the MariaDB UUID_SHORT() function:

UUID_SHORT()

Parameters

The MariaDB UUID_SHORT() function do not have any parameters.

Return value

The MariaDB UUID_SHORT() function return a short universal identifier as a 64-bit unsigned integer.

This is how the UUID_SHORT() function return value is constructed:

  (server_id & 255) << 56
+ (server_startup_time_in_seconds << 24)
+ incremented_variable++;

The value returned by the UUID_SHORT() function is unique when the following conditions are met:

  • The current server has a server_id value between 0 and 255 and is unique within your set of source and replica servers
  • You don’t set the server host’s system time between mysqld restarts
  • You average calling times per seconds is less than 16,000,000.

MariaDB UUID_SHORT() Examples

The following example shows how to use the UUID_SHORT() function to obtain a unique identifier.

SELECT UUID_SHORT();

Output:

+--------------------+
| UUID_SHORT()       |
+--------------------+
| 100158760672034816 |
+--------------------+

If you call it again, you will get a different value:

SELECT UUID_SHORT();

Output:

+--------------------+
| UUID_SHORT()       |
+--------------------+
| 100158760672034817 |
+--------------------+

Even if you call UUID_SHORT() twice in the same statement, different values ​​will be reached:

SELECT
  UUID_SHORT(),
  UUID_SHORT()\G

Output:

UUID_SHORT(): 100158760672034818
UUID_SHORT(): 100158760672034819

SYS_GUID() vs UUID() vs UUID_SHORT()

The following example shows the difference between SYS_GUID(), UUID(), and UUID_SHORT():

SELECT
  UUID_SHORT(),
  UUID(),
  SYS_GUID()\G

Output:

UUID_SHORT(): 100158760672034821
      UUID(): 442e4aba-a10d-11ed-ac31-18c04d19fce5
  SYS_GUID(): 442e4abfa10d11edac3118c04d19fce5

Conclusion

In MariaDB, UUID_SHORT() is a built-in function that returns a short, conditionally unique Universal Identifier (UUID).