Re: MySQL rand() is slow on large datasets
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
Subject
Views
Written By
Posted
19089
July 24, 2007 08:19AM
Re: MySQL rand() is slow on large datasets
14467
July 24, 2007 08:28AM
7954
September 02, 2007 10:30AM
10252
January 18, 2008 12:25AM
7802
May 15, 2008 03:15PM
8632
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.