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

解决npm -v突然失效 无反应

js中树与数组的相互转化(树的子节点若为空隐藏children字段)

cocoapods的安装和使用

Login module use case writing

2019 ICPC Asia Yinchuan regional (water problem solution)

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

After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"

Redis sentinel mode setup under Windows

Arc GIS basic operation 3

V-permission add permission
随机推荐
wap端微信h5支付,用于非微信浏览器
配置ADCS后访问certsrv的问题
QT随手笔记(六)——更新界面、截图、文件对话框
Use of OpenCV class
How to add a PDB
V-permission add permission
服务器、客户端双认证
Fiddler download and installation
keepalived 实现mysql自动故障切换
asp. Net using redis cache (2)
Windows backs up the database locally by command
EOJ 2020 January race E-number transformation
tabbarController的使用
asp.net 使用redis缓存
【Mysql数据库】mysql基本操作集锦-看得会的基础(增删改查)
电机转速模糊pid控制
nodejs中mysql的使用
Wechat applet avatarcropper avatar clipping
(1) Hand eye calibration of face scanner and manipulator (eye on hand)
莫队学习总结(二)