Search the MySQL manual:

5 MySQL Optimisation

Optimisation is a complicated task because it ultimately requires understanding of the whole system. While it may be possible to do some local optimisations with small knowledge of your system or application, the more optimal you want your system to become the more you will have to know about it.

This chapter will try to explain and give some examples of different ways to optimise MySQL. Remember, however, that there are always some (increasingly harder) additional ways to make the system even faster.

Subsections

User Comments

Posted by Christoph Tapper on Monday October 7 2002, @3:14pm[Delete] [Edit]

Slow SQLs may be a result of unintended locks.

I had trouble with an SELECT that joined 4 tables but should return only 1 row (LIMIT 1). After returning the result the connection still was heavy busy (a bug?). The CPU usage of mysqld was about 97% and SHOW PROCESSLIST showed that the connection was in a state "Copying to tmp table" and thus LOCKING all tables participating in the query.

The solution was to split the SQL into multiple CREATE TEMPORARY TABLE SQLs and then joining these. That reduced the execution speed from about 300 seconds to something below 1 second :)

Add your own comment.