Extended EXPLAIN

Extended EXPLAIN


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.


Share this post

Comments (9)

  • Yukko Reply

    Planty = plenty ;-)

    July 24, 2006 at 12:00 am
  • Testing The Web Dot Com » Blog Archive » Extended EXPLAIN Reply

    […] Read the full article by Peter Zaitsev […]

    July 25, 2006 at 8:13 am
  • Sergey Petrunia Reply

    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)

    July 27, 2006 at 9:23 am
  • peter Reply

    Thank you Sergey, Now updated.

    I forgot in which version it was added.

    July 27, 2006 at 11:27 am
  • Dave Edwards Reply

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

    July 28, 2006 at 11:18 am
  • Sahibinden Reply

    Thank you very much for your explaination.

    best regars

    July 28, 2007 at 1:02 am
  • Taksi Reply

    Realy great example.
    thank you very much.

    August 8, 2007 at 8:22 am
  • Alfred Ayache Reply

    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.

    – AAA

    February 8, 2008 at 11:00 am
  • derrenblby Reply

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

    March 1, 2011 at 1:17 am

Leave a Reply