Performance of mysql derived tables and views: 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.
MySQL 4.1 supports subqueries for derived tables, online views, or Basic FROM clauses.
These features are quite related to each other but how do they compare in terms of performance?
These features are related to each other, but what is the performance comparison between them?
Derived Tables in MySQL 5.0 seems to have different implementation from views, even though I wowould perform CT code base to be merged as it is quite the same task in terms of query optimization.
The derived table in MySQL 5.0 seems to be different from the View implementation method, although I think the query optimization should be the same from the combined code base.
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 ).
The derived table is still explicitly processed in the form of a temporary table, and there are still temporary tables without indexes (so it is best not to connect two derived tables as in the 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.
On the other hand, the derived table needs to be explicitly processed, although only the EXPLAIN statement is executed. Therefore, if you make a mistake in the SELELCT operation in the FROM clause, for example, if you forget to write the connection conditions, the EXPLAIN statement may always be running.
Views on other hand do not have to be materialized and normally executed by rewriting the query. It only will be materialized if query merge is impossible or if requested by view creator.
The view is different. it does not need to be explicitly processed, but simply overwrites the query. Explicit processing is required only when the query cannot be merged or when the request is attempted by the creator.
What does it mean in terms of performance:
This means that their performance differences are as follows:
PLAIN TEXT
SQL:
Query ON base TABLE executes using index and it IS very fast
Execute indexed queries on basic tables, which is very fast
Mysql> SELECT * FROM test WHERE I = 5;
+ --- + ------------------------------------ +
| I | j |
+ --- + ------------------------------------ +
| 5 | 0c88dedb358cd96c9069b73a57682a45 |
+ --- + ------------------------------------ +
1 row in set (0.03 sec)
Same query USING derived TABLE crawler: