Кошерна ідентифікація GUID чи UUID

UUID (англ. universally unique identifier «универсальный уникальный идентификатор») — стандарт идентификации, используемый в создании программного обеспечения, стандартизированный Open Software Foundation (OSF) как часть DCE — среды распределённых вычислений. Основное назначение UUID — это позволить распределённым системам уникально идентифицировать информацию без центра координации. Таким образом, любой может создать UUID и использовать его для идентификации чего-либо с приемлемым уровнем уверенности, что данный идентификатор непреднамеренно никогда не будет использован для чего-то ещё. Поэтому информация, помеченная с помощью UUID, может быть помещена позже в общую базу данных, без необходимости разрешения конфликта имен. Наиболее распространённым использованием данного стандарта является Globally Unique Identifier (GUID) фирмы Microsoft.
//ru.wikipedia.org/wiki/UUID 

Хотя GUID (от Microsoft) и UUID (из RFC 4122) выглядят похоже и служат для похожих целей, существуют тонкие, но иногда важные различия. В частности, в документации Microsoft упоминается, что GUID может содержать любые шестнадцатеричные цифры в любых позициях, в то время как RFC 4122 требует использовать определённые значения version и variant. Там же упоминается, что GUID должен быть полностью в верхнем регистре, в то время как UUID должен «выводиться в нижнем регистре и быть нечувствительным к регистру при вводе». Это может привести к несовместимости между разными библиотеками

Рассматривайте их как 16-байтное (128-битное) значение, которое призвано быть уникальным. В Microsoft их называют GUID, в то время как все остальные называют UUID.

И авторы спецификации UUID, и сам Microsoft в настоящее время считают их синонимами:

в RFC 4122 указанно, что UUID «also known as GUIDs (Globally Unique IDentifier)»;

в ITU-T Recommendation X.667, ISO/IEC 9834-8:2004 International Standard: «UUIDs are also known as Globally Unique Identifiers (GUIDs), but this term is not used in this Recommendation»;

и даже Microsoft в своей документации указывает: «The term universally unique identifier (UUID) is sometimes used in Windows protocol specifications as a synonym for GUID».

Однако по-настоящему правильный ответ зависит от того, что именно в вопросе имеется в виду под термином «UUID».

Первая часть зависит от того, о чём спрашивающий думает, когда говорит «UUID».

Структура

MySQL

UUID()
Returns a Universal Unique Identifier (UUID) generated according to RFC 4122, “A Universally Unique IDentifier (UUID) URN Namespace” (http://www.ietf.org/rfc/rfc4122.txt).
A UUID is designed as a number that is globally unique in space and time. Two calls to UUID() are expected to generate two different values, even if these calls are performed on two separate devices not connected to each other.
Although UUID() values are intended to be unique, they are not necessarily unguessable or unpredictable. If unpredictability is required, UUID values should be generated some other way.

IS_UUID(string_uuid)
Returns 1 if the argument is a valid string-format UUID, 0 if the argument is not a valid UUID, and NULL if the argument is NULL.

UUID_SHORT()
Returns a “short” universal identifier as a 64-bit unsigned integer. Values returned by UUID_SHORT() differ from the string-format 128-bit identifiers returned by the UUID() function and have different uniqueness properties. The value of UUID_SHORT() is guaranteed to be unique if the following conditions hold:

BIN_TO_UUID(binary_uuid), BIN_TO_UUID(binary_uuid, swap_flag)
BIN_TO_UUID() is the inverse of UUID_TO_BIN(). It converts a binary UUID to a string UUID and returns the result. The binary value should be a UUID as a VARBINARY(16) value. The return value is a string of five hexadecimal numbers separated by dashes. (For details about this format, see the UUID() function description.) If the UUID argument is NULL, the return value is NULL. If any argument is invalid, an error occurs.

UUID_TO_BIN(string_uuid), UUID_TO_BIN(string_uuid, swap_flag)
Converts a string UUID to a binary UUID and returns the result. (The IS_UUID() function description lists the permitted string UUID formats.) The return binary UUID is a VARBINARY(16) value. If the UUID argument is NULL, the return value is NULL. If any argument is invalid, an error occurs.

MariaDB

Present in MySQL Only, because MariaDB and MySQL have differing implementations:
BIN_TO_UUID()
IS_UUID()
UUID_TO_BIN (MDEV-15854)

Решение

HEX(str), HEX(N)

For a string argument str, HEX() returns a hexadecimal string representation of str where each byte of each character in str is converted to two hexadecimal digits. (Multibyte characters therefore become more than two digits.) The inverse of this operation is performed by the UNHEX() function.
For a numeric argument N, HEX() returns a hexadecimal string representation of the value of N treated as a longlong (BIGINT) number. This is equivalent to CONV(N,10,16). The inverse of this operation is performed by CONV(HEX(N),16,10).

UNHEX(str)
For a string argument str, UNHEX(str) interprets each pair of characters in the argument as a hexadecimal number and converts it to the byte represented by the number. The return value is a binary string.

 

PHP

//

//

Источники

В чём разница между UUID и GUID? //ru.stackoverflow.com
10.7 preview feature: UUID Data Type //mariadb.org
Function Differences Between MariaDB 10.6 and MySQL 8.0 //mariadb.com

Leave a Reply