当前位置:网站首页>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 handy notes (VI) -- update interface, screenshot, file dialog box
- Audio and video knowledge
- 搜索模块用例编写
- wap端微信h5支付,用于非微信浏览器
- (2) Hand eye calibration of face scanner and manipulator (eye out of hand: nine point calibration)
- 2020-12-29
- sublime 安装插件
- The problem of accessing certsrv after configuring ADCs
- el-table的formatter属性的用法
- E. Two Small Strings
猜你喜欢
随机推荐
附加到进程之后,断点显示“当前不会命中断点 还没有为该文档加载任何符号”
Arc GIS basic operation 3
V-permission add permission
M-ary number STR to n-ary number
(二)面扫描仪与机械臂的手眼标定(眼在手外:九点标定)
微信小程序学习笔记1
2019 ICPC Asia Yinchuan Regional(水题题解)
Mo team learning notes (I)
微信小程序开发
Audio and video knowledge
莫队学习笔记(一)
青少年软件编程等级考试标准解读_二级
copyTo
How to add a PDB
matlab simulink实现模糊pid对中央空调时延温度控制系统控制
登录模块用例编写
nodejs服务后台执行(forever)
Source code analysis of object wait notify notifyAll
Neural network and deep learning-6-support vector machine 1-pytorch
Basic use of ArcGIS 1