PostgreSQL在何处处理 sql查询之十一

接前面,继续进行分析:

前面已经说过,在planner函数运行时,发生了实际物理磁盘访问。

/*****************************************************************************

 *

 *       Query optimizer entry point

 *

 * To support loadable plugins that monitor or modify planner behavior,

 * we provide a hook variable that lets a plugin get control before and

 * after the standard planning process.  The plugin would normally call

 * standard_planner().

 *

 * Note to plugin authors: standard_planner() scribbles on its Query input,

 * so you'd better copy that data structure if you want to plan more than once.

 *

 *****************************************************************************/

PlannedStmt *

planner(Query *parse, int cursorOptions, ParamListInfo boundParams)

{

    PlannedStmt *result;



    if (planner_hook)

        result = (*planner_hook) (parse, cursorOptions, boundParams);

    else

        result = standard_planner(parse, cursorOptions, boundParams);

    return result;

}



PlannedStmt *

standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)

{

    ...

/* primary planning entry point (may recurse for subqueries) */ top_plan = subquery_planner(glob, parse, NULL, false, tuple_fraction, &root);

    ...

    top_plan = set_plan_references(root, top_plan);

    ...

    forboth(lp, glob->subplans, lr, glob->subroots)

    {

        Plan       *subplan = (Plan *) lfirst(lp);

        PlannerInfo *subroot = (PlannerInfo *) lfirst(lr);



        lfirst(lp) = set_plan_references(subroot, subplan);

    }

/* build the PlannedStmt result */

    result = makeNode(PlannedStmt);

    ...

    return result;

}

接着,要分析 subquery_planner

你可能感兴趣的:(PostgreSQL)