当前位置:网站首页>Logical architecture of MySQL
Logical architecture of MySQL
2022-07-26 09:36:00 【Little Zhang free - & gt; Zhang Youbo】
Catalog
Introduce
We usually write one SQL,MySQL How to receive SQL, perform SQL, And return the query results to the client . How is this set of processes executed , Let's talk about MySQL The logical structure of .
Overview map

Specific processing flow 
We can see from the picture that ,MySQL The program receives the request from the client through three parts , Connection management 、 Analysis and optimization 、 Storage engine .
adjoining course
System ( client ) visit MySQL In front of the server , The first thing to do is to establish TCP Connect .
After three handshakes, the connection is established successfully ,MySQL Server pair TCP The transmitted account and password are used for identity authentication 、 Access .
- Wrong user name or password , I'll get one Access denied for user error , The client program completes execution
- User name password authentication passed , From the permission table, you will find out the permission of the account and the connection Association , The following permission judgment logic , Will depend on the permissions read at this time
TCP After the connection receives the request , Must be assigned to a thread dedicated to the interaction with this client . So there will be a thread pool , Go to the later process . Each connection gets threads from the thread pool , Eliminates the overhead of creating and destroying threads .
Service layer
Caches & Buffers: Query cache component
Server If you find this in the query cache SQL sentence , The result will be returned directly to the client ; without , We're in the parser phase . It should be noted that , Because query caching is often inefficient , So in MySQL8.0 After that, I abandoned this function .
MySQL There's some internal maintenance Cache and Buffer, such as Query Cache Used to cache a SELECT Statement execution result , If the corresponding query result can be found in it , Then there is no need to query and parse 、 Optimization and execution of the whole process , Directly feed back the results to the client .
The caching mechanism consists of a series of small caches . For example, table caching , Record the cache ,key cache , Authority cache, etc .
This query cache can be shared between different clients .
from MySQL 5.7.20 Start , Query caching is not recommended , And in MySQL 8.0 Delete in .
Parser: Parser
In the parser SQL Statement syntax analysis 、 Semantic analysis . take SQL Statements are decomposed into data structures , And pass the structure to the next step , in the future SQL Statements are passed and processed based on this structure . If you encounter an error in the decomposition composition , So that's it SQL The statement is unreasonable .
stay SQL Commands are validated and parsed by the parser when they are passed to the parser , And create a syntax tree for it , And enrich the query syntax tree according to the data dictionary , Will verify that the client has permission to execute the query . After creating the syntax tree ,MySQL Will also be right SQL Query syntax optimization , Query rewriting .

Optimizer: Query optimizer
SQL Statement after syntax parsing 、 Before the query, the query optimizer will be used to determine SQL Statement execution path , Generate an execution plan .
This execution plan indicates which indexes should be used for queries ( Full table search or index search ), What is the connection order between tables , Finally, the method provided by the storage engine will be called according to the steps in the execution plan to truly execute the query , And return the query results to the user .
actuator
Before execution, you need to judge whether the user Have authority . without , A permission error will be returned . If you have permission , Is executed SQL Query and return the result . stay MySQL8.0 The following version , If query cache is set , At this time, the query results will be cached .
Engine layer
Up to now , There's no real access to real data tables .
MySQL The server encapsulates the data storage and extraction operations into a file called Storage engine In the module of . We know surface It consists of line by line records , But it's just a logical concept , How to represent records physically , How to read data from a table , How to write data to specific physical memory , This is all Storage engine Responsible things .
Plug in storage engine layer ( Storage Engines), Really responsible MySQL The storage and extraction of data in , Perform operations on the underlying data maintained at the physical server level , The service layer through API Communicating with the storage engine .
So in MySQL server After query optimization , You only need to call the API, Just get the data and return it to the client .
summary

SQL Statements in MySQL The process in is : SQL sentence → adjoining course → The query cache → Parser → Optimizer → actuator → Storage engine extracts and stores data .
If this blog is of some help to you , You remember Leaving a message. + give the thumbs-up + Collection Oh
边栏推荐
猜你喜欢

Qt随手笔记(三)在vs中使用QtCharts画折线图

【荧光字效果】

Server and client dual authentication (2)

R语言ggplot2可视化: 将图例标题(legend title)对齐到ggplot2中图例框的中间(默认左对齐、align legend title to middle of legend)

Fiddler下载安装

asp. Net using redis cache

MQTT X CLI 正式发布:强大易用的 MQTT 5.0 命令行工具

Zxing simplified version, reprinted

小程序纪录
![[MySQL] understand the important architecture of MySQL (I)](/img/89/5fb595b0112fac987626857b76f9a4.png)
[MySQL] understand the important architecture of MySQL (I)
随机推荐
IIS网站配置
MQTT X CLI 正式发布:强大易用的 MQTT 5.0 命令行工具
Force deduction brush questions, sum of three numbers
[MySQL] understand the important architecture of MySQL (I)
QT handy notes (VI) -- update interface, screenshot, file dialog box
C# 托管与非托管
The combination of officially issued SSL certificate and self signed certificate realizes website two-way authentication
Basic use of ArcGIS 4
学习笔记之常用数组api 改变原数组和不改变原数组的有哪些?
设置视图动态图片
copyTo
阿里云技术专家郝晨栋:云上可观测能力——问题的发现与定位实践
EOJ 2020 1月月赛 E数的变换
Implementation of fragment lazy loading after multi-layer nesting
高斯消元的应用
tabbarController的使用
搜索模块用例编写
sublime 安装插件
选择器的使用
How to add a PDB