博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL的prepare 和 execute 动作背后
阅读量:5995 次
发布时间:2019-06-20

本文共 4101 字,大约阅读时间需要 13 分钟。

我给PostgreSQL的源代码加入了调试信息以后,会有如下表现:

我执行Prepare:

postgres=# prepare s(int) as select * from tst01 t where id < $1;PREPAREpostgres=#

背后的反应:

** In PostgresMain In exec_simple_query loop for parsetree_list++++++++++++++++++++++++++Before pg_plan_queries***************In pg_plan_queries -------start................In pg_plan_queries...query->commandType == CMD_UTILITY***************In pg_plan_queries -------endIn exec_simple_query loop for parsetree_list++++++++++++++++++++++++++After pg_plan_queries...In exec_simple_query....Before PortalRun.....In PortalRun ------------start.......In PortalRunUtility ---------------start.........In ProcessUtility----Start.........In ProcessUtility----End.......In PortalRunUtility ---------------end.....In PortalRun ------------end...In exec_simple_query....After PortalRun

接着执行 Execute:

postgres=# execute s(2); id ----1(1 row)postgres=#

背后的反应:

In exec_simple_query loop for parsetree_list++++++++++++++++++++++++++Before pg_plan_queries***************In pg_plan_queries -------start................In pg_plan_queries...query->commandType == CMD_UTILITY***************In pg_plan_queries -------endIn exec_simple_query loop for parsetree_list++++++++++++++++++++++++++After pg_plan_queries...In exec_simple_query....Before PortalRun.....In PortalRun ------------startxxxxxxIn FillPortalStore ...........start.......In PortalRunUtility ---------------start.........In ProcessUtility----Start..........In standard_ProcessUtility ... Before ExecuteQuery xxxxxxxxxxxIn ExecuteQuery--------start++++++++++++In GetCachedPlan ........start.............In BuildCachedPlan, Before pg_plan_queries ***************In pg_plan_queries -------start................In pg_plan_queries...query->commandType != CMD_UTILITY..................In pg_plan_query........start*******************In planner ........start___________________In standard_planner........start********************In subquery_planner........start++++++++++++++++++++++In grouping_planner......start************************In query_planner......start........................In make_one_rel......start...........................In set_base_rel_pathlists......start-----------------------------In set_rel_pathlist......start******************************In set_plain_rel_pathlist......start-------------------------------Before add_path of seqscan-------------------------------After add_path of seqscan-------------------------------Before create_index_paths-------------------------------After create_index_path-------------------------------Before create_tidscan_paths-------------------------------After create_tidscan_paths-------------------------------Before set_cheapest-------------------------------After set_cheapest******************************In set_plain_rel_pathlist......end-----------------------------In set_rel_pathlist......end...........................In set_base_rel_pathlists......end........................In make_one_rel......end************************In query_planner......end++++++++++++++++++++++In grouping_planner......end********************In subquery_planner........end___________________In standard_planner........end*******************In planner ........end..................In pg_plan_query........end***************In pg_plan_queries -------end.............In BuildCachedPlan, After pg_plan_queries ++++++++++++In GetCachedPlan ........end.....In PortalRun ------------start.....In PortalRun ------------endxxxxxxxxxxxIn ExecuteQuery--------end..........In standard_ProcessUtility ... After ExecuteQuery .........In ProcessUtility----End.......In PortalRunUtility ---------------endxxxxxxIn FillPortalStore ...........end.....In PortalRun ------------end...In exec_simple_query....After PortalRun

按照对过去版本的认识,应当是PortalRun的时候单纯执行计划。

但是preapre....execute 方式,把它破坏了。

可以看到,prepare时候,不进行path的生成。

execute 的时候,在PortalRun的阶段,通过 ExecuteQuery->GetCachedPlan->BuildCachedPlan,

来生成path和确定plan。

不过要注意到一点是,我所执行的上述的例子中,并没有导致 param_info 非空。

可以说,这种针对单一表的preapre execute,是把执行计划的生成推后了,但是并不等于它就是 Parameterized Path。

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3144475.html,如需转载请自行联系原作者

你可能感兴趣的文章
步步为营 .NET 代码重构学习笔记系列总结
查看>>
BROKER服务器同客户端和应用服务器三者之间传递消息的格式定义
查看>>
【转】20个Cydia常见错误问题解决方法汇总
查看>>
使用jQuery和Bootstrap实现多层、自适应模态窗口
查看>>
C#中如何选择使用T[]或List<T>
查看>>
对象不支持此属性或方法
查看>>
process launch failed : failed to get the task for process xxx
查看>>
ADS1.2安装
查看>>
[华为机试练习题]9.坐标移动
查看>>
April Fools Day Contest 2016 B. Scrambled
查看>>
iOS开发--多线程
查看>>
网易游戏2015年暑期实习生面试经历-游戏研发project师
查看>>
Celery的实践指南
查看>>
Shell中的while循环【转】
查看>>
Linux下安装memcached
查看>>
qt介绍
查看>>
error
查看>>
ASP.NET MVC下使用AngularJs语言(一):Hello your name
查看>>
[书目20111003]Ivor Horton's Beginning Java, Java 7 Edition
查看>>
centos使用yum安装软件的时候出现了undefined symbol: CRYPTO_set_locking_callback
查看>>