I'm trying to retrieve a "random" row from a table where the randomness is "weighted" by a factor, let's call it "weight" (original, huh?).
the following (pseude-SQL) works but is EXTREMELY slow:
SELECT * FROM table
ORDER BY RAND() * ( 1 / weight)
LIMIT 1;
I've read that "ORDER BY RAND()" is a big no-no as far as optimization is concerned.
Is there another, more optimal way to construct a weighted random query?
the following (pseude-SQL) works but is EXTREMELY slow:
SELECT * FROM table
ORDER BY RAND() * ( 1 / weight)
LIMIT 1;
I've read that "ORDER BY RAND()" is a big no-no as far as optimization is concerned.
Is there another, more optimal way to construct a weighted random query?