MySQL Forums
Forum List  »  Performance

Re: MySQL rand() is slow on large datasets
Posted by: Jay Paroline
Date: January 18, 2008 12:25AM

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.

Options: ReplyQuote


Subject
Views
Written By
Posted
18827
July 24, 2007 08:19AM
7784
September 02, 2007 10:30AM
Re: MySQL rand() is slow on large datasets
9928
January 18, 2008 12:25AM


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.