How to execute a SQL statement in mysql?
Article content from: Geek time – Lin Xiaobin teacher -MySQL combat 45 talk learning collate
Before you understand how a query is executed, you need to understand the basic architecture of MySQL, as shown in the following figure:
It can be seen that MySQL is mainly divided into Server layer and storage engine
The SQL statement is executed as follows:
(1) Establish the connection through the connector first. In this case, the user name and password are required for authentication
(2) After the connection is successful, it will query the cache. If the cache is hit, it will return directly. Otherwise, it needs to continue to the analyzer
(3) the analyzer needs to do lexical analysis, identify keywords such as SELECT, and judge whether your SQL syntax is correct
(4) After being parsed, the optimizer will optimize the query, such as which index to use
(5) After the execution of the optimizer, it is necessary to execute the executor. During the execution process, it is also necessary to determine whether the current user has the permission to query. If so, it is necessary to call the interface of the storage engine to query the data return