Skip navigation links

MySQL Forums :: Performance :: MySQL rand() is slow on large datasets


Advanced Search

Re: MySQL rand() is slow on large datasets
Posted by: Mike Pogues ()
Date: May 12, 2009 10:21AM

Tried Jeff's query but only low number ids were generated. The query below solves this.

SELECT t.id FROM table t JOIN (SELECT(FLOOR(max(id) * rand())) as maxid FROM table) as tt on t.id >= tt.maxid LIMIT 1

Options: ReplyQuote


Subject Views Written By Posted
MySQL rand() is slow on large datasets 16309 pbu pbu 07/24/2007 08:19AM
Re: MySQL rand() is slow on large datasets 9888 Thomas Baggelaar 07/24/2007 08:28AM
Re: MySQL rand() is slow on large datasets 6752 Maurizio G 09/02/2007 10:30AM
Re: MySQL rand() is slow on large datasets 8089 Jay Paroline 01/18/2008 12:25AM
Re: MySQL rand() is slow on large datasets 6524 Jeff Fillmore 05/15/2008 03:15PM
Re: MySQL rand() is slow on large datasets 6041 Mike Pogues 05/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.