MySQL Forums
Forum List  »  Performance

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.

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

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

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
Re: Select random rows when using UUID
1274
June 14, 2016 11:23AM


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.