当前位置:网站首页>Analysis -- MySQL statement execution process & MySQL architecture

Analysis -- MySQL statement execution process & MySQL architecture

2022-07-07 05:00:00 Certainly tomorrow

Catalog

Statement execution procedure

What is half duplex

framework

Network connection layer

Service layer

Thread pool

sql Interface

Parser

Optimizer

cache

Manage service components and tool components

Storage engine layer

System file layer


Statement execution procedure

  1. Establishing a connection . Through the client / The server communication protocol establishes a connection , The mode of communication is Half duplex . The established connection has a thread monitoring status , We can use show processlist; To view the . The detailed field meaning can be determined by Baidu . 
  2.   The query cache . If the exact query is matched in the cache sql, Then directly return the data in the cache . have access to show variables like '%query_cache%'; Check whether query caching is enabled 、 Cache size 、 Limit etc. have access to show status like 'Qcache%'; See more detailed cache parameters , Available cache space , Cache block .
  3. Parser . analysis sql, Preprocessing . For example, check sql grammar 、 Check if the list exists 、 The analysis shows that , Table alias . Then generate the parse tree .
  4. Query optimizer . Generate the optimal execution plan according to the parse tree . It can be divided into compile time optimization and run-time optimization .
  5. Query execution engine . Responsible for the execution of sql, According to the storage engine , And corresponding api Interface or physical file interaction , Find the result and return it to the client . If the cache is enabled , Will sql Statements and results are cached . If too many results are returned , Then take incremental return to reduce pressure .

The general flow chart is as follows :

 

What is half duplex

Data is usually in two stations ( Point to point ) Transmission between , According to the direction of data flow, it can be divided into three transmission modes : Simplex 、 Half duplex , full duplex .

Simplex : Only send or receive . A one-way street similar to a road .

Half duplex : At the same time , Only send or accept . Similar to the previous interphone .

full duplex : Send and receive at any time . It's like making a phone call .

framework

  It is roughly divided into four layers : Network connection layer 、 Service layer 、 Storage engine layer 、 System file layer .

Network connection layer

mysql Support the mainstream programming technology of the server . The essence is still through tcp The protocol establishes the connection .

Service layer

Thread pool

MySQL Is a single process multithreaded application , When the user passes Connetor towards MySQL Server When requesting a connection , Through the thread pool (Connection Pool) Establish a user connection , This connection session will always exist .

sql Interface

Accept sql sentence

Parser

Conduct sql analysis , Generate parse tree

Optimizer

Optimize the parse tree . Analyze and measure the cost of which method , Minimum cost , The cost calculation depends on the various internal components of the index to evaluate , The result is an approximation , Also consider the current MySQL Statistics of internal resource access

cache

If you turn on caching , Will query sql And full result cache .

When inquiring , If cache hits , Then go to cache to find .

Manage service components and tool components

Backup & Recovery: Backup recovery tools 
Security: Safety tools 
Replication: Copy tool 
Cluster: The cluster service 
Administration Configuration: Manage configuration tools 
Migration: Migration tools 
Metadata: Responsible for managing the MySQL Metadata tools 

Storage engine layer

Pluggable storage engine . You can specify the storage engine when creating tables .

System file layer

Log files . Error log 、 General query log 、 Binary log 、 Slow query log

Data files .

The configuration file .mysql Configuration information file .

pid file .unix perhaps Linux Delegate your own processes id.

socket file . use unix socket Connect mysql.

The above is an explanation of the infrastructure process , You can expand on this basis , For example, how the storage engine modifies data …… There are too many extensible points , If you want to study deeply, you still need some time and energy .

 

原网站

版权声明
本文为[Certainly tomorrow]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130739593223.html

随机推荐