当前位置:网站首页>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);
...
}
六、返回结果
具体函数还为找到
边栏推荐
- BigDecimal 的正确使用方式
- Analyze "C language" [advanced] paid knowledge [II]
- Input and output of C language pointer to two-dimensional array
- 新一代云原生消息队列(一)
- String or binary data will be truncated
- 云原生混部最后一道防线:节点水位线设计
- FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
- TiFlash 源码阅读(四)TiFlash DDL 模块设计及实现分析
- FLIR blackfly s industrial camera: auto exposure configuration and code
- Golang foundation - data type
猜你喜欢
@Before, @after, @around, @afterreturning execution sequence
FLIR blackfly s industrial camera: auto exposure configuration and code
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法
解密函数计算异步任务能力之「任务的状态及生命周期管理」
建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!
一片葉子兩三萬?植物消費爆火背後的“陽謀”
【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
随机推荐
Batch delete data in SQL - set in entity
Vingt - trois mille feuilles? "Yang mou" derrière l'explosion de la consommation végétale
Centos8 install MySQL 8.0 using yum x
Blackfly S USB3工业相机:缓冲区处理
Stm32f4 --- PWM output
Unicode string converted to Chinese character decodeunicode utils (tool class II)
使用Ceres进行slam必须要弄清楚的几个类和函数
一片葉子兩三萬?植物消費爆火背後的“陽謀”
Flir Blackfly S 工业相机:自动曝光配置及代码
张平安:加快云上数字创新,共建产业智慧生态
FLIR blackfly s industrial camera: auto exposure configuration and code
Freeswitch dials extension number source code tracking
ROS学习(十九)机器人SLAM功能包——cartographer
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
Several classes and functions that must be clarified when using Ceres to slam
Draco - glTF模型压缩利器
大咖云集|NextArch基金会云开发Meetup来啦!
Ros Learning (23) Action Communication Mechanism
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
ROS learning (22) TF transformation