Derived tables is the internal name for subqueries in the
The processing of derived tables is now included in the table
opening process (
Routine of execution derived tables and substituting temporary
table instead of it (
will be called just after opening and locking all real tables used
in query (including tables used in derived table query).
lex->derived_tables flag is present, all
SELECT_LEX structures will be scanned (there is
a list of all
SELECT_LEX structures in reverse
lex->all_selects_list, the first
SELECT in the query will be last in this list).
There is a pointer for the derived table,
SELECT_LEX_UNIT stored in the
TABLE_LIST::derived). For any table that has
mysql_derived() will be called.
union_resultfor writing results in this table (with empty table entry, same as for
unit->prepare()to get list of types of result fields (it work correctly for single
SELECT, and do not create temporary table for
UNIONprocessing in this case).
Creates a temporary table for storing results.
Assign this temporary table to
mysql_unionto execute the query.
If it is not explain, then cleanup
JOINstructures after execution (
EXPLAINneeds data of optimization phase and cleanup them after whole query processing).
Stores pointer to this temporary table in
TABLE_LISTstructure, then this table will be used by outer query.
Links this temporary table in
thd->derived_tablesfor removing after query execution. This table will be closed in
close_thread_tablesif its second parameter (
bool skip_derived) is true.