be shure you have an index on every column you use on a WHERE or ORDER BY statement, you should also replicate your query from the command line using EXPLAIN SELECT ...
to figure out HOW things are done and WHERE you can optimize your query or table structure.