Sunday, April 17, 2005

Faster way of getting random rows in mysql instead of using order by rand()

1. create a new indexed column (= column_x) that's integer incremented for each table
2. select count(*) to get # of rows
3. use the app to generate X # of integers between 1 and last row
4. select * from table where column_x in (rand1, rand2, rand3, ...)