Thursday, June 21, 2012

What are the different methods to optimize the MySQL query?

It does not depend upon single entity. In order to optimize you have to consider many things:

1. Make sure table has primary key.

2. If there is any field which is used more frequently for searching then INDEX it.

3. Check the order of join condition.

4. In "Select" statement "where" condition should have indexed column.

5. Use "Limit" clause to fetch required amount of records from the database.

6. Use "count()" instead of "*" if you want to know the number of records fetched from the DB.

No comments: