当前位置:网站首页>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);
...
}
六、返回结果
具体函数还为找到
边栏推荐
- 新一代云原生消息队列(一)
- ROS learning (21) robot slam function package -- installation and testing of orbslam
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
- [leetcode] day97 remove linked list elements
- Flir Blackfly S USB3 工业相机:白平衡设置方法
- #yyds干货盘点# 解决名企真题:最大差值
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
- go swagger使用
- Alibaba cloud middleware open source past
猜你喜欢
Robot team learning method to achieve 8.8 times human return
Flir Blackfly S 工业相机:配置多个摄像头进行同步拍摄
Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma
Dall-E Mini的Mega版本模型发布,已开放下载
Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
张平安:加快云上数字创新,共建产业智慧生态
Infrared camera: juge infrared mag32 product introduction
ROS learning (21) robot slam function package -- installation and testing of orbslam
将截断字符串或二进制数据
[paper reading | deep reading] dngr:deep neural networks for learning graph representations
随机推荐
ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
激光雷达:Ouster OS产品介绍及使用方法
【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
Lidar: introduction and usage of ouster OS
ROS learning (22) TF transformation
Recommended collection!! Which is the best flutter status management plug-in? Please look at the ranking list of yard farmers on the island!
Seconds understand the delay and timing function of wechat applet
Golang foundation - data type
长安链学习笔记-证书研究之证书模式
Recent applet development records
The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
freeswitch拨打分机号源代码跟踪
ROS学习(十九)机器人SLAM功能包——cartographer
强化学习如何用于医学影像?埃默里大学最新《强化学习医学影像分析》综述,阐述最新RL医学影像分析概念、应用、挑战与未来方向
String or binary data will be truncated
Redis tool class redisutil (tool class III)
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma
Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野