当前位置:网站首页>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
边栏推荐
猜你喜欢

Neural network and deep learning-6-support vector machine 1-pytorch

Drawing shadow error diagram with MATLAB

Qt随手笔记(三)在vs中使用QtCharts画折线图
![[MySQL] understand the important architecture of MySQL (I)](/img/89/5fb595b0112fac987626857b76f9a4.png)
[MySQL] understand the important architecture of MySQL (I)

面试突击68:为什么 TCP 需要 3 次握手?

【Mysql数据库】mysql基本操作集锦-看得会的基础(增删改查)

微信小程序学习笔记1

注册模块用例编写

小白搞一波深拷贝 浅拷贝

Search module use case writing
随机推荐
官方颁发的SSL证书与自签名证书结合实现网站双向认证
asp. Net using redis cache (2)
Windows backs up the database locally by command
Redis sentinel mode setup under Windows
系统安装Serv-U后IIS出错提示:HRESULT:0x80070020
Process32First返回false,错误x信息24
Login module use case writing
Gauss elimination solves the inverse of matrix (Gauss)
IIS网站配置
添加dll
Server and client dual authentication (2)
TabbarController的封装
网站设计需要的基本知识
RMQ学习笔记
高斯消元
v-premission添加权限
微信小程序图片无法显示时显示默认图片
Wechat applet avatarcropper avatar clipping
设置视图动态图片
Solve "note: one or more layouts are missing the layout_width or layout_height attributes."