Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
None
Description
UUIDs are stored in a binary form, but not byte-swapped like in MySQL's uuid_to_bin https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin
The order provided by UUID_TO_BIN() is not really friendly to index prefix compression:
it only reorders the timestamp segments, while the clock-seq and the node-ID segments are still at the end. This ruins the whole idea of prefix compression.
Let's sort UUID in a really index-friendly order, by moving the constant part to the left and the variable part to the right.
So for comparison purposes we'll reorder segments, but keep the byte order inside the segments (i.e. in big endian order):
MariaDB binary UUIDv1 representation, as returned by the UUID() function:
|
|
llllllll-mmmm-Vhhh-vsss-nnnnnnnnnnnn
|
|
Binary sortable representation:
|
|
nnnnnnnnnnnn-vsss-Vhhh-mmmm-llllllll
|
|
Sign Section Bits Bytes Pos PosBinSortable
|
------------- ------- ---- ----- --- --------------
|
llllllll time low 32 4 0 12
|
mmmm time mid 16 2 4 10
|
Vhhh version and time hi 16 2 6 8
|
vsss variant and clock seq 16 2 8 6
|
nnnnnnnnnnnn node ID 48 6 10 0
|
Attachments
Issue Links
- causes
-
MDEV-29959 UUID Sorting
-
- Closed
-
- is caused by
-
MDEV-4958 Adding datatype UUID
-
- Closed
-
- relates to
-
MDEV-20477 Merge binlog extended metadata support from the upstream
-
- Closed
-
-
MDEV-27588 MyISAM/Aria descending index compression is not as efficient as ascending
-
- Closed
-
- links to
SQL Server has a data type uniqueidentifier with a good sort order.
Tested with SQL Server 2017:
00000000-0000-0000-0000-000000000000
F0000000-0000-0000-0000-000000000000
0000000F-0000-0000-0000-000000000000
00000000-F000-0000-0000-000000000000
00000000-000F-0000-0000-000000000000
00000000-0000-F000-0000-000000000000
00000000-0000-000F-0000-000000000000
00000000-0000-0000-000F-000000000000
00000000-0000-0000-F000-000000000000
00000000-0000-0000-0000-00000000000F
01C0423E-F36B-1410-8001-400000000001
01C0423E-F36B-1410-8001-400000000002
01C0424E-F36B-1410-8001-500000000001
02C0424E-F36B-1410-8001-500000000001
0BC0423E-F36B-1410-800B-800000000000
0CC0423E-F36B-1410-800C-800000000000
00000000-0000-0000-0000-F00000000000
01C0423E-F36B-1410-8001-F00000000001
01C0423E-F36B-F410-8001-F00000000001
01C0423E-FF6B-F410-8001-F00000000001
01C0423E-F36B-1410-F001-F00000000001
However, the NewSequentialId() function in SQL Server puts the timestamp segments of the UUID in little endian order, while MariaDB function UUID() puts the timestamp segments in big endian order.