当前位置:网站首页>Mysql45 talking about infrastructure: how is an SQL query executed?
Mysql45 talking about infrastructure: how is an SQL query executed?
2022-07-26 05:53:00 【lingengy】

Server Layers include connectors 、 The query cache 、 analyzer 、 Optimizer 、 Actuators etc. , cover MySQL Most of the core service functions of , And all the built-in functions ( Such as date 、 Time 、 Mathematics and cryptographic functions ), All cross-storage engine functionality is implemented in this layer , Like stored procedures 、 trigger 、 View etc. .
The storage engine layer is responsible for data storage and extraction .
One 、server layer
1、 The connector
Verify user name and password , Verify reserved permissions , After a user successfully establishes a connection , Even if you use the administrator account to modify the permissions of this user , It does not affect the permissions of existing connections .
The process of establishing a connection is usually more complicated , So I suggest that you try to minimize the action of establishing connection in use , That is, try to use long connections .
But after using all the long connections , 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 this problem ? You can consider the following two options .
a、 Regularly disconnect long connections . Use it for a while , Or it can be judged in the program that a large memory consuming query has been executed , disconnect , Then query and reconnect .
b、 If you're using a MySQL 5.7 Or later , You can do this after each large operation , 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 .
2、 The query cache
characteristic : If hit, the result will be returned directly , Otherwise execution sql, Cache results .
But for the most part I would advise you not to use the query cache , Why? ? Because query caching often does more harm than good .
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 .
Fortunately MySQL This is also provided “ According to the need to use ” The way . You can set the parameters query_cache_type Set to DEMAND, So for the default SQL Statements do not use the query cache . For the statements that you decide to use the query cache , It can be used SQL_CACHE Explicitly specify , Like the following statement :
mysql> select SQL_CACHE * from T where ID=10;
MySQL 8.0 Version of the query cache directly removed the entire block .
3、 analyzer
The analyzer will do “ Lexical analysis ”. What you enter is a string with multiple Spaces SQL sentence ,MySQL You need to identify the strings in it , What is the .
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”.
After these identifications , Just do it “ Syntax analysis ”. According to the result of lexical analysis , The parser will follow the grammar rules , Judge the one you typed SQL Does the statement satisfy MySQL grammar .
If the grammar is wrong, an error will be reported .
4、 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 .
The logical result of the two execution methods is the same , But the efficiency of the execution will be different , The role of the optimizer is to decide which scheme to use .
5、 actuator
Judge the permission before execution , 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 .
边栏推荐
猜你喜欢

Benji Banas launched the second season of earn while playing bonus activities, supporting the use of multiple Benji passes!

某公司给每个工位装监控:只为看员工写代码?

又一开源神器,值得收藏学习!

Jdbc流式查询与游标查询

NFT in the eyes of blackash: the platform is crying for slaughter, and users send money to the door

Ros2 knowledge: DDS basic knowledge

Is it really hopeless to choose electronic engineering and be discouraged?

我又发现了超赞的软硬件项目,全部开源

Solve vagrant's error b:48:in `join ': incompatible character encodings: GBK and UTF-8 (encoding:: Compatib
![[论文笔记] 面向网络语音隐写的抗分组丢失联合编码](/img/ca/95476b6d4b5765f5fde82cbeda577e.png)
[论文笔记] 面向网络语音隐写的抗分组丢失联合编码
随机推荐
金仓数据库 KingbaseES SQL 语言参考手册 (7. 条件表达式)
Kingbasees SQL language reference manual of Jincang database (6. Expression)
Unity2D 动画器无法 创建过渡
Day110.尚医通:Gateway集成、医院排班管理:科室列表、根据日期统计数据、排班详情
vagrant下载速度慢的解决方法
em和rem
ament_cmake生成ROS2库并链接
二叉排序树(BST) ~
How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects
leetcode-aboutString
1.12 Web开发基础
Jincang database kingbasees SQL language reference manual (5. Operators)
语法泛化三种可行方案介绍
ES Cluster in Red status: what about write & delete operations?
高手是怎样炼成的?
Use of feign (Part 2)
卸载手机自带APP的操作步骤
LNMP architecture
MBA-day28 数的概念-练习题
1.12 basis of Web Development