MySQL多表连接算法的一点说明

来源:互联网 发布:兰大网络继续教育学院 编辑:程序博客网 时间:2024/05/18 03:07

朋友问:

best_extension_by_limited_search, 这个函数的功能是选取余下表中代价最小的那个,这个代价最小具体指的是什么呢? 1, 遍历余下的表,选择最小代价的那个,2, 还是所有余下的表中组合代价最小的第1个表呢?
回答:
1 MySQL代码注释说:
    The algorithm begins with an empty partial plan stored in 'join->positions'
    and a set of N tables - 'remaining_tables'. Each step of the algorithm
    evaluates the cost of the partial plan extended by all access plans for
    each of the relations in 'remaining_tables', expands the current partial
    plan with the access plan that results in lowest cost of the expanded
    partial plan, and removes the corresponding relation from
    'remaining_tables'. The algorithm continues until it either constructs a
    complete optimal plan, or constructs an optimal plartial plan with size =
    search_depth.
2 best_extension_by_limited_search, 这个函数的功能是选取余下表中代价最小的那个,这个代价最小具体指的是什么呢?(如A-B-C连接,得到B-A-C连接方式的cost最小,则B-A-C是代价最小的,这样,BCA,ACB等组合方式被舍弃) 1, 遍历余下的表(注意注释和代码中对'remaining_tables'的值的变化),选择最小代价的那个,2, 还是所有余下的表中组合代价最小的第1个表呢?(所以,"余下表"表示本层次要遍历的所有表中的除已经被计算的表外的其他表. 如:A-B-C组合,当前计算完A的花费,余下B和C,则递归求BC和CB这两种连接方式的每种的cost,从而得出是ABC的cost还是ACB组合的cost小).

0 0