当前位置:网站首页>openGauss简单查询SQL的执行流程解析
openGauss简单查询SQL的执行流程解析
2022-06-11 15:36:00 【Gauss松鼠会】
目录
上一期酷哥分析了openGauss数据库的启动过程,包括主线程,辅助线程及业务处理线程的启动过程,这一期主要分析简单查询语句在业务处理线程Postgres上的执行流程,并介绍如何利用gdb梳理代码逻辑。
简单查询的执行
SQL引擎是数据库系统的入口,执行用户简单查询的入口函数是exec_simple_query。运行在业务处理线程Postgres。
通常可以把SQL引擎分成SQL解析和查询优化两个主要的模块,SQL引擎对输入的SQL语言进行词法分析、语法分析、语义分析,从而生成逻辑执行计划,逻辑执行计划经过代数优化和代价优化之后,产生物理执行计划。
在SQL引擎将用户的查询解析优化成可执行的计划之后,数据库进入查询执行阶段。执行器基于执行计划对相关数据进行提取、运算、更新、删除等操作,以达到用户查询想要实现的目的。

exec_simple_query

1.start_xact_command():开始一个事务
2.pg_parse_query():对查询语句进行词法和语法分析,生成一个或者多个初始的语法分析树
3. 进入foreach (parsetree_item, parsetree_list)循环,对每个语法分析树执行查询
4. pg_analyze_and_rewrite():根据语法分析树生成基于Query数据结构的逻辑查询树,并进行重写等操作
5. pg_plan_queries():对逻辑查询树进行优化,生成查询计划
6. CreatePortal():创建Portal, Portal是执行SQL语句的载体,每一条SQL对应唯一的Portal
7. PortalStart():负责进行Portal结构体初始化工作,包括执行算子初始化、内存上下文分配等
8. PortalRun():负责真正的执行和运算,它是执行器的核心
9. PortalDrop():负责最后的清理工作,主要是数据结构、缓存的清理
10. finish_xact_command():完成事务提交
11. EndCommand():通知客户端查询执行完成
gdb调试
调试需要用到符号信息,configure使用如下命令
./configure --gcc-version=7.3.0 CC=g++ CFLAGS='-O0' --prefix=$GAUSSHOME --3rd=$BINARYLIBS --enable-debug --enable-cassert --enable-thread-safety --with-readline --without-zlibgdb attach 进程号,这里进程号为17012
gdb attach 17012info threads查看所有线程,t 线程号切换线程,bt可以查看线程调用栈

也可以使用linux工具gstack 打印函数调用栈

以调试select语句为例,gdb attach 进程号,在exec_simple_query打上断点,执行select语句即可开始调试



边栏推荐
- 知网被立案调查;字节跳动成立抖音集团,或在港上市;钉钉被曝裁员30%;北京人均存款超20万元 |Q资讯
- In June, 2019, cat teacher's report on monitoring
- 2022 Tibet's latest eight major construction personnel (labor workers) simulation test question bank and answers
- Learnopongl notes (IV) - Advanced OpenGL II
- Shutter-- page Jump animation
- 测试9年,面试华为要薪1万,华为员工:公司没这么低工资的岗
- Summary of redis basic knowledge
- 03 _ 事务隔离:为什么你改了我还看不见?
- [creation mode] prototype mode
- Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container..
猜你喜欢

With a loss of 13.6 billion yuan in three years, can listing revive Weima?
![[process blocks and methods of SystemVerilog] ~ domain, always process block, initial process block, function, task, life cycle](/img/c7/ff28df36b8d5dda704aa829dd5264f.png)
[process blocks and methods of SystemVerilog] ~ domain, always process block, initial process block, function, task, life cycle

C language simple webserver

Elk log analysis system

Design and implementation of data analysis system

【创建型模式】建造者模式

04 _ 深入浅出索引(上)

What is excess product power? Find the secret key of the second generation cs75plus in the year of the tiger
![[azure application service] nodejs express + msal realizes the authentication experiment of API Application token authentication (AAD oauth2 idtoken) -- passport authenticate()](/img/11/7262211654680512dae0a9a696740e.png)
[azure application service] nodejs express + msal realizes the authentication experiment of API Application token authentication (AAD oauth2 idtoken) -- passport authenticate()

Let me tell you the benefits of code refactoring
随机推荐
Exporting data using mysqldump
Simple C language address book
[azure application service] nodejs express + msal realizes the authentication experiment of API Application token authentication (AAD oauth2 idtoken) -- passport authenticate('oauth-bearer', {session:
Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container..
04 _ 深入浅出索引(上)
02 _ Log system: how does an SQL UPDATE statement execute?
A former employee of Baidu was awarded 1.07 million yuan for job hopping; Apple, Google and Microsoft plan to "kill" the password; It is said that Geely has acquired Meizu | Q information
将配置导出到FTP或TFTP服务器
HowNet has been filed for investigation; Byte beat established Tiktok group or listed in Hong Kong; The nail was exposed to be cut by 30%; Beijing's per capita deposit exceeds 200000 yuan | Q informat
Charles自动保存响应数据
Elk log analysis system
PHP Apache built-in stress testing tool AB (APACHE bench)
回溯法/活动安排 最大兼容活动
线程实战入门【硬核慎入!】
Devil cold rice # 037 devil shares the ways to become a big enterprise; Female anchor reward routine; Self discipline means freedom; Interpretation of simple interest and compound interest
[creation mode] builder mode
Arthas practice documentation
Safepoint explanation and analysis of its placement ideas
Implementation of placing the scroll bar on the top of the uniapp
Uniapp develops wechat applet from build to launch