196 karma · joined January 22, 2010
[1] And, if they don't, you should run away. Fast.
[2] The actual rules are a little more complex than that, but that's what it comes down to.
mysql> select * from large_table order by rand() limit 1;
<...>
1 row in set (36.69 sec)
mysql> select primary_key_column from large_table order by rand() limit 1;
<...>
1 row in set (7.33 sec)
Basically, ORDER BY RAND() forces a temporary table / filesort no matter what; selecting fewer columns decreases the size of the temporary table, but doesn't actually eliminate the problem.The best way to select a random row from a MySQL table is using a trick I got from Mediawiki: create an indexed float column, set it to RAND() for each row, and select random rows using:
SELECT * FROM table WHERE randnum > RAND() ORDER BY randnum LIMIT 1
This runs as an index range scan, making it basically instantaneous.(2) I wish I knew. Not really our place to ask, though.
- They've forgotten the password, but it's still in the keychain (or equivalent) for their mail or FTP client, which will all stop working when they reset the password.
- The password is shared with other employees, and it might be difficult to notify them all of the new password.
You can also view MySQL user passwords by clicking on the username in the panel (https://panel.dreamhost.com/index.cgi?tree=goodies.mysql). This shouldn't be a big deal, though, as you have to store the passwords in the clear in config files anyway.