3
I had just asked questions regarding the ordering of random values through the MYSQL
.
From there I began to notice an uncomfortable slowness in the suggested system of friendships here of the company.
I use the Laravel 3
. I went to check what might be slowing down the system.
Hence I obtained the following results in a query. In both cases, I am using LIMIT 10
.
With the RAND()
:
85.203170776367
6.6289901733398
Without RAND()
0.074863433837891
0.11181831359863
How did the MYSQL
uses the ORDER BY RAND()
internally - to be so slow?
What possible changes to obtain results in the MYSQL
randomly.
Updating
I did more tests using the MYSQL
directly with Phpmyadmin.
Look at.
With RAND()
:
SELECT * FROM pessoa ORDER BY RAND()
#A mostrar registos de 0 - 29 (9024 total, O Query demorou 1.0453 sec)
Without RAND()
:
SELECT * FROM pessoa ORDER BY id
#A mostrar registos de 0 - 29 (9024 total, O Query demorou 0.0008 sec)
the numerical values are in milliseconds, certain?
– Daniel Omine
In the source code of the Laravel is like this:
(microtime(true) - $start) * 1000
– Wallace Maxters
Idependente of the measure, you can see the difference in performance. kkkkk
– Wallace Maxters
seriously it takes 85 seconds ? how many records does the table hold? 40 billion records ? rsrsrs Even using Rand(), you should not go from 0.4 in a small query to a table with 100,000 records and without any optimization.. all in default.
– Daniel Omine
you want a random result (which can be repeated) or you always want a different result from the previous one?
– rray
Your table has 9024 records, right? Surely there is some problem in the table.. It may be using indices too much or the wrong way.. A consultation with
ORDER BY RAND() limit 10;
normally return in 0.04 seconds on a server with default settings, with no optimizations..– Daniel Omine
I’ll show you the appointment I’m doing. You’ll stand on your hair
– Wallace Maxters
Send us this berry to see!
– Daniel Omine
Cry in that Paste bin
– Wallace Maxters
When the
RAND
is what gives a degree– Wallace Maxters
I figured it was a little monster. rsrs has a lot of subselect, but that doesn’t mean it’s the problem.. can be misuse or lack use of indices or keys such as relationships (foreign key).. post the DDL of the tables involved.
– Daniel Omine
Hey, guys? What’s new?
– Wallace Maxters
Yes. Ronaldinho Gaúcho came out of Fluminense, out of nowhere...
– Diego Souza