zoukankan      html  css  js  c++  java
  • PostgreSQL在何处处理 sql查询之五十八

    看到了其源代码中的一段注释,似乎认识又提高了一层:

    /*
     *     INTERFACE ROUTINES
     *        ExecInitNode    -        initialize a plan node and its subplans
     *        ExecProcNode    -        get a tuple by executing the plan node
     *        ExecEndNode        -        shut down a plan node and its subplans
     *
     *     NOTES
     *        This used to be three files.  It is now all combined into
     *        one file so that it is easier to keep ExecInitNode, ExecProcNode,
     *        and ExecEndNode in sync when new nodes are added.
     *
     *     EXAMPLE
     *        Suppose we want the age of the manager of the shoe department and
     *        the number of employees in that department.  So we have the query:
     *
     *                select DEPT.no_emps, EMP.age
     *                where EMP.name = DEPT.mgr and
     *                      DEPT.name = "shoe"
     *
     *        Suppose the planner gives us the following plan:
     *
     *                        Nest Loop (DEPT.mgr = EMP.name)
     *                        /        \
     *                       /         \
     *                   Seq Scan        Seq Scan
     *                    DEPT          EMP
     *                (name = "shoe")
     *
     *        ExecutorStart() is called first.
     *        It calls InitPlan() which calls ExecInitNode() on
     *        the root of the plan -- the nest loop node.
     *
     *      * ExecInitNode() notices that it is looking at a nest loop and
     *        as the code below demonstrates, it calls ExecInitNestLoop().
     *        Eventually this calls ExecInitNode() on the right and left subplans
     *        and so forth until the entire plan is initialized.    The result
     *        of ExecInitNode() is a plan state tree built with the same structure
     *        as the underlying plan tree.
     *
     *      * Then when ExecutorRun() is called, it calls ExecutePlan() which calls
     *        ExecProcNode() repeatedly on the top node of the plan state tree.
     *        Each time this happens, ExecProcNode() will end up calling
     *        ExecNestLoop(), which calls ExecProcNode() on its subplans.
     *        Each of these subplans is a sequential scan so ExecSeqScan() is
     *        called.  The slots returned by ExecSeqScan() may contain
     *        tuples which contain the attributes ExecNestLoop() uses to
     *        form the tuples it returns.
     *
     *      * Eventually ExecSeqScan() stops returning tuples and the nest
     *        loop join ends.  Lastly, ExecutorEnd() calls ExecEndNode() which
     *        calls ExecEndNestLoop() which in turn calls ExecEndNode() on
     *        its subplans which result in ExecEndSeqScan().
     *
     *        This should show how the executor works by having
     *        ExecInitNode(), ExecProcNode() and ExecEndNode() dispatch
     *        their work to the appopriate node support routines which may
     *        in turn call these routines themselves on their subplans.

    那么,我能否一定制造出 Nest Loop效果呢

  • 相关阅读:
    模拟链表
    解密回文——栈
    解密QQ——队列
    排序算法的实现与比较
    2016年第七届蓝桥杯C/C++B组省赛题目解析
    记账类问题汇总
    斐波那契数列题型汇总
    MFC绘图小实验(1)
    MFC绘图基础——上机操作步骤
    求 pi 的近似值题型汇总
  • 原文地址:https://www.cnblogs.com/gaojian/p/3130693.html
Copyright © 2011-2022 走看看