当前位置:网站首页>postgresql之整体查询大致过程
postgresql之整体查询大致过程
2022-07-06 18:39:00 【happytree001】
客户端通过pg服务器查询的大致过程如下
一、 建立连接
客户端首先需要连接上pg服务器,服务器在和客户端建立连接后fork一个子进程处理后续客户端的请求,服务器然后等待下一个客户端的连接。
二、发送请求
客户端发送请求数据给pg服务器,pg子进程读取请求。
- 客户端发送请求
比如命令行,读取用户输入,发送给服务器src/bin/psql/mainloop.c
int
MainLoop(FILE *source)
{
...
SendQuery(query_buf->data);
...
}
- 服务器接收请求
void
PostgresMain(int argc, char *argv[],
const char *dbname,
const char *username)
{
...
for (;;)
{
...
firstchar = ReadCommand(&input_message);
...
}
}
三、解析
以简单查询为例子。服务器接收到的是一串字符串,需要解析理解这个数据才能执行。
src/backend/tcop/postgres.c
static void
exec_simple_query(const char *query_string)
{
...
parsetree_list = pg_parse_query(query_string);
...
}
通过词法以及语法解析,构建一个原始的语法树。
四、优化
static void
exec_simple_query(const char *query_string)
{
...
querytree_list = pg_analyze_and_rewrite(parsetree, query_string,
NULL, 0, NULL);
plantree_list = pg_plan_queries(querytree_list, query_string,
CURSOR_OPT_PARALLEL_OK, NULL);
..
}
将原始的语法树转化为一个查询树,并且对查询树进行优化以及重写,提升执行速度。
五、执行
static void
exec_simple_query(const char *query_string)
{
...
(void) PortalRun(portal,
FETCH_ALL,
true, /* always top level */
true,
receiver,
receiver,
&qc);
...
}
六、返回结果
具体函数还为找到
边栏推荐
- The use of video in the wiper component causes full screen dislocation
- ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
- Sensor: introduction of soil moisture sensor (xh-m214) and STM32 drive code
- How can reinforcement learning be used in medical imaging? A review of Emory University's latest "reinforcement learning medical image analysis", which expounds the latest RL medical image analysis co
- Analyze "C language" [advanced] paid knowledge [i]
- FLIR blackfly s industrial camera: auto exposure configuration and code
- 【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
- 2022/0524/bookstrap
- Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption
猜你喜欢
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
ROS学习(十九)机器人SLAM功能包——cartographer
3D laser slam: time synchronization of livox lidar hardware
SchedulX V1.4.0及SaaS版发布,免费体验降本增效高级功能!
@Before, @after, @around, @afterreturning execution sequence
豆瓣平均 9.x,分布式领域的 5 本神书!
BigDecimal 的正确使用方式
Batch delete data in SQL - set in entity
Blackfly s usb3 industrial camera: buffer processing
The boss is quarantined
随机推荐
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
Analyze "C language" [advanced] paid knowledge [II]
Date processing tool class dateutils (tool class 1)
Blackfly S USB3工业相机:缓冲区处理
处理streamlit库上传的图片文件
Cisp-pte practice explanation (II)
New generation cloud native message queue (I)
Seconds understand the delay and timing function of wechat applet
Redis configuration class redisconfig
centos8安裝mysql報錯:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
大咖云集|NextArch基金会云开发Meetup来啦!
Recognition of C language array
组合导航:中海达iNAV2产品描述及接口描述
freeswitch拨打分机号源代码跟踪
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
Word wrap when flex exceeds width
FLIR blackfly s industrial camera: configure multiple cameras for synchronous shooting
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“