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

    接前面,回溯调用关系:

    exec_simple_query --> PortalStart --> ExecutorStart --> StandardExecutorStart --> InitPlan

    再回到 exec_simple_query 来:

    事前知道,表 tst04 对应的文件名为 16393。

    postgres=# select oid from pg_class where relname='tst04';
      oid  
    -------
     16393
    (1 row)
    
    postgres=# 

    看 exec_simple_query,加点调试信息:

    static void
    exec_simple_query(const char *query_string)
    {
        ...
        parsetree_list = pg_parse_query(query_string);
        ...
        /*
         * Run through the raw parsetree(s) and process each one.
         */
        foreach(parsetree_item, parsetree_list)
        {
            ...
            querytree_list = pg_analyze_and_rewrite(parsetree, query_string,NULL, 0);
            plantree_list = pg_plan_queries(querytree_list, 0, NULL);
            ...
            portal = CreatePortal("", true, true);
            ...
            PortalDefineQuery(portal,
                              NULL,
                              query_string,
                              commandTag,
                              plantree_list,
                              NULL);
            ...
            PortalStart(portal, NULL, 0, snapshot_set);
            ...
    
            fprintf(stderr,"Before we call PortalRun,Now sleep for 120 seconds!!!\n");
            sleep(120);
    
            /*
             * Run the portal to completion, and then drop it (and the receiver).
             */
            (void) PortalRun(portal,
                             FETCH_ALL,
                             isTopLevel,
                             receiver,
                             receiver,
                             completionTag);
    
            fprintf(stderr,"After we call PortalRun!!!\n");
            ...
        }                            /* end loop over parsetrees */
        ...
    }

    在PortalRun之前,让它休眠120秒,在此期间,将 tst04表对应文件改名。

    测试发现,改名对执行无影响、在同一客户端,再次发起对同名表的sql问,没有问题:

    [postgres@lex pgsql]$ ./bin/pg_ctl -D ./data start
    server starting
    [postgres@lex pgsql]$ LOG:  database system was shut down at 2013-05-30 13:15:52 CST
    LOG:  autovacuum launcher started
    LOG:  database system is ready to accept connections
    Before we call PortalRun,Now sleep for 120 seconds!!!
    After we call PortalRun!!!
    Before we call PortalRun,Now sleep for 120 seconds!!!
    After we call PortalRun!!!
    [postgres@lex 12788]$ mv 16393 16393.bak
    [postgres@lex 12788]$ 
    postgres=# select val from tst04;
     val 
    -----
     100
     200
     300
    (3 rows)
    
    postgres=# select id from tst04;
     id 
    ----
      1
      2
      3
    (3 rows)
    
    postgres=# 

    这说明:一旦准备好了执行计划,对文件的打开句柄将保持(除非因lru之类算法被移除)。

  • 相关阅读:
    java 递归函数
    iOS安全攻防(三):使用Reveal分析他人app
    mapreduce任务失败、重试、猜測式运行机制小结
    javascript UniqueID属性
    弧度和角度的转换
    批处理批量创建90个用户
    【设计模式】状态模式
    【.NET进程通信】初探.NET中进程间通信的简单的实现
    天将降大任于斯人也,必先苦其心志,劳其筋骨,饿其体肤,空乏其身,行拂乱其所为,所以动心忍性,增益其所不能
    冷门却使用的 javascript 技巧
  • 原文地址:https://www.cnblogs.com/gaojian/p/3108018.html
Copyright © 2011-2022 走看看