Download at Pin5i.Com
如下伪代码显示了/sql/sql_select.cc 中 handle_select()函 数的逻辑结构。
(源代码/sql/sql_select.cc 处理 SQL 查询)
handle_select()
mysql_select()
JOIN::prepare()
setup_fields()
JOIN::optimize() /* optimizer is
from here ... */
optimize_cond()
opt_sum_query()
make_join_statistics()
get_quick_record_count()
choose_plan()
/* Find the best way to access tables *
/
/* as specified by the user.
*/
optimize_straight_join()
best_access_path()
/* Find a (sub-)optimal plan among all o
r subset */
/* of all possible query plans where the
user */
/* controls the exhaustiveness of the sea
rch. */
greedy_search()
best_extension_by_limited_search()
best_access_path()
/* Perform an exhaustive search for an o
ptimal plan */
find_best()
make_join_select() /* ... to here */
JOIN::exec()
缩进行显示了哪个函数调用哪个函数,如 handle_select()函数调用
mysql_select()函数,mysql_select()函数会调用 JOIN::prepare()、
JOIN::optimize()、JOIN::exec(),以及类 推。mysql_select()函数的第一部
分是调用 JOIN::prepare(),此函数用来上下文分析、元数据建立和一些语句转
化。查询优化器函 数 JOIN::optimize()和其所有优化处理中的子路线。当执行
完 JOIN::optimize()函数后,JOIN::exec()接管并完成 JOIN::optimize()函数
优化决断后的执行工作。
虽然有 JOIN 字出现,其实查询优化器的工作会处理所有的查询类型,不单单
JOIN 联接查询。
评论1
最新资源