One nice feature added for EXPLAIN statement in MySQL 4.1 is EXTENDED keyword which provides you with some helpful additional information on query optimization. It should be used together with SHOW WARNINGS to get information about how query looks after transformation as well as what other notes optimizer may wish to tell us. It is best seen by example:

As you see after query transformation “*” was expanded to full column list, each column was fully quantified plus MySQL optimizer converted
c=”a” and pad=c; to c=”a” and pad=”a”. MySQL optimizer could not however catch id>5 and id>6 can be converted just to id>6.

Lets see another example:

In this case we can see table t1 is accessed using “const” access type, which means it should pre-read value for “t1.k” and place it into the query. This transformation however is not shown by EXTENDED EXPLAIN for some reason, while it would be quite helpful.

Finally lets look at third example:

As you see in this case there is planty of extra information in the message. We can see query is using , it is converted to using . And there is some in being done.

Unfortnuately there is yet not too much does available about what each of these means so you should guess from names or take a look at the sources.

To note about last query – even if it looks like there is a whole big deal of optimization being done query is executed extremely poor, completing in 16 seconds, while if you just run this subquery manually and use IN (1,2,3,…10) it completes in tiny fraction of the second.

Anyway EXPLAIN EXTENDED is very valuable addition to EXPLAIN for MySQL Performance troubleshooting.

8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Sergey Petrunia

Peter, a small correction: EXPLAIN EXTENDED was introduced in 4.1, not in 5.0 (and it is documented at http://dev.mysql.com/doc/refman/4.1/en/explain.html)

Dave Edwards

Thanks Peter — blogged in this week’s Log Buffer.

Sahibinden

Thank you very much for your explaination.

best regars

Taksi

Realy great example.
thank you very much.

Alfred Ayache

Thanks for the great article Peter.

The paragraph following the last example has some HTML problems. It should read:

As you see in this case there is planty of extra information in the message. We can see query is using <in_optimizer>, it is converted to <exists> using <primary key=”” lookup=””>. And there is some <cache> in being done.

HTH,
– AAA

derrenblby

Nice feature. Just need to learn how this really can help in optimization.. Thanks for sharing

Yukko

Planty = plenty ;-)