当前位置:网站首页>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 .
边栏推荐
- Pinia uses the whole process, including state, actions, getters, and how to deconstruct, respond, and various methods used by actions
- How to do smooth data migration: Double write scheme
- Session&Cookie&token
- MySQL下载安装 & 完美卸载
- C语言 通讯录管理系统(链表,手机号码分段存储,txt文件存取,完整源码)
- Safety fourth after class exercise
- 「Photoshop2021入门教程」“拉平”带有透视感的图像
- 【搜索】Flood Fill 和 最短路模型
- The price reduction of iphone13 is just a show. Consumers are waiting for iphone14
- Comprehensive experiment of static routing
猜你喜欢

ps怎么导入lut预设?Photoshop导入lut调色预设教程

Three cores of Redux

JS tips
![[day02] Introduction to data type conversion, operators and methods](/img/81/e2c49a4206e5d0d05308a1fc881626.png)
[day02] Introduction to data type conversion, operators and methods

Easily download data in power Bi reports with power auto
![[hcip] redistribute, redistribute and redistribute experiments](/img/53/18e1a589a85b508675c97a0108aee6.png)
[hcip] redistribute, redistribute and redistribute experiments

CEPH operation

IP 14th day notes

Comprehensive experiment of static routing

IIC communication protocol (I)
随机推荐
负数的右移
Yolov4网络详解
Cloudcompare & PCL match point distance suppression
.htaccess学习
Solution: how to use bash batch command in win10
RN development series < 9 > --mobx (1) Introduction
Title: there is an array that has been sorted in ascending order. Now enter a number and ask to insert it into the array according to the original rule.
js小技巧
「Photoshop2021入门教程」调整图片到不同的长宽比
Final review of management information system
日落红暖色调调色滤镜luts预设Sunset LUTs 1
Text processing tool in shell, cut [option parameter] filename Description: the default separator is the built-in variable of tab, awk [option parameter] '/pattern1/{action1}filename and awk
Unity:Resource Merging、Static Batching、Dynamic Batching、GPU Instancing
Summary of fire safety training materials
[C language] detailed explanation of user-defined types (structure + enumeration + Union)
Technology sharing | gtid that needs to be configured carefully_ mode
Affine transformation module and conditional batch Standardization (CBN) of detailed text generated images
Yolov4 network details
MySQL下载安装 & 完美卸载
Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"