当前位置:网站首页>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);
...
}
六、返回结果
具体函数还为找到
边栏推荐
- What to do when encountering slow SQL? (next)
- MetaForce原力元宇宙开发搭建丨佛萨奇2.0系统开发
- Input and output of C language pointer to two-dimensional array
- Flir Blackfly S 工业相机 介绍
- FLIR blackfly s industrial camera: auto exposure configuration and code
- Cat recycling bin
- Redis configuration class redisconfig
- The empirical asset pricing package (EAP) can be installed through pypi
- Flir Blackfly S 工业相机:自动曝光配置及代码
- [leetcode] day97 remove linked list elements
猜你喜欢
Correct use of BigDecimal
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
云原生混部最后一道防线:节点水位线设计
阿里云中间件开源往事
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
张平安:加快云上数字创新,共建产业智慧生态
【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
Command injection of cisp-pte
【服务器数据恢复】raid损坏导致戴尔某型号服务器崩溃的数据恢复案例
1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效
随机推荐
Vingt - trois mille feuilles? "Yang mou" derrière l'explosion de la consommation végétale
豆瓣平均 9.x,分布式领域的 5 本神书!
Web开发小妙招:巧用ThreadLocal规避层层传值
UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“
FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method
ROS learning (XIX) robot slam function package cartographer
Several classes and functions that must be clarified when using Ceres to slam
Recognition of C language array
centos8安裝mysql報錯:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
ROS learning (22) TF transformation
#yyds干货盘点# 解决名企真题:最大差值
Draco - glTF模型压缩利器
猫猫回收站
Batch delete data in SQL - set in entity
The use of video in the wiper component causes full screen dislocation
Centos8 install MySQL 8.0 using yum x
Blackfly S USB3工业相机:缓冲区处理
【LeetCode】Day97-移除链表元素
Flir Blackfly S 工业相机:配置多个摄像头进行同步拍摄