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