A SELECT query in the database have experienced the implementation of what

Are dealing every day with mysql, you know execute a simple select statement, we have gone through what process?

 

First, mysql is mainly composed of two parts of the server and storage layers. server layer mainly comprises a connector, query cache analyzer, optimizer, executor. Storage layer is mainly used to store and query data, there are commonly used storage engine InnoDB, MyISAM, MySQL 5.5.5 version uses InnoDB as the default storage engine after.

 

Connector

The connector is mainly responsible for establishing a connection mysql client and server, the connection is successful, it will obtain the rights of the current user's connection. Here acquired rights are valid for the entire connection, once the connection is successful, if you use an administrator account to change the permissions of the user currently has permission to connect remains unchanged, only to wait until the next update will reconnect permission.

 

Query Cache

Once connected, it began to formally execute select statement, but before executing the query, mysql will go to the next cache content of the article there is no statement, if there is a cache read directly from the cache and returned the data back no longer perform the steps to end the query.

 

If not then continue to the next cache execution, and save the results and statements in the cache.

 

Note: After mysql8 has no query caching this feature, because the cache is very easy to be emptied out, the hit rate is relatively low. As long as there is an update on the table, all the caches on the table will be empty, so you just cached content, not enough time to use it is another update emptied.

 

Analyzer

Since not found the cache, you need to start the implementation of the sql statement, sql statement certainly need to be resolved prior to execution. Mainly analyzer sql statement syntax and semantic analysis, check whether the word is misspelled, as well as table or field inspection to be queried exists.

 

If the parser will return an error is detected similar "You have an error in your sql" this error message, and the end of the query operation.

 

The optimizer
then through the analyzer, mysql even understand you want to perform the operation. Usually for the same sql statement, there may be a variety of internal mysql implementation of the program, such as when there are multiple indexes, which index the choice, when more than one table associated with the query, how to confirm the connection order of the table.

 

The results of these programs are the same, but the efficiency is not the same, so before executing mysql need to try to find an optimal solution to this is to optimize the device's main work. Mysql but there will be choosing the wrong program when temporarily go into detail here, to stay behind to explain why.

 

Actuator

After the optimizer to select a plan, the actuator on the implementation of sql statement in accordance with the selected program. Earlier we have said before, will read the permissions of the current user in the connector, the connector only get permission only, and no authority to judge and check.

 

Therefore, in the actuator, before executing the statement will judge authority, if there is no corresponding rights and prompt will be returned. No permission.

 

Here you may ask, why not the connector directly determine permissions it, here I think it may be because you want to query mysql table is not necessarily limited to those in Table sql statement literally, sometimes it may take analyzer and after the optimizer to determine how to execute in the end, so check the permissions on the actuator it is justified.

 

Note If, ​​after the cache was found in the previous query cache, the authority will do check before returning the results.

 

After verification by the authority, it will continue to open the table, call interface provided by the storage engine to query and returns the result set data.

 Here, a query is executed sql statement ended. Speak rough, just a general process, where each step to achieve the underlying mysql are very complex and require in-depth understanding gradually.

Guess you like

Origin www.cnblogs.com/gjc592/p/11228331.html