MySQL源码 优化器

完成了sql的解析过程后,开始进入优化器:
调用的流程分为:
    mysql_select:
          JOIN::prepare:
          JOIN::optimize:
          JOIN::exec:
          
 
 
prepare过程:
     组装各个组件,包括:stepup tables, fields, condition, order
     1. tables:
          setup_tables_and_check_access:从table_list中检查访问权限,并加入到leaf_tables中,增加tables计数。
               setup_tables&&check_single_table_access
               
     2. setup_fields
          setup_wild:如果使用了*,这个地方要解开成字段。
          find_field_in_tables:查找字段是否存在表中 
          把item生成成field。
    
     3. setup_without_group
               setup_conds:处理where条件,检索conds中的字段
               setup_order:处理order子句,检索order中的字段
               setup_group:处理group子句,检索group中的字段
 
optimize过程:
     1. simplify_joins:所有的外连接更改为内连接。
     2. build_bitmap_for_nested_joins:为嵌套的join查询建立一个bitmap。
     3. optimize_cond:优化where条件
               remove_eq_conds:删除等价的条件
     4. prune_partitions:分区修剪,这里只是分区表的处理,非分区表不做处理
     5. make_join_statistics:
               table->file->stats.records;检索引擎上对表的统计信息,
               table->s->keys:获取table_share对象上这个表的所有key。
               update_ref_and_keys:获取索引信息
               choose_plan:
                    optimize_straight_join:
                    find_best:
                    greedy_search:
 
exec的过程:
     1. do_select:分解join
     2. sub_select: Retrieve records
     3. evaluate_join_record:
 
下一篇开始进行一些实验:
posted @ 2014-06-05 11:35  xpchild  阅读(816)  评论(0编辑  收藏  举报