How is an SQL query executed?

What are the components of MySQL?

1. Connector: manage connections and verify permissions. 2. Analyzer: lexical analysis, grammar analysis. 3. Optimizer: execute plan generation and index selection. 4. Actuator: Operates the storage engine and returns a result. 5. Storage engine: Stores data and provides read and write interfaces.

The connector

The first step is to connect to the MySQL database, in this case to the connector. Connectors establish connections to customers, obtain permissions, and maintain and manage connections.

mysql -h $ip -u root -p
Copy the code

The query cache

Once the connection is established, we can use the SELECT statement, which takes us to the second step of the execution logic: the query cache. MySQL will now query the cache to see if this statement has been executed before and return it if it has. This module has been removed since MySQL 8.0.

analyzer

If there is no query cache, this is where MySQL starts to analyze what we are doing, and we need to analyze the SQL statements we are writing. The parser first does a lexical analysis, identifying the string and what it represents. Then we parse the SQL statement to see if it has any errors, and if it does, we throw an error.

The optimizer

After going through the parser, MySQL knows what you’re doing, and the optimizer decides which scheme to use based on table structure and statement purpose.

actuator

MySQL knows what to do from the parser, and it knows how to do it most efficiently from the optimizer. You can then enter the executor and actually execute the SQL statement.

Select * from users where name = 'operator'Copy the code

Assume that the name field in the Users table is not indexed, then the executor calls InnoDB engine interface to fetch the first line and check whether name is equal to operator. If not, skip it and put it in the result set. The engine interface is then called to fetch the next row, and the same logical judgment is repeated until the last row of the table is fetched. Finally, the result set is returned to the client.

※ Some articles from the network, if any infringement, please contact to delete; More articles and materials | click behind the text to the left left left 100 gpython self-study data package Ali cloud K8s practical manual guide] [ali cloud CDN row pit CDN ECS Hadoop large data of actual combat operations guide the conversation practice manual manual Knative cloud native application development guide OSS Operation and maintenance actual combat manual cloud native architecture white paper Zabbix enterprise distributed monitoring system source document 10G large factory interview questions