PHP, MySQL - would results-array shuffle be quicker than "select... order by rand()"?
Posted
by sombe
on Stack Overflow
See other posts from Stack Overflow
or by sombe
Published on 2009-12-12T01:03:47Z
Indexed on
2010/04/20
22:43 UTC
Read the original article
Hit count: 155
I've been reading a lot about the disadvantages of using "order by rand" so I don't need update on that. I was thinking, since I only need a limited amount of rows retrieved from the db to be randomized, maybe I should do:
$r = $db->query("select * from table limit 500");
for($i;$i<500;$i++)
$arr[$i]=mysqli_fetch_assoc($r);
shuffle($arr);
(i know this only randomizes the 500 first rows, be it).
would that be faster than
$r = $db->("select * from table order by rand() limit 500");
let me just mention, say the db tables were packed with more than...10,000 rows.
why don't you do it yourself?!? - well, i have, but i'm looking for your experienced opinion.
thanks!
© Stack Overflow or respective owner