Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
与其他解决方案相比,性能真的ORDER BY rand()很慢吗?如果是,从数据库中选择随机行的更好方法是什么?
ORDER BY rand()
我的查询:
SELECT sName FROM bpoint WHERE placeID=? ORDER BY rand() LIMIT 1;
是的,ORDER BY RAND()在较大的结果集中可能会非常慢。
ORDER BY RAND()
一种选择是使用此语句获取结果集(放入数组中):
SELECT sName FROM bpoint WHERE placeID=?;
之后 - 用于array_rand($resultset)从$resultset查询中获取随机项。
array_rand($resultset)
$resultset