Why not use mysql ORDER BY RAND ()?

I saw many websites that do not use ORDER BY RAND (), for example http://forge.mysql.com/wiki/Top10SQLPerformanceTips So, I run the test, I tested the speed and performance in a table of 20 thousand records, 10 thousand records, among them there is a username = "username":

SELECT username FROM testingspeed WHERE username='username' ORDER BY RAND(); 

Result:

 Showing rows 0 - 29 (10,000 total, Query took 0.0119 sec). id = 1 select_type = SIMPLE table = testingspeed type = ref posible_keys = username key = username key_len = 32 ref = const rows = 3225 Extra = Using where; Using index; Using temporary; Using filesort 

since it took 0.0119 seconds just to complete the request, it should be very good speed, why do people still say DO NOT use ORDER BY RAND ()? Why only 3225 lines? Why won't 10,000 rows suffer?

+4
source share
1 answer

The problem with ORDER BY RAND() is that since your explanation tells you to use temporary and use file port. For each query, a temporary table is created and sorted. This is a rather difficult operation. It probably doesn't matter when your database is not under heavy load, but it will cost a lot of performance.

+5
source

All Articles