当前位置:网站首页>postgresql之整體查詢大致過程
postgresql之整體查詢大致過程
2022-07-07 02:20: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);
...
}
六、返回結果
具體函數還為找到
边栏推荐
- Dall-E Mini的Mega版本模型发布,已开放下载
- @Before, @after, @around, @afterreturning execution sequence
- Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
- Analyze "C language" [advanced] paid knowledge [II]
- The empirical asset pricing package (EAP) can be installed through pypi
- go swagger使用
- 一片葉子兩三萬?植物消費爆火背後的“陽謀”
- 【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
- 2022/0524/bookstrap
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
猜你喜欢
Alibaba cloud middleware open source past
豆瓣平均 9.x,分布式领域的 5 本神书!
张平安:加快云上数字创新,共建产业智慧生态
Infrared camera: juge infrared mag32 product introduction
组合导航:中海达iNAV2产品描述及接口描述
CISP-PTE之命令注入篇
Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins
String or binary data will be truncated
New generation cloud native message queue (I)
postgresql之整体查询大致过程
随机推荐
Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!
Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins
Redis tool class redisutil (tool class III)
【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
Blackfly s usb3 industrial camera: buffer processing
纽约大学 CITIES 研究中心招聘理学硕士和博士后
Treadpoolconfig thread pool configuration in real projects
Robot team learning method to achieve 8.8 times human return
处理streamlit库上传的图片文件
GEE升级,可以实现一件run tasks
Several classes and functions that must be clarified when using Ceres to slam
机器人队伍学习方法,实现8.8倍的人力回报
How to use strings as speed templates- How to use String as Velocity Template?
The last line of defense of cloud primary mixing department: node waterline design
6 seconds to understand the book to the Kindle
低代码平台中的数据连接方式(上)
Data connection mode in low code platform (Part 1)
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Flir Blackfly S 工业相机:自动曝光配置及代码