MySql UUID Duplication BUG

There is an error that I found in MySql 5.5.19.

While doing:

select uuid(), uuid();

You get two equal identifiers.

I run this error twice when inserting two uuids into my table, I always had the same values.

Does anyone else work on this error? How can I execute the insert command, which requires two uuids for my keys?

Edit

In fact, I was mistaken, they are different in one figure, so it was very difficult to see

c3db913 7 -705e-11e1-ae17-1c6f6531b785
c3db913 e -705e-11e1-ae17-1c6f6531b785

+1
source share
3 answers

UUID , . , UUID() . , , . .

+6

, , (, ). - , UUID , , ( ?), , , . , SELECT uuid()

+8

, mysql uuid_v1, , uuid, uuid_v4, uuid . , uuid_v1 uuid, ,

-- Change delimiter so that the function body doesn't end the function 
declaration
DELIMITER //

CREATE FUNCTION uuid_v4()
    RETURNS CHAR(36)
BEGIN
    -- Generate 8 2-byte strings that we will combine into a UUIDv4
    SET @h1 = LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0');
    SET @h2 = LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0');
    SET @h3 = LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0');
    SET @h6 = LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0');
    SET @h7 = LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0');
    SET @h8 = LPAD(HEX(FLOOR(RAND() * 0xffff)), 4, '0');

    -- 4th section will start with a 4 indicating the version
    SET @h4 = CONCAT('4', LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'));

    -- 5th section first half-byte can only be 8, 9 A or B
    SET @h5 = CONCAT(HEX(FLOOR(RAND() * 4 + 8)),
                LPAD(HEX(FLOOR(RAND() * 0x0fff)), 3, '0'));

    -- Build the complete UUID
    RETURN LOWER(CONCAT(
        @h1, @h2, '-', @h3, '-', @h4, '-', @h5, '-', @h6, @h7, @h8
    ));
END
//
-- Switch back the delimiter
DELIMITER ;

0

Source: https://habr.com/ru/post/1683521/


All Articles