Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Apr 272011
 

Explain query execution plan in MySQL

Answer:

To get a better understanding of the performance of your MySQL query, you can use the explain statement.

E.g.

mysql> explain select * from user where host = 'localhost';
+----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key     | key_len | ref   | rows | Extra       |
+----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+
|  1 | SIMPLE      | user  | ref  | PRIMARY       | PRIMARY | 180     | const |   12 | Using where |
+----+-------------+-------+------+---------------+---------+---------+-------+------+-------------+

Usually you need to look at the column "key" to see if index was being used, and the column "rows" to see how many rows are scanned for the query.

  One Response to “Explain query execution plan in MySQL”

  1. [...] MySQL, you can get a better understanding of the performance of your MongoDB's query, you can use the [...]

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>