当前位置:网站首页>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 .
边栏推荐
- Balanced binary tree (AVL)~
- Use of feign (Part 2)
- [论文笔记] 面向网络语音隐写的抗分组丢失联合编码
- [personal summary] end of July 24, 2022
- Is it really hopeless to choose electronic engineering and be discouraged?
- Day110.尚医通:Gateway集成、医院排班管理:科室列表、根据日期统计数据、排班详情
- Rocbossphp free open source light community system
- Redis transaction
- Redis persistence AOF
- unity 像素画导入模糊问题
猜你喜欢
随机推荐
Jincang database kingbasees SQL language reference manual (5. Operators)
A company installs monitoring for each station: write code only to see employees?
MBA-day29 算术-绝对值初步认识
2022 National latest fire-fighting facility operator (Senior fire-fighting facility operator) simulation test questions and answers
Another open source artifact, worth collecting and learning!
Motor control column summary
三本毕业,三年嵌入式软件的心路历程
Talking about the practice of software defect management
二叉排序树(BST) ~
ERROR: Could not open requirements file: [Errno 2] No such file or directory: ‘requirments.txt’
Redis持久化-AOF
Mba-day28 concept of number - exercise questions
unity 像素画导入模糊问题
Learn about spark project on nebulagraph
柠檬班自动化学习毕竟
漫谈软件缺陷管理的实践
对接微信支付(二)统一下单API
Properties of binary tree~
EM and REM
MBA-day28 数的概念-练习题









