Starting MySQL 4.1, MySQL had support for what is called derived
tables, inline views or basically subselects in the from
clause.
In MySQL 5.0 support for views was added.
These features are quite related to each other but how do they compare in terms of performance ?
Derived Tables in MySQL 5.0 seems to have different implementation from views, even though I would expect code base to be merged as it is quite the same task in terms of query optimization.
Derived Tables are still handled by materializing them in the temporary table, furthermore temporary table with no indexes (so you really do not want to join two derived tables for example).
One more thing to watch for is the fact derived table is going to be materialized even to execute EXPLAIN statement. So if you have done mistake in select in from clause, ie forgotten join condition you might have EXPLAIN running forever.
Views on other hand …
[Read more]