执行的过程有:
解析
- Preparation
- Locking of tables
- Optimization
- Execution or explain
- Cleanup
这几部分
prepare阶段
if (select->prepare(thd))
goto err;
unit->set_prepared();
}
else
{
if (unit->prepare(thd, result, SELECT_NO_UNLOCK | added_options,
removed_options))
goto err;
}
进入prepare函数
Resolve table and column information.
Resolve all expressions (item trees), ie WHERE clause, join conditions,
GROUP BY clause, HAVING clause, ORDER BY clause, LIMIT clause.
Prepare all subqueries recursively as part of resolving the expressions.
Apply permanent transformations to the abstract syntax tree, such as
semi-join transformation, derived table transformation, elimination of
constant values and redundant clauses (e.g ORDER BY, GROUP BY).