R_User
R_User

Reputation: 11082

How to interpret the output of MySQL EXPLAIN?

I want to select the content of the column text from entrytable.

EXPLAIN SELECT text
FROM entrytable
WHERE user = 'username' &&
`status` = '1' && (
    `status_spam_user` = 'no_spam'
    || (
        `status_spam_user` = 'neutral' &&
        `status_spam_system` = 'neutral'
    )
)
ORDER BY datum DESC
LIMIT 6430 , 10

The table has three indices:

The EXPLAIN result is:

id  select_type     table       type    possible_keys                       key         key_len     ref     rows    Extra
1   SIMPLE          entrytable  ref     index_user,index_status_mit_spam    index_user  32          const   7800    Using where; Using filesort

Upvotes: 26

Views: 18991

Answers (2)

Namphibian
Namphibian

Reputation: 12221

Answering your questions:

You need to understand that indexes speeds up reads and slows down writes to tables. So just adding indexes is not always a good idea. The above answers and pointers should help you gain a solid understanding.

Upvotes: 15

Joddy
Joddy

Reputation: 2695

  • possible_keys denotes all the indices of your table (keys or index columns)
  • MySQL optimizer decides the best way to EXECUTE a query, it may use any index (not necessary primary key), or none
  • To force MySQL to use or ignore an index listed in the possible_keys column, use FORCE INDEX, USE INDEX, or IGNORE INDEX in your query
  • Check this link - http://dev.mysql.com/doc/refman/5.1/en/index-hints.html .

    You can specify the scope of a index hint by adding a FOR clause to the hint. This provides more fine-grained control over the optimizer's selection of an execution plan for various phases of query processing. To affect only the indexes used when MySQL decides how to find rows in the table and how to process joins, use FOR JOIN. To influence index usage for sorting or grouping rows, use FOR ORDER BY or FOR GROUP BY. (However, if there is a covering index for the table and it is used to access the table, the optimizer will ignore IGNORE INDEX FOR {ORDER BY|GROUP BY} hints that disable that index.)

  • Try forcing different index - check this link for sure - MySQL `FORCE INDEX` use cases?

  • Understand EXPLAIN output format - http://dev.mysql.com/doc/refman/5.1/en/explain-output.html

Upvotes: 5

Related Questions