I'm using MariaDB 10.8.3. I have a table with a PK of type UUID. I'm inserting ordered UUIDs generated in application side. When I retrive the data of the table ordering by UUID column, it is not ordered as expected. For example:
SELECT id_label, date_add FROM mod_label ORDER BY id_label ASC;
The retrieved data is this:
But if I cast the UUID to char or convert to hex, the result is ordered as expected:
SELECT id_label, date_add FROM mod_label ORDER BY CAST(id_label AS CHAR(36)) ASC; SELECT id_label, date_add FROM mod_label ORDER BY HEX(id_label) ASC;
As I understand it, MariaDB saves UUIDs as 128-bit integers, so I don't understand this behavior.
Can someone explain me this behavior and how to fix it?