当前位置:网站首页>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语句即可开始调试



边栏推荐
- MySQL master-slave replication
- About the hacked database
- Metamask项目方给Solidity程序员的16个安全建议
- what the fuck! I'm flattered. He actually wrote down the answers to the redis interview questions that big companies often ask!
- Party, Google's autoregressive Wensheng graph model
- Mlife forum | microbiome and data mining
- Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
- Sqlserver 2000 has long-lasting vitality
- How to efficiently analyze online log
- The difference between apt and apt get
猜你喜欢

物联网?快来看 Arduino 上云啦

Getting started with the lvgl Library - colors and images

钉钉、飞书、企业微信:迥异的商业门道

On the value foam of digital copyright works from the controversial nature of "Meng Hua Lu"

CVPR 2022 - Interpretation of selected papers of meituan technical team

Nifi from introduction to practice (nanny level tutorial) - environment

"Interesting" is the competitiveness of the new era

Creation and use of unified links in Huawei applinking
![[2022 national tournament simulation] BigBen -- determinant, Du Jiao sieve](/img/ec/6c6e3d878e2a05a6e7a4ca336ae134.jpg)
[2022 national tournament simulation] BigBen -- determinant, Du Jiao sieve

一文讲透研发效能!您关心的问题都在
随机推荐
Concept + formula (excluding parameter estimation)
Babbitt | metauniverse daily must read: 618 scores have been announced. How much contribution has the digital collection made behind this satisfactory answer
Experience of IOS interview strategy - App testing and launching
申请MIMIC数据库失败怎么办?从失败到成功的经验分享给你~
Redis' contribution in the field of microservices
LVGL库入门教程 - 颜色和图像
Metamask项目方给Solidity程序员的16个安全建议
Leetcode 1218. Longest definite difference subsequence
C语言中常量的定义和使用
实现领域驱动设计 - 使用ABP框架 - 创建实体
What is SCRM? What is the difference between SCRM and CRM
How to do research on plant endophytes? Special topic on Microbiology
Smart Policing: how to use video intelligent analysis technology to help urban policing visual comprehensive supervision and command system
我真傻,招了一堆只会“谷歌”的程序员!
青藤入选工信部网安中心“2021年数字技术融合创新应用典型解决方案”
Codereview tool chain for micro medicine
Definition and use of constants in C language
Opengauss kernel: simple query execution
what the fuck! I'm flattered. He actually wrote down the answers to the redis interview questions that big companies often ask!
nifi从入门到实战(保姆级教程)——环境篇