Start with a group optimization job for the ROOT group. 从ROOT组的组优化作业开始。
This first schedules a group implementation job and waits for it to finish. 这首先安排一个组实现作业,并等待它完成。
The group implementation job first starts a group exploration job and waits for that to finish. 组实现作业首先启动组探索作业,然后等待该作业完成。
The group exploration job starts an expression exploration job for every logical expression in the group and suspends itself. 组探索作业为组中的每个逻辑表达式启动一个表达式探索作业,并挂起它自己。
Each expression exploration job first starts a group exploration job for its child groups. 每个表达式探索作业首先为其子组启动一个组探索作业。
Once the group exploration of the children is done, the expression exploration job schedules all applicable exploration transforms for this expression. 一旦完成了子对象的组探索,表达式探索作业就为该表达式安排所有适用的探索转换。
Once the expression exploration jobs for our first group are all done, the group exploration job checks whether any new expressions have been created, and schedules additional expression exploration jobs for them. This process goes on until no more new expressions are being generated. At that point, exploration is finished for all groups and expressions in Memo. 一旦我们第一组的表达式探索作业全部完成,组探索作业就会检查是否创建了任何新的表达式,并为它们安排额外的表达式探索工作。这个过程一直持续到不再生成新的表达式为止。此时,Memo中所有组和表达式的探索都已完成。
With the exploration phase finished, we are back to the group implementation task for our root group. This can now proceed to scheduling expression implementation jobs for all the logical expressions in the group. 随着探索阶段的结束,我们又回到了根组的组实现任务。现在可以继续为组中的所有逻辑表达式调度表达式实现作业。
Each expression implementation job first implements a group implementation job for its child groups. 每个表达式实现作业首先为其子组实现一个组实现作业。
Once that is done, it schedules a transformation job for every applicable implementation xform. Once these xforms are done, the job is finished. 一旦完成,它就会为每个适用的实现xform安排一个转换作业。一旦这些xforms完成,工作就完成了。
When all the expression implementation jobs are finished, the group implementation job is finished. 当所有表达式实现作业都完成时,组实现作业就完成了。
With the implementation phase finished, the group optimization job can now schedule an expression optimization job, each of which represents an optimization request, for every physical expression in the group. How many optimization requests (sets of child contexts) we try depends on the operator (CPhysical::UlOptRequests()). 随着实现阶段的完成,组优化作业现在可以为组中的每个物理表达式调度表达式优化作业,每个表达式优化作业表示优化请求。我们尝试了多少优化请求(子上下文集)取决于运算符(CPhysical::UlOptRequests())。
Each expression optimization job iterates once over its non-scalar children (first to last or last to first, depending on the operator), generating a context for the child group. It then schedules a group optimization task for that context and waits for its completion (this process gets short-cut if the context has already been optimized). Once this current child group optimization task is complete, it checks whether it makes sense to continue (e.g. whether we found a valid plan for the previous child and whether we already exceeded the cost limit). If needed, the job is finished early at this point. Otherwise, we continue with the next child. 每个表达式优化作业在其非标量子级上迭代一次(从第一个到最后一个或从最后一个到第一个,具体取决于运算符),生成子组的上下文。然后,它为该上下文安排一个组优化任务,并等待其完成(如果上下文已经优化,则此过程会缩短)。一旦当前子组优化任务完成,它将检查继续是否有意义(例如,我们是否为前一个子组找到了有效的计划,以及我们是否已经超过了成本限制)。如果需要的话,此时工作会提前完成。否则,我们继续下一个孩子。
When we have optimized all the child groups, we add enforcers for required plan properties, if needed. 当我们优化了所有子组后,如果需要,我们会为所需的计划属性添加强制器。
With that finished, the group optimization job can now schedule additional expression optimization jobs for any enforcers added to the group during optimization. 完成后,组优化作业现在可以为优化期间添加到组中的任何执行器安排额外的表达式优化作业。
When no more new enforcers are being added to the group, the optimization phase is finished and we can extract the optimal plan. 当不再有新的执行器添加到组中时,优化阶段就结束了,我们可以提取最优计划。