Re: MySQL rand() is slow on large datasets
The way to make that fast:
SELECT * FROM Table T JOIN (SELECT FLOOR(MAX(ID)*RAND()) AS ID FROM Table) AS x ON T.ID >= x.ID LIMIT 1;
It's not pretty but it is fast. The way Thomas suggested causes the MAX()*RAND() to be executed for every row comparison.
Subject
Views
Written By
Posted
19279
July 24, 2007 08:19AM
14639
July 24, 2007 08:28AM
8022
September 02, 2007 10:30AM
Re: MySQL rand() is slow on large datasets
10421
January 18, 2008 12:25AM
7890
May 15, 2008 03:15PM
8812
May 12, 2009 10:21AM
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.