当前位置:网站首页>openGauss内核:简单查询的执行
openGauss内核:简单查询的执行
2022-06-24 12:47:00 【华为云开发者联盟】
摘要:本文主要分析简单查询语句在业务处理线程Postgres上的执行流程,并介绍如何利用gdb梳理代码逻辑。
本文分享自华为云社区《openGauss内核分析(二):简单查询的执行》,作者:Gauss松鼠会。
简单查询的执行
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_**yze_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语句即可开始调试



边栏推荐
- Baidu simian: talk about persistence mechanism and rdb/aof application scenario analysis!
- 1. Snake game design
- [live broadcast of celebrities] elastic observability workshop
- How long will it take to open a mobile account? Is online account opening safe?
- How does Argo family bucket make Devops easier?
- Attack popular science: DDoS
- Common special characters in JS and TS
- Reset the password, and the automatic login of the website saved by chrome Google browser is lost. What is the underlying reason?
- WPF from zero to 1 tutorial details, suitable for novices on the road
- 如何高效的分析online.log
猜你喜欢

Quickly understand the commonly used message summarization algorithms, and no longer have to worry about the thorough inquiry of the interviewer

Concept + formula (excluding parameter estimation)

【数据挖掘】期末复习(样卷题目+少量知识点)

谁是鱼谁是饵?红队视角下蜜罐识别方式汇总

WPF从零到1教程详解,适合新手上路

WPF from zero to 1 tutorial details, suitable for novices on the road

一文讲透研发效能!您关心的问题都在

Who said that "programmers are useless without computers? The big brother around me disagrees! It's true

爱可可AI前沿推介(6.24)

CVPR 2022 - Interpretation of selected papers of meituan technical team
随机推荐
The data value reported by DTU cannot be filled into Tencent cloud database through Tencent cloud rule engine
How can junior middle school developers effectively reduce their own workload?
what the fuck! I'm flattered. He actually wrote down the answers to the redis interview questions that big companies often ask!
青藤入选工信部网安中心“2021年数字技术融合创新应用典型解决方案”
How to do research on plant endophytes? Special topic on Microbiology
"I, an idiot, have recruited a bunch of programmers who can only" Google "
J'a i ouvert quelques mots d'un ami et quelques réflexions personnelles sur le livre des six ancêtres
IIS WCF 808 port service access exception
The agile way? Is agile development really out of date?
Smart Policing: how to use video intelligent analysis technology to help urban policing visual comprehensive supervision and command system
SCRM, a breakthrough in the new consumption era
Opengauss kernel: simple query execution
Who is the fish and who is the bait? Summary of honeypot recognition methods from the perspective of red team
Use abp Zero builds a third-party login module (I): Principles
Sphere, openai and ai21 jointly publish the best practice guidelines for deployment models
The 35 "top 100 counties" of tmall 618 agricultural products come from the central and western regions and Northeast China
Sinomeni vine was selected as the "typical solution for digital technology integration and innovative application in 2021" of the network security center of the Ministry of industry and information te
Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
How stupid of me to hire a bunch of programmers who can only "Google"!
Party, Google's autoregressive Wensheng graph model