MySQL Forums
Forum List  »  Performance

Re: MySQL rand() is slow on large datasets
Posted by: Thomas Baggelaar
Date: July 24, 2007 08:28AM

Maybe this can help you with your performance issue

This query:

SELECT * FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 1;

should be much faster than this query:

SELECT * FROM `table` ORDER BY RAND() LIMIT 1;

See also: http://forums.mysql.com/read.php?10,163708,163708#msg-163708

Options: ReplyQuote


Subject
Views
Written By
Posted
18827
July 24, 2007 08:19AM
Re: MySQL rand() is slow on large datasets
13766
July 24, 2007 08:28AM
7784
September 02, 2007 10:30AM


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.