September 20, 2014

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.

About Peter Zaitsev

Peter managed the High Performance Group within MySQL until 2006, when he founded Percona. Peter has a Master's Degree in Computer Science and is an expert in database kernels, computer hardware, and application scaling.

Comments

  1. Yukko says:

    Planty = plenty ;-)

  2. Sergey Petrunia says:

    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)

  3. peter says:

    Thank you Sergey, Now updated.

    I forgot in which version it was added.

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

  5. Sahibinden says:

    Thank you very much for your explaination.

    best regars

  6. Taksi says:

    Realy great example.
    thank you very much.

  7. 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

  8. derrenblby says:

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

Speak Your Mind

*