{question}
Which is the best UUID data type?
{question}
{answer}
This topic describes the best UUID data type that can be chosen depending on your use case.
Use INT
or BIGINT
fields for joining tables if performance is the most crucial consideration. Joining on BINARY(16)
columns works but is noticeably slower.
Comparing Binary and Char. We recommend using the BINARY(16)
over CHAR(32)
. This will both improve performance and reduce space consumption. But use integers whenever possible.
If BINARY(16)
is selected It will save space compared withVARCHAR(36)
36-char GUIDs in string format with dashes. But data has to be converted first like described below,
singlestore> create table sometable(UUID binary(16));
Query OK, 0 rows affected (0.15 sec)
singlestore> INSERT INTO sometable (UUID) VALUES
-> (UNHEX(REPLACE("3f06af63-a93c-11e4-9797-00505690773f", "-","")))
-> ;
Query OK, 1 row affected (0.07 sec)
singlestore> select hex(uuid) from sometable;
+----------------------------------+
| hex(uuid) |
+----------------------------------+
| 3F06AF63A93C11E4979700505690773F |
+----------------------------------+
Built-In: UUID() is available from SingleStore v7.5: Click here to learn more about it.
Syntax:
SYS_GUID()
UUID()
For SQL references click here.
{answer}