PostgreSQL在何处处理 sql查询之四

简介:

看看portal生成完毕后,干了什么(PortalDefineQuery):

复制代码
 1         /*
 2          * Create unnamed portal to run the query or queries in. If there
 3          * already is one, silently drop it.
 4          */
 5         portal = CreatePortal("", true, true);
 6         /* Don't display the portal in pg_cursors */
 7         portal->visible = false;
 8 
 9         /*
10          * We don't have to copy anything into the portal, because everything
11          * we are passing here is in MessageContext, which will outlive the
12          * portal anyway.
13          */
14         PortalDefineQuery(portal,
15                           NULL,
16                           query_string,
17                           commandTag,
18                           plantree_list,
19                           NULL);
复制代码

再来看PortalDefineQuery的定义:

复制代码
 1 /*
 2  * PortalDefineQuery
 3  *        A simple subroutine to establish a portal's query.
 4  *
 5  * Notes: as of PG 8.4, caller MUST supply a sourceText string; it is not
 6  * allowed anymore to pass NULL.  (If you really don't have source text,
 7  * you can pass a constant string, perhaps "(query not available)".)
 8  *
 9  * commandTag shall be NULL if and only if the original query string
10  * (before rewriting) was an empty string.    Also, the passed commandTag must
11  * be a pointer to a constant string, since it is not copied.
12  *
13  * If cplan is provided, then it is a cached plan containing the stmts, and
14  * the caller must have done GetCachedPlan(), causing a refcount increment.
15  * The refcount will be released when the portal is destroyed.
16  *
17  * If cplan is NULL, then it is the caller's responsibility to ensure that
18  * the passed plan trees have adequate lifetime.  Typically this is done by
19  * copying them into the portal's heap context.
20  *
21  * The caller is also responsible for ensuring that the passed prepStmtName
22  * (if not NULL) and sourceText have adequate lifetime.
23  *
24  * NB: this function mustn't do much beyond storing the passed values; in
25  * particular don't do anything that risks elog(ERROR).  If that were to
26  * happen here before storing the cplan reference, we'd leak the plancache
27  * refcount that the caller is trying to hand off to us.
28  */
29 void
30 PortalDefineQuery(Portal portal,
31                   const char *prepStmtName,
32                   const char *sourceText,
33                   const char *commandTag,
34                   List *stmts,
35                   CachedPlan *cplan)
36 {
37     AssertArg(PortalIsValid(portal));
38     AssertState(portal->status == PORTAL_NEW);
39 
40     AssertArg(sourceText != NULL);
41     AssertArg(commandTag != NULL || stmts == NIL);
42 
43     portal->prepStmtName = prepStmtName;
44     portal->sourceText = sourceText;
45     portal->commandTag = commandTag;
46     portal->stmts = stmts;
47     portal->cplan = cplan;
48     portal->status = PORTAL_DEFINED;
49 }
复制代码

根据参数调用的情况:

*prepStmtName是NULL,sourceText是 query_string,commandTag传递了。
Lits *stmts 是 exec_simple_query中生成的 plantree_list,CachedPlan *cplan 是空值。

在我使用 select * from tab01 这种语句的时候,commandTag是 SELECT。







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

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
3月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS费用价格:MySQL、SQL Server、PostgreSQL和MariaDB引擎收费标准
阿里云RDS数据库支持MySQL、SQL Server、PostgreSQL、MariaDB,多种引擎优惠上线!MySQL倚天版88元/年,SQL Server 2核4G仅299元/年,PostgreSQL 227元/年起。高可用、可弹性伸缩,安全稳定。详情见官网活动页。
784 152
|
3月前
|
SQL 监控 关系型数据库
一键开启百倍加速!RDS DuckDB 黑科技让SQL查询速度最高提升200倍
RDS MySQL DuckDB分析实例结合事务处理与实时分析能力,显著提升SQL查询性能,最高可达200倍,兼容MySQL语法,无需额外学习成本。
|
3月前
|
SQL 存储 关系型数据库
MySQL体系结构详解:一条SQL查询的旅程
本文深入解析MySQL内部架构,从SQL查询的执行流程到性能优化技巧,涵盖连接建立、查询处理、执行阶段及存储引擎工作机制,帮助开发者理解MySQL运行原理并提升数据库性能。
|
3月前
|
SQL 监控 关系型数据库
SQL优化技巧:让MySQL查询快人一步
本文深入解析了MySQL查询优化的核心技巧,涵盖索引设计、查询重写、分页优化、批量操作、数据类型优化及性能监控等方面,帮助开发者显著提升数据库性能,解决慢查询问题,适用于高并发与大数据场景。
|
3月前
|
关系型数据库 分布式数据库 数据库
阿里云数据库收费价格:MySQL、PostgreSQL、SQL Server和MariaDB引擎费用整理
阿里云数据库提供多种类型,包括关系型与NoSQL,主流如PolarDB、RDS MySQL/PostgreSQL、Redis等。价格低至21元/月起,支持按需付费与优惠套餐,适用于各类应用场景。
|
2月前
|
SQL 关系型数据库 MySQL
(SQL)SQL语言中的查询语句整理
查询语句在sql中占了挺大一部分篇幅,因为在数据库中使用查询语句的次数远多于更新与删除命令。而查询语句比起其他语句要更加的复杂,可因为sql是数据库不可或缺的一部分,所以即使不懂,也必须得弄懂,以上。
243 0
|
4月前
|
SQL XML Java
通过MyBatis的XML配置实现灵活的动态SQL查询
总结而言,通过MyBatis的XML配置实现灵活的动态SQL查询,可以让开发者以声明式的方式构建SQL语句,既保证了SQL操作的灵活性,又简化了代码的复杂度。这种方式可以显著提高数据库操作的效率和代码的可维护性。
313 18
|
3月前
|
关系型数据库 MySQL 数据库
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎
阿里云数据库RDS支持MySQL、SQL Server、PostgreSQL和MariaDB引擎,提供高性价比、稳定安全的云数据库服务,适用于多种行业与业务场景。
|
4月前
|
SQL 人工智能 数据库
【三桥君】如何正确使用SQL查询语句:避免常见错误?
三桥君解析了SQL查询中的常见错误和正确用法。AI产品专家三桥君通过三个典型案例:1)属性重复比较错误,应使用IN而非AND;2)WHERE子句中非法使用聚合函数的错误,应改用HAVING;3)正确的分组查询示例。三桥君还介绍了学生、课程和选课三个关系模式,并分析了SQL查询中的属性比较、聚合函数使用和分组查询等关键概念。最后通过实战练习帮助读者巩固知识,强调掌握这些技巧对提升数据库查询效率的重要性。
158 0
|
5月前
|
SQL
SQL中如何删除指定查询出来的数据
SQL中如何删除指定查询出来的数据

推荐镜像

更多