没有合适的资源?快使用搜索试试~ 我知道了~
//主入口函数//标准查询优化器函数//生成(子)查询执行计划//上拉子链接,ANY and EXISTS SubLinks//上拉子查询//条件、表达式化简(
资源详情
资源评论
资源推荐
//主入口函数
planner.c
planner()
//标准查询优化器函数
planner.c
standard_planner()
//生成(子)查询执行计划
planner.c
subquery_planner()
//上拉子链接,ANY and EXISTS SubLinks
prejointree.c
pull_up_sublinks()
//上拉子查询
planner.c
pull_up_subqueries()
//优化简单union all
planner.c
flatten_simple_union_all()
//条件、表达式化简(returningList、jointree、havingQual、wi
ndowClause、limitOffset、limitCount、append_rel_list、rte-
>funcexpr等)
planner.c
preprocess_expression()
preprocess_qual_conditions()
//启发优化:合并having子句到where子句
planner.c
lappend()
//优化:化简外连接为内连接
planner.c
reduce_outer_joins()
逻辑查询优化
物理查询优化
//生成查询执行计划
planner.c
grouping_planner()
//存在limit、offset子句,修改元组片段因子
planner.c
preprocess_limit()
//处理集合操作
planner.c
plan_set_operations()
//求路径排序
make_pathkeys_for_sortclauses()
//处理非集合操作
planner.c
//处理groupby
preprocess_groupclause()
//预处理目标列
preprocess_targetlist()
//处理窗口函数
find_window_functions()
select_active_windows()
//调整目标列按groupby子句
make_subplanTargetList()
//处理聚集函数(targetList、havingQual)
count_agg_clauses()
preprocess_minmax_aggregates()
//为groupby/orderby生成排序路径
make_pathkeys_for_sortclauses()
//为窗口函数生成排序路径
make_pathkeys_for_window()
//为distinct生成排序路径
make_pathkeys_for_sortclauses()
//生成最优查询路径的两个候选(排序和未排序)
query_planner()
//若有groupby,选择分组方式
choose_hashed_grouping()
//distinct优化方式
choose_hashed_distinct()
//根据f分组和distinct优化方式,选择最优路径
best_path = cheapest_path;/best_path = sorted_path;
//优化:min、max函数
best_path = cheapest_path;/best_path = sorted_path;
//根据query_planner最优查询路径生成查询执行计划
create_plan()
//生成非SPJ节点:聚集、having、窗口函数等
make_agg()/make_sort_from_groupcols()
make_sort_from_groupcols()
make_group()
make_result()
//生成非SPJ节点(集合操作外,distinctClause)
make_sort_from_pathkeys()
make_unique()
//生成非SPJ节点(集合操作外,oderby)
make_sort_from_pathkeys()
//for update clause
make_lockrows()
//生成非SPJ节点(集合操作外,limit)
make_limit()
//prepunion.c
//Generate plan for a recursive UNION node
generate_recursion_plan()
//prepunion.c
//Recursively handle one step in a tree of set operations
recurse_set_operations()
//prepunion.c
//Recursively handle one step in a tree of set operations
recurse_set_operations()
subquery_planner()
generate_union_plan()
generate_setop_tlist()
//prepunion.c
//处理没有From子句
*cheapest_path=create_result_path();*sorted_path = NULL;
//标准化其他排序键,groupby、oderby
canonicalize_all_pathkeys()
get_equality_op_for_ordering_op()
build_minmax_path()
//找出所有的基本表
add_base_rels_to_query(root, (Node *) parse->jointree);
//创建基本表(范围表)
build_simple_rel()
//处理目标列和提交表达式,生成占位符
build_base_rel_tlists(root, tlist);
find_placeholders_in_jointree(root);
//分解where、join/on子句的约束条件,构造连接树
joinlist = deconstruct_jointree(root);
//检查外连接子句,分发约束条件到对应关系
reconsider_outer_join_clauses(root);
//根据等价类生成约束条件(逻辑优化)
generate_base_implied_equalities(root);
//规范化各类排序路径pathkeys
canonicalize_all_pathkeys(root);
//Adjust the "needed at" levels for placeholder inputs
fix_placeholder_input_needed_levels(root);
//去除无用连接
joinlist = remove_useless_joins(root, joinlist);
//分发占位符到基表
add_placeholders_to_base_rels(root);
//estimate total_table_pages
//进行多表连接,得到查询计划主体(动态规划、遗传)
final_rel = make_one_rel(root, joinlist);
//根据子句类型(groupby、agg/having、distinct),确定元
组片段因子
//多表连接后的最优路径
cheapestpath = final_rel->cheapest_total_path;
sortedpath=get_cheapest_fractional_path_for_pathkeys(final
_rel->pathlist,root->query_pathkeys,NULL,tuple_fraction);
//递归处理连接树
deconstruct_recurse(root, (Node *) root->parse->jointree, f
alse, &qualscope, &inner_join_rels);
RangeTblRef:
joinlist = list_make1(jtnode);
FromExpr:
sub_joinlist = deconstruct_recurse();
joinlist = lappend(joinlist, sub_joinlist);
distribute_qual_to_rels();//约束条件下推到对应的表
JoinExpr:
JOIN_INNER、JOIN_LEFT...:deconstruct_recurse()
//生成joinlist
//Process the LEFT JOIN clauses
//Process the RIGHT JOIN clauses
//Process the FULL JOIN clauses
generate_base_implied_equalities_const(root, ec);//处理带有常量
generate_base_implied_equalities_no_const(root, ec);//带有变量
generate_base_implied_equalities_broken(root, ec);//带有不相等
//估计基本表的大小
set_base_rel_sizes(root);
//生成单表最优访问路径
set_base_rel_pathlists(root);
//生成最终最优路径
rel = make_rel_from_joinlist(root, joinlist);
//构建基本表访问路径
set_rel_pathlist(root, rel, rti, root->simple_rte_array[rti]);
//初始化连接表
RangeTblRef://基本表
thisrel = find_base_rel(root, varno);
List://递归处理子查询连接路径
thisrel = make_rel_from_joinlist(root, (List *) jlnode);
initial_rels = lappend(initial_rels, thisrel);
//遗传算法
geqo(root, levels_needed, initial_rels);
//动态规划算法
standard_join_search(root, levels_needed, initial_rels);
//搜索一层的连接方式
join_search_one_level(root, lev);
//选择最小代价路径,并保存
set_cheapest(rel);
三更寒天
- 粉丝: 83
- 资源: 326
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0