Home > Database > Mysql Tutorial > body text

退役笔记一#MySQL=lambdasql:sql+'SourceCode4ExplainPlan'_MySQL

WBOY
Release: 2016-06-01 13:01:46
Original
940 people have browsed it

Mysql 查询执行过程 大致分为4个阶段吧:

语法分析(sql_parse.cc)

>>sql_resolver.cc # JOIN.prepare

生成逻辑查询plan(sql_optimizer.cc)

>># JOIN.optimize

生成物理查询plan(sql_planner.cc)

run the explain plan(sql_executor.cc) JOIN.exec

JOIN.prepare() :

子查询的冗余子句消除

in类型子查询优化 resolve_subquery()

将all/any等类型子查询转换为min/max操作 对简单子查询进行的优化


JOIN.optimize():

子查询上拉 flatten_subqueries()

把外连接优化为内连接 simplify_joins()

消除嵌套连接

where子句, join/on子句,having子句化简,含有常量的表达式化简,等式合并 optimize_cond() opt_sum_query()

优化没有group by 子句的下的count(*) min() man()

确定多表连接路径 make_join_statistice()

优化distinct

创建临时表存储临时结果优化分组排序 choose_table_order()

其实,逻辑与物理优化,有点混乱,分得不明确,

就是在物理查询优化之后,继续进行了部分逻辑优化

仅两种单表扫描方式:

index scan(others), table scan(JT_ALL)

Opt_range.h > class QUICK_SELECT_I > 利用索引扫描滴总接口

其几个子类 见source code;

主要的类和结构体:

查询树 class st_select_lex

索引 struct st_key_create_information class Key_part_spec

连接表 st_join_table

连接类 JOIN : public Sql_alloc

条件 COND_EQUAL

位置 struct st_position

代价估算 Cost_estimate

SELECT NOW(),CURDATE(),CURTIME()
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!