1.2 best_extension

   best_extension中调用函数best_extension_by_limited_search完成递归遍历,其输入是部分执行计划(pplan)和它的成本,函数目的是找到下一个关联的表。思路很简单,遍历所有剩余表,对每一个表,计算对应的"局部"最优执行计划,当然计算这个“局部”最优仍然是调用这个函数,所以这是一个深度优先的遍历。

   伪代码(是不是又有人说我总贴代码了):

 5171 @code

 5172 procedure best_extension_by_limited_search(

 5173 pplan in, // in, partial plan of tables-joined-so-far

 5174 pplan_cost, // in, cost of pplan

 5175 remaining_tables, // in, set of tables not referenced in pplan

 5176 best_plan_so_far, // in/out, best plan found so far

 5177 best_plan_so_far_cost,// in/out, cost of best_plan_so_far

 5178 search_depth) // in, maximum size of the plans being considered

 5179 {

       5180 for each table T from remaining_tables

       5181 {

             5182 // Calculate the cost of using table T as above

             5183 cost = complex-series-of-calculations;

             5184

             5185 // Add the cost to the cost so far.

             5186 pplan_cost+= cost;

             5187

             5188 if (pplan_cost >= best_plan_so_far_cost)

             5189 // pplan_cost already too great, stop search

             5190 continue;

             5191


全文:http://bbs.landingbj.com/t-0-250315-1.html