Comments on: EXPLAIN: missing db info https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info Blog by Shlomi Noach Wed, 12 May 2010 12:57:00 +0000 hourly 1 https://wordpress.org/?v=5.3.3 By: Xaprb https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13460 Wed, 12 May 2010 12:57:00 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13460 I wish I had a memory that good.

Even if you don’t learn Perl, the test cases in trunk/common/t/QueryParser.t might be useful to you.

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13450 Wed, 12 May 2010 08:13:06 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13450 @Baron

Thank you; Roland is a good listener 🙂

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13449 Wed, 12 May 2010 08:01:43 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13449 @shlomi,

well, thank baron 🙂

Here’s the slides:

http://assets.en.oreilly.com/1/event/36/EXPLAIN%20Demystified%20Presentation%201.pdf

(these are of the 2010 talk – not the one I attended but I see the info is still there)

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13448 Wed, 12 May 2010 07:54:30 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13448 @Roland,
Hey, that’s pretty cool! I may play around with this (or maybe not just right now). I’ll let you know if I happen to get results.

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13446 Wed, 12 May 2010 07:38:53 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13446 @shlomi,

“How can I guess the alias and match it against the query?”

I think I picked this up during Baron’s “Explain Demystified” talk from two years back at the MySQL user conference.

Assuming you can parse the SQL and succesfully match the ci and co aliases in the explain output to the query parse tree, you then know that `co` is a DERIVED table. Together with the value in the id column for that table, you get “derived2” (as in, CONCAT(LOWER(select_type), id)

Try it with another query like this:

explain extended select id from world.City ci, (select code from (select * from world.Country) co) s1;

You’ll notice that it actually works.

Of course, don’t mistake my explanation as approval – this is an ugly mess, at least for what you want to achieve 🙂

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13443 Wed, 12 May 2010 05:46:01 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13443 @Baron,

Thanks; I’ve just seen it. I think mk-query-digest already uses a very smart SQL parser.
If I happen to work on my perl skills, I’ll take a better look.

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13441 Wed, 12 May 2010 05:22:13 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13441 Roland,

It still does not help in matching the query against the execution plan.

mysql> explain extended select id from world.City ci, (select code from world.Country co) s1;
+----+-------------+------------+-------+---------------+---------+---------+------+------+----------+--------------------------------+
| id | select_type | table      | type  | possible_keys | key     | key_len | ref  | rows | filtered | Extra                          |
+----+-------------+------------+-------+---------------+---------+---------+------+------+----------+--------------------------------+
|  1 | PRIMARY     | <derived2> | ALL   | NULL          | NULL    | NULL    | NULL |  239 |   100.00 |                                |
|  1 | PRIMARY     | ci         | index | NULL          | PRIMARY | 4       | NULL | 4079 |   100.00 | Using index; Using join buffer |
|  2 | DERIVED     | co         | index | NULL          | PRIMARY | 3       | NULL |  239 |   100.00 | Using index                    |
+----+-------------+------------+-------+---------------+---------+---------+------+------+----------+--------------------------------+


How can I guess the <derived2> alias and match it against the query? How about two derived tables?

You are right; I don’t have to go to that depth; but the job becomes very difficult. I suspect there are other examples.

]]>
By: Xaprb https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13419 Tue, 11 May 2010 14:23:58 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13419 Take a look at what mk-index-usage does. There is a lot of overlap between your case and what that tool does. Yes, there is a lot of SQL parsing, and it is not easy. We have a lot of test cases.

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13411 Tue, 11 May 2010 08:43:47 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13411 Shlomi, Rob has a point. The “canonical” query in the EXPLAIN EXTENDED output is very ugly, but probably quite easy to parse, as all identifiers are quoted, join conditions are fully parenthesized, whitespace is normalized – lot of headeaches gone.

I suspect you could even do it with a hand-crafted operator precedence parser.

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/explain-missing-db-info/comment-page-1#comment-13410 Tue, 11 May 2010 08:33:06 +0000 https://shlomi-noach.github.io/blog/?p=2368#comment-13410 @Peter,
I see you’ve tried the same path…

]]>