您的位置:首页 > 数据库

PostgreSQL在何处处理 sql查询之三十四

2013-05-30 13:39 417 查看
接前面,回溯调用关系:

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之类算法被移除)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: