How do I select a random record efficiently in MySQL?

Posted by user198729 on Stack Overflow See other posts from Stack Overflow or by user198729
Published on 2010-04-25T09:05:07Z Indexed on 2010/04/25 9:13 UTC
Read the original article Hit count: 192

Filed under:
|
mysql> EXPLAIN SELECT * FROM urls ORDER BY RAND() LIMIT 1;
+----+-------------+-------+------+---------------+------+---------+------+-------+---------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | Extra                           |
+----+-------------+-------+------+---------------+------+---------+------+-------+---------------------------------+
|  1 | SIMPLE      | urls  | ALL  | NULL          | NULL | NULL    | NULL | 62228 | Using temporary; Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+-------+---------------------------------+

The above doesn't qualify as efficient,how should I do it properly?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql-optimization