I had just asked questions about ordering random values through MYSQL
.
From there I began to notice an uncomfortable slowness in the system of friendships suggested here by the company.
I use Laravel 3
. I went to do a check of what could be slowing down the system.
Then I got the following results from a query. In both cases, I'm using LIMIT 10
.
With RAND()
:
85.203170776367
6.6289901733398
No RAND()
0.074863433837891
0.11181831359863
How does MYSQL
use ORDER BY RAND()
internally - to stay so slow?
What possible changes to get results in MYSQL
randomly.
Update
I did more testing using MYSQL
directly with PhpMyAdmin.
See.
With RAND()
:
SELECT * FROM pessoa ORDER BY RAND()
#A mostrar registos de 0 - 29 (9024 total, O Query demorou 1.0453 sec)
No RAND()
:
SELECT * FROM pessoa ORDER BY id
#A mostrar registos de 0 - 29 (9024 total, O Query demorou 0.0008 sec)