Home » Performance » MySQL » RAND() Efficiency on well indexed columns
RAND() Efficiency on well indexed columns [message #193] Tue, 26 September 2006 09:11 Go to next message
Speeple  is currently offline Speeple
Messages: 91
Registered: August 2006
Member
I plan on having a large table, large as in lots of rows with contain a small amount of data.

The table holds integers acting as pointers.

Let's say the table has 10 Mil rows to start with.

The following query would be efficient:

SELECT id FROM pointers WHERE user_id=1 LIMIT 5

Out of the 10Mil rows, this user "1" has 20 stored pointers, so the PRIMARY index should be efficient at extracting the resultset.

To make sure each pointer id gets a fair amount of audience I would like to randomise the results.

How efficient is "ORDER BY RAND()" on such a query?

My guess is quite efficient, MySQL would maybe create a temp table fast with the 20 results, then randomise them?

The table gets lots of simultaneous read/writes and is innodb type engine.


Martin Gallagher | Speeple: The latest news
Re: RAND() Efficiency on well indexed columns [message #194 is a reply to message #193 ] Tue, 26 September 2006 09:15 Go to previous messageGo to next message
Peter  is currently offline Peter
Messages: 405
Registered: August 2006
Senior Member
Super Guru
Right.

If you have 20 rows matching WHERE clause only these rows would be sorted so it would not be that bad.


Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
Re: RAND() Efficiency on well indexed columns [message #3398 is a reply to message #193 ] Sun, 10 August 2008 06:34 Go to previous message
shila  is currently offline shila
Messages: 1
Registered: August 2008
Junior Member
Hi,

here you can find good solutions to MySQL problems.
http://www.fixya.com/support/t883221-mysql_efficiency

Ciao,
Shila.
Previous Topic:how to give path of the file in load data file syntax
Next Topic:ROW SIZE????
Goto Forum:
  


Current Time: Sat Jul 4 03:17:03 EDT 2009

Total time taken to generate the page: 0.15159 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.