当前位置:网站首页>The execution process of a select statement in MySQL
The execution process of a select statement in MySQL
2022-07-27 04:56:00 【Meme_ xp】

It's on it mysql The architecture of the figure
Divided into Server layer , And storage engine layer
First step , The connector
You will connect to this database first , It's the connector that receives you . The connector is responsible for establishing a connection with the client 、 Access permissions 、 Maintaining and managing connections .
Connect... In the command mysql It's a client tool , Used to establish a connection with the server . In the completion of the classic TCP After shaking hands , The connector is about to start authenticating your identity , This is the user name and password you entered .
Long connection and short connection
If the client does not move for a long time , The connector will automatically disconnect it . This time is determined by the parameter wait_timeout The control of the , The default value is 8 Hours .
If you ask again after eight hours, you will ask for reconnection , But the connection process is usually complicated , So try to use long connections , But long connections can also cause problems .
After all using long connection , You might notice , Sometimes MySQL Memory usage is rising very fast , This is because MySQL Memory temporarily used during execution is managed in connection objects . These resources will be released when the connection is broken . So if long connections accumulate , May cause too much memory , Killed by the system (OOM), From a phenomenological point of view MySQL Abnormal restart .
How to solve
1. Regularly disconnect long connections , To use reconnection
2.mysql5.7 And above , It can be done after larger operations . Through execution mysql_reset_connection To reinitialize the connection resources . This process does not require reconnection and re-authorization , But it restores the connection to the state it was in when it was created .
The first 2 Step , The query cache
I'll check the cache first , Executed statements and their results may be key-value On the form of , Is directly cached in memory . If it is not in the cache, go to the next step .
But most don't query the cache , Because the advantages outweigh the disadvantages
Query cache failures are very frequent , As long as there is an update to a table , All query caches on this table will be cleared . So it's likely that you're struggling to save the results , It's not in use yet , It's all cleared by an update . For databases that are under pressure to update , The hit rate for the query cache will be very low . Unless your business is a static table , It takes a long time to update . such as , A system configuration table , Then the query on this table is suitable for the query cache .
mysql 8.0 The query cache function above version has been directly deleted
The first 3 Step , analyzer
If the query cache is not hit , It's about time to actually execute the statement .
In the following order :
1.MySQL From what you typed "select" This keyword recognizes , This is a query statement . It also takes strings “T” Identify a “ Table name T”, Put the string “ID” Identify a “ Column ID”.
2. Judge sql Does the statement satisfy mysql grammar
Step four , Optimizer
The optimizer is when there are multiple indexes in a table , Decide which index to use ; Or there are multiple table associations in a statement (join) When , Determine the join order of the tables .
Step five , actuator
At the beginning of execution , Let's first judge what you do to this watch T Do you have permission to execute the query , without , An error with no permissions is returned , If you have authority , Open the table and continue . When I open my watch , The actuator is defined according to the engine of the table , Use the interface provided by the engine .
For tables with indexes , The execution logic is similar . The first time I call this “ Let's take the first row that satisfies our condition ” This interface , And then we loop “ That satisfies the next row ” This interface , These interfaces are all defined in the engine .
边栏推荐
- 2019强网杯upload
- Interesting C language
- HCIA dynamic routing rip basic experiment
- 使用Unity做一个艺术字系统
- R-score reproduction R-Precision evaluation index quantitative text generation image r-score quantitative experiment whole process reproduction (R-Precision) quantitative evaluation experiment step on
- 微信小程序编辑头像
- Simple static routing in ENSP
- 第4章 Bean对象的作用域以及生命周期
- Open the door of programming
- ps怎么导入lut预设?Photoshop导入lut调色预设教程
猜你喜欢

Interesting C language

Basic configuration of static routing to achieve network wide accessibility

js小技巧

The price reduction of iphone13 is just a show. Consumers are waiting for iphone14
![[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!](/img/26/22597a7ece0431a4e54703945a775c.jpg)
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!

ceph操作

MySQL下载安装 & 完美卸载

【搜索】DFS之连通性模型 + 搜索顺序
Full revolutionary networks for semantic segmentation (FCN)

如何重置Photoshop首选项?ps重置首选项的方法
随机推荐
【HCIP】重发布、重分布、重分发实验
Grid layout
RN development series < 9 > --mobx (1) Introduction
Technology sharing | gtid that needs to be configured carefully_ mode
Huawei's entry into the commercial market: due to the trend, there are many challenges
网络协议详解:IP
Cache read / write policies: cacheside, read/writethrough and writeback policies
小程序项目如何创建
第4章 Bean对象的作用域以及生命周期
[construction of independent stations] this website is the first choice for cross-border e-commerce companies to open online stores at sea!
Open the door of programming
Digital integrated circuit: MOS tube device chapter (I)
IP 14th day notes
Unity:Resource Merging、Static Batching、Dynamic Batching、GPU Instancing
2022 T2i text generated image Chinese Journal Paper quick view-1 (ecagan: text generated image method based on channel attention mechanism +cae-gan: text generated image technology based on transforme
TCP three handshakes and four disconnects
Easy to use mobile app automation testing framework where to find? Just collect this list!
Structural mode - bridging mode
Prometheus node exporter common monitoring indicators
报错:cannot read poperties of undefined(reading ‘then‘)