Retired Note 1 # MySQL = lambdasql: SQL + & #39; SourceCode4ExplainPlan & #39;
The Mysql query execution process is roughly divided into four stages:
Syntax analysis (SQL _parse.cc <lexical analysis, syntax analysis, semantic check>)
> SQL _resolver.cc # JOIN. prepare
Generate logical query plan (SQL _optimizer.cc)
>># JOIN. optimize
Generate a physical query plan (SQL _planner.cc)
Run the explain plan (SQL _executor.cc) JOIN.exe c
JOIN. prepare ():
Remove redundant sub-queries
In subquery optimization resolve_subquery ()
Converts all/any subqueries to min/max to optimize simple subqueries.
JOIN. optimize ():
Pull flatten_subqueries () on the subquery ()
Optimize external connection to internal connection simplify_joins ()
Eliminate nested connections
Where clause, join/on clause, having clause simplification, expression simplification containing constants, equality merge optimize_cond () opt_sum_query ()
Optimize count (*) min () man () without the group by clause ()
Determine the multi-Table connection path make_join_statistice ()
Optimize distinct
Create temporary table store temporary results optimize group sorting choose_table_order ()
In fact, logical and physical optimization is a bit confusing and ambiguous,
After the physical query is optimized, some logic optimization is continued.
There are only two ways to scan a single table:
Index scan (others), table scan (JT_ALL)
Opt_range.h> class QUICK_SELECT_ I> use the index scanning drop-down Interface
For the child classes, see source code;
Main classes and struct:
Query tree class st_select_lex
Index struct st_key_create_information class Key_part_spec
Connection table st_join_table
JOIN: public SQL _alloc
Condition COND_EQUAL
Location struct st_position
Cost Estimation Cost_estimate
SELECT NOW(),CURDATE(),CURTIME()