Analyze your slow mysql query with “Explain”

When you think your mysql is slow , the first step is to analyze your sql query with “Exlain” command.

This is an example
explain select * from table1 inner join table2 on table1.field1=table2.field2 and table.field3 =577458498

It will give you some thing like this , look at the “rows” column , if the number of that column is too high, try to reduce it by changing your query , or add index.

+--------+------+-------------------+---------+---------+-------+------+-----------+
|table   | type | possible_keys     | key     | key_len | ref   | rows |Extra      |
+--------+------+-------------------+---------+---------+-------+------+-----------+
|employee| ref  | surname,surname_2 | surname |      41 | const |    1 |where used |
+--------+------+-------------------+---------+---------+-------+------+-----------+

Leave a Reply

Your email address will not be published. Required fields are marked *