Welcome Guest, Not a member yet? Register   Sign In
Help tuning a very poor SQL query
#11

[eluser]TheFuzzy0ne[/eluser]
Hi, Leon. I just wanted to follow up on my previous suggestion, and post back the results of my test. I had a million rows in my database:

Counting the rows, selecting a random number, then grabbing a row took 0.0787 seconds:
Code:
SELECT * FROM `tmp_table` LIMIT 90016, 1;

Ordering by RAND() took an incredible 81.3853 seconds!
Code:
SELECT * FROM `tmp_table` ORDER BY RAND() LIMIT 1;

Ordering by RAND() is OK for smaller tables, but it doesn't scale well. I wish MySQL would implement a change that picked up on when the results were to be ordered by rand, and instead count the rows, select a random number and return a row that way instead.

All the best.


Messages In This Thread
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 08:03 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 08:19 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 08:24 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 09:42 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 09:47 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 10:10 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 10:28 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 11:21 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 11:40 AM
Help tuning a very poor SQL query - by El Forum - 06-17-2009, 11:49 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 05:49 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 05:53 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 06:02 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 09:57 AM
Help tuning a very poor SQL query - by El Forum - 06-18-2009, 10:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB