当前位置:网站首页>The underlying logical architecture of MySQL
The underlying logical architecture of MySQL
2022-07-06 10:14:00 【Eric-x】
List of articles
1、 The server handles client requests
What does the server process do with the request sent by the client process , To produce the final processing result ? Here, take the query request as an example to show :
Let's take a look at
first floor : 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 .
The second floor : Service layer
SQL Interface: SQL Interface
- Receive the user's SQL command , And returns the result of the query that the user needs . such as SELECT … FROM It's called SQL Interface
- MySQL Support DML( Data operation language )、DDL( Data definition language )、 stored procedure 、 View 、 trigger 、 User defined functions, etc SQL Language interface
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 for it Grammar tree , And enrich the query syntax tree according to the data dictionary , Meeting Verify whether 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 a Implementation plan
- The implementation plan indicates that Which index to use The query ( 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 .
- It USES “ selection - Projection - Connect ” Strategy to query . for example
SELECT id,name FROM student WHERE gender = ' Woman ';
This SELECT The query is based on WHERE The sentence goes on selection , Instead of querying all the tables and then gender Filter . This SELECT The query is based on id and name Make attributes Projection , Instead of taking all the attributes out and filtering them later , These two query criteria Connect Get up and generate the final query results .
Caches & Buffers: Query cache component
- 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 .
- The query can be cached in Sharing between different clients .
- from MySQL 5.7.20 Start , Query caching is not recommended , And in MySQL 8.0 Delete in , Because this is chicken ribs
Little story :
If I ask you 9+8×16-3×2×17 What's the value of , You may use a calculator to calculate , final result 35. If I ask you again 9+8×16-
3×2×17 What's the value of , Do you still use another silly calculation ? We have just calculated , Just say the answer directly .
The third level : Engine layer
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 , Server pass API Communicating with the storage engine . Different storage engines have different functions , So we can choose according to our actual needs .
MySQL 8.0.25 The storage engines supported by default are as follows :
Storage layer
All data , database 、 The definition of the table , The contents of each row of the table , Indexes , All exist On the file system , In the form of a file , And complete the interaction with the storage engine . Of course, some storage engines, such as InnoDB, It also supports direct management of bare devices without using the file system , But the implementation of modern file systems makes this unnecessary . Under the file system , You can use a local disk , have access to DAS、NAS、SAN And other storage systems .
summary
Let's get familiar with SQL The execution process is convenient , We can simplify it as follows :
Simplified to a three-tier structure :
- adjoining course : Establish connection between client and server , The client sends SQL To the server side ;
- SQL layer ( Service layer ): Yes SQL Statement for query processing ; It has nothing to do with the storage mode of database files ;
- Storage engine layer : Dealing with database files , Responsible for data storage and reading .
边栏推荐
- MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
- CAPL脚本中关于相对路径/绝对路径操作的几个傻傻分不清的内置函数
- The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
- Docker MySQL solves time zone problems
- 实现以form-data参数发送post请求
- Canoe cannot automatically identify serial port number? Then encapsulate a DLL so that it must work
- A necessary soft skill for Software Test Engineers: structured thinking
- The real future of hardware engineers may not be believed by you if I say so
- Combined search /dfs solution - leetcode daily question - number of 1020 enclaves
- [Julia] exit notes - Serial
猜你喜欢
![16 medical registration system_ [order by appointment]](/img/7f/d94ac2b3398bf123bc97d44499bb42.png)
16 medical registration system_ [order by appointment]

Redis集群方案应该怎么做?都有哪些方案?

MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?

Super detailed steps for pushing wechat official account H5 messages

实现以form-data参数发送post请求

再有人问你数据库缓存一致性的问题,直接把这篇文章发给他

Carolyn Rosé博士的社交互通演讲记录

CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本

在CANoe中通過Panel面板控制Test Module 運行(初級)

软件测试工程师必备之软技能:结构化思维
随机推荐
竞赛vscode配置指南
C杂讲 动态链表操作 再讲
Write your own CPU Chapter 10 - learning notes
Preliminary introduction to C miscellaneous lecture document
实现微信公众号H5消息推送的超级详细步骤
Contest3145 - the 37th game of 2021 freshman individual training match_ B: Password
MySQL ERROR 1040: Too many connections
Vscode common instructions
[CV] target detection: derivation of common terms and map evaluation indicators
CANoe不能自动识别串口号?那就封装个DLL让它必须行
C杂讲 文件 续讲
The replay block of canoe still needs to be combined with CAPL script to make it clear
好博客好资料记录链接
Implement context manager through with
CANoe下载地址以及CAN Demo 16的下载与激活,并附录所有CANoe软件版本
CANoe CAPL文件操作目录合集
[after reading the series of must know] one of how to realize app automation without programming (preparation)
Teach you how to write the first MCU program hand in hand
Inject common SQL statement collation
South China Technology stack cnn+bilstm+attention