At the MySQL Mini Conference in Sydney this week we discussed how
to use EXPLAIN EXTENDED to view the rewrites undertaken by the
MySQL optimizer. IN particular, to see if MySQL performs a
merge of the query into the view definition, or if it creates a
temporary table.
It can be tricky to optimize queries using views, since it's
often hard to know exactly how the query will be resovled - will
MySQL push merge the text of the query and the view, or will it
use a temporary table containing the views result set and then
apply the query clauses to that?
In general, MySQL merges query text except when the view
definition includes a GROUP BY or UNION. But to be sure we
can use EXPLAIN EXTENDED. This also helps when we get
confusing output in the EXPLAIN output.
For instance if we have a view definition like this:
CREATE VIEW user_table_v AS
…
[Read more]