当前位置:网站首页>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);
...
}
六、返回結果
具體函數還為找到
边栏推荐
- pgpool-II和pgpoolAdmin的使用
- Lumion 11.0软件安装包下载及安装教程
- Sensor: DS1302 clock chip and driver code
- String or binary data will be truncated
- RC振荡器和晶体振荡器简介
- 张平安:加快云上数字创新,共建产业智慧生态
- Livox激光雷达硬件时间同步---PPS方法
- [server data recovery] data recovery case of a Dell server crash caused by raid damage
- argo workflows源码解析
- BigDecimal 的正确使用方式
猜你喜欢

The boss is quarantined

Flir Blackfly S 工业相机:通过外部触发实现多摄像头同步拍摄

使用Ceres进行slam必须要弄清楚的几个类和函数

Time synchronization of livox lidar hardware -- PPS method

Command injection of cisp-pte

Lumion 11.0软件安装包下载及安装教程

Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法

阿里云中间件开源往事

Data connection mode in low code platform (Part 1)

Sensor: introduction of soil moisture sensor (xh-m214) and STM32 drive code
随机推荐
FLIR blackfly s usb3 industrial camera: how to use counters and timers
Analyze "C language" [advanced] paid knowledge [II]
Data connection mode in low code platform (Part 1)
Redis tool class redisutil (tool class III)
3D激光SLAM:Livox激光雷达硬件时间同步
MetaForce原力元宇宙开发搭建丨佛萨奇2.0系统开发
最近小程序开发记录
Robot team learning method to achieve 8.8 times human return
FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins
企业中台建设新路径——低代码平台
Flir Blackfly S 工业相机:自动曝光配置及代码
leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
ZABBIX 5.0: automatically monitor Alibaba cloud RDS through LLD
【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
The last line of defense of cloud primary mixing department: node waterline design
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
@Before, @after, @around, @afterreturning execution sequence
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
go swagger使用