Sebastian wrote:
i have a table with several thousand records. i want to know if adding an index will improve things, example:

-------------------------------------
| id | item | text | runtime | dateline
-------------------------------------

now say i create this query:

$stats = mysql_query("
SELECT COUNT(*) as total, AVG(runtime) as avgtime
FROM table WHERE dateline > ".strtotime('6 hours ago')."
");

should dateline be an index?

Yes, because that's the only condition of your WHERE query, and the most discriminant one.

basically, i would like to know when i should create an index, when an index is not needed, and what columns should be indexes..

you should basically the columns you use in your "WHERE" condition, regarding which is the most relevant columns. Optimization is quiet a large field, and leads to endless discussion.


any urls which explains all this would be helpful.


http://dev.mysql.com/doc/mysql/en/mysql-optimization.html

You want to read, the one on "optimizing Select" and the one on columns indexes.

--
Philippe Poelvoorde
COS Trading Ltd.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to