I’ve been using order by rand() and it’s becoming too much of a bottle neck.
I’ve tried this
SELECT id
FROM users
JOIN (
SELECT CEIL( RAND( ) * ( SELECT MAX( id ) FROM users ) ) AS id
) AS r2
USING ( id )
And it would work if all the id’s were incremented, however with this particular table, they’re not. The id’s are fairly random themselves.
Anyone have a better method? Thanks!
Maybe create another table and put there all id’s in compact way, adding id int autoincrement? If you using this function often, new table will pay for itself.