当前位置:网站首页>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);
...
}
六、返回結果
具體函數還為找到
边栏推荐
- The last line of defense of cloud primary mixing department: node waterline design
- 企业中台建设新路径——低代码平台
- Sensor: introduction of soil moisture sensor (xh-m214) and STM32 drive code
- centos8 用yum 安装MySQL 8.0.x
- Draco - glTF模型压缩利器
- Treadpoolconfig thread pool configuration in real projects
- Seconds understand the delay and timing function of wechat applet
- 张平安:加快云上数字创新,共建产业智慧生态
- Metaforce force meta universe development and construction - fossage 2.0 system development
- Decryption function calculates "task state and lifecycle management" of asynchronous task capability
猜你喜欢

Flir Blackfly S 工业相机 介绍

MySQL execution process and sequence

CISP-PTE实操练习讲解(二)

【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs

本周 火火火火 的开源项目!

Draco - glTF模型压缩利器

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

Data connection mode in low code platform (Part 1)

【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件

Lombok同时使⽤@Data和@Builder 的坑
随机推荐
sql中批量删除数据---实体中的集合
ROS learning (26) dynamic parameter configuration
The last line of defense of cloud primary mixing department: node waterline design
FLIR blackfly s industrial camera: auto exposure configuration and code
张平安:加快云上数字创新,共建产业智慧生态
传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
Cat recycling bin
How did partydao turn a tweet into a $200million product Dao in one year
Analyze "C language" [advanced] paid knowledge [II]
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
Web开发小妙招:巧用ThreadLocal规避层层传值
XML to map tool class xmlmaputils (tool class V)
3D laser slam: time synchronization of livox lidar hardware
postgresql之整体查询大致过程
MetaForce原力元宇宙开发搭建丨佛萨奇2.0系统开发
Blackfly s usb3 industrial camera: buffer processing
STM32F4---通用定时器更新中断
Blackfly S USB3工业相机:缓冲区处理
@Before, @after, @around, @afterreturning execution sequence
Stm32f4 --- general timer update interrupt