当前位置:网站首页>L01_ How is an SQL query executed?
L01_ How is an SQL query executed?
2022-06-24 09:15:00 【jackaroo2020】
Reading guide
This article mainly adopts a SQL Query statement , Let's have a preliminary understanding of MYSQL Basic framework .

1、MYSQL Logical architecture
mysql> select * from T where ID=10;
Here is MySQL Basic architecture diagram , You can see clearly from it SQL Statements in MySQL The execution process in each function module of .

2、MySQL The framework has several components , What is the role of each ?
The connector
Responsible for and mysql The client establishes a connection , Get user rights , Maintaining and managing connections . The connection command is usually written like this :
mysql>mysql -h$ip -P$port -u$user -p
When the connection is complete , If you don't follow up , This connection is idle , You can show processlist See it in the command . As shown in the figure , Among them Command The column is shown as “Sleep” This line , It means that there is an idle connection in the system . 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 . The order is :
mysql>show processlist;
mysql>show variables like 'wait_timeout';

The query cache
Query requests to access the cache first (key Is the statement of the query ,value Is the result of a query ). Hit direct return . Caching is not recommended , Updates will clear the cache ( Turn off caching : Parameters query_cache_type Set to DEMAND). 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;
It should be noted that ,MySQL 8.0 Version of the query cache directly removed the entire block , in other words 8.0 It's starting to disappear completely .
analyzer
analysis sql Statement for errors , Lexical analysis and grammatical analysis .
Optimizer
Decide which index to use , More than a table (join) When , Determine the join order of the tables .
actuator
Execute statement , First judge whether the user has query permission , Storage engine using table definitions .
mysql> select * from T where ID=10;
For example, the table in our example T in ,ID Field has no index , So the execution process of the actuator is like this :
(1) call InnoDB The engine interface takes the first row of this table , Judge ID Value is 10, If not, skip , If it is, the row will exist in the result set ;
(2) Call the engine interface “ The next line ”, Repeat the same logic of judgment , Until you get to the last row of the table .
(3) The executor returns the record set composed of all the rows that meet the conditions in the traversal process to the client as a result set .
3、Server What are the roles of the storage engine layer and the storage engine layer ?
In general ,MySQL Can be divided into Server Layer and storage engine layer .
Server layer Including 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. .
Storage engine layer Responsible for data storage and extraction . Its architecture pattern is plug-in , Support InnoDB、MyISAM、Memory Wait for multiple storage engines . Now the most commonly used storage engine is InnoDB, It is from MySQL 5.5.5 Version began to be the default storage engine .
The notes are mainly from teacher linxiaobin <<MYSQL actual combat 45 speak >> Course , It is mainly used for personal learning notes , If this article infringes upon your rights , Please contact me , I will delete the infringing articles as soon as possible !
边栏推荐
- [use picgo+ Tencent cloud object to store cos as a map bed]
- 【输入法】迄今为止,居然有这么多汉字输入法!
- 学习太极创客 — ESP8226 (十三)OTA
- Support vector machine (SVC, nusvc, linearsvc)
- MySQL data (Linux Environment) scheduled backup
- Essay - Reflection
- Cmake命令之target_compile_options
- P6117-[JOI 2019 Final]コイン集め【贪心】
- Common emoticons
- 关于 GIN 的路由树
猜你喜欢

Redis implements a globally unique ID

Mba-day25 best value problem - application problem

Ordinary people have no education background. Can they earn more than 10000 yuan a month by Self-taught programming?

听说你还在花钱从网上买 PPT 模板?

Webrtc series - network transmission 5: select the optimal connection switching

零基础自学SQL课程 | 子查询

Ebanb B1 Bracelet brush firmware abnormal interrupt handling

Every (), map (), forearch () methods. There are objects in the array

Squid代理服务器应用

零基础自学SQL课程 | 相关子查询
随机推荐
【ES6闯关】Promise堪比原生的自定义封装(万字)
Scheme of alcohol concentration tester based on single chip microcomputer
浮点数表示法(总结自CS61C和CMU CSAPP)
Depens:*** but it is not going to be installed
[noi simulation] pendulum (linear algebra, Du Jiao sieve)
学习太极创客 — ESP8226 (十三)OTA
110. balanced binary tree recursive method
The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different
Sword finger offer 55 - I. depth DFS method of binary tree
4275. Dijkstra sequence
从618看京东即时零售的野心
Data middle office: a collection of middle office construction architectures of large domestic factories
[Niuke] length of the last word of HJ1 string
每周推薦短視頻:談論“元宇宙”要有嚴肅認真的態度
2021-05-20computed and watch applications and differences
What do you mean by waiting for insurance records? Where should I go for filing?
Data middle office: overview of data governance
216. combined summation III enumeration method
Squid代理服务器应用
Webrtc series - network transmission 5: select the optimal connection switching