MySQL Forums :: Performance :: Select random rows when using UUID

Advanced Search

Re: Select random rows when using UUID
Posted by: Jonathan Keen ()
Date: June 14, 2016 11:23AM

Thanks, Rick! UUID is the primary key in my use case.

When evaluating whether the UUID is > RIGHT( HEX( (1<<24) * (1+RAND()) ), 6) what is it converting the UUID into in order to evaluate it? I'm not proficient enough to understand.

I was also doing the following with what I thought were good speeds and decent very random results. Any thoughts? No real reason for evaluating at the 6th character within the UUID besides being lazy from looking at your examples. ;)

The set could also be done with an application cache every x amount of hours.

SET @max := (SELECT MIN(HEX(LEFT(id, 6))) FROM random_test);
SET @min := (SELECT MAX(HEX(LEFT(id, 6))) FROM random_test);

FROM (SELECT FLOOR(RAND() * (@max - @min) + @min) AS start FROM random_test) AS init
JOIN random_test y
WHERE HEX(LEFT(, 6)) > init.start OR HEX(LEFT(, 6)) < init.start
) z

Thanks again for taking a look, as well as your time, and I apologize if I've overlooked anything glaringly obvious.

Options: ReplyQuote

Subject Views Written By Posted
Select random rows when using UUID 673 Jonathan Keen 06/09/2016 11:43AM
Re: Select random rows when using UUID 353 Rick James 06/13/2016 01:36AM
Re: Select random rows when using UUID 389 Jonathan Keen 06/14/2016 11:23AM
Re: Select random rows when using UUID 348 Rick James 06/18/2016 01:35AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.