MySQL Architecture

Understanding MySql must keep in mind its architecture diagram, Mysql is composed of SQL interface, parser, optimizer, cache, storage engine.

a1

1 Connectors refer to the interaction with SQL in different languages

 

2 Management Services & Utilities: System management and control tools

 

3 Connection Pool: Connection pool.

Manage buffered user connections, thread processing, etc. that require caching

 

4 SQL Interface: SQL interface.

Accept the user's SQL command, and return the result that the user needs to query. For example, select from is to call SQL Interface

 

5 Parser: Parser.

SQL commands are validated and parsed by the parser when passed to the parser. The parser is implemented by Lex and YACC and is a long script.

The main function:

a. Decompose the SQL statement into a data structure, and pass this structure to the subsequent steps. The subsequent transmission and processing of SQL statements are based on this structure

b. If an error is encountered in the decomposition, it means that the sql statement is unreasonable

 

6 Optimizer: Query optimizer.

The SQL statement will use the query optimizer to optimize the query before querying. He uses the "select-project-join" strategy to query.

It can be understood with an example: select uid,name from user where gender = 1;

This select query first selects according to the where statement, instead of querying all the tables first and then performing gender filtering

This select query first performs attribute projection based on uid and name, instead of filtering all attributes after taking them out

Join these two query conditions to generate the final query result

 

7 Cache and Buffer: Query cache.

If the query cache has a hit query result, the query statement can directly go to the query cache to fetch data.

This caching mechanism consists of a series of small caches. Such as table cache, record cache, key cache, permission cache, etc.

 

8 Engine: storage engine.

The storage engine is a specific subsystem in MySql that deals with files. It is also one of the most distinctive places of Mysql.

Mysql's storage engine is plug-in. It customizes a file access mechanism based on an abstract interface of the file access layer provided by MySql AB (this access mechanism is called a storage engine)

Now there are many kinds of storage engines, the advantages of each storage engine are different, the most commonly used MyISAM, InnoDB, BDB

By default, MySql uses the MyISAM engine, which has fast query speed, better index optimization and data compression technology. But it doesn't support transactions.

InnoDB supports transactions and provides row-level locking, which is widely used.
Mysql also supports its own custom storage engine, and even different tables in a library use different storage engines, which are all allowed.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326557341&siteId=291194637