MYSQL Advanced MYSQL Logical Architecture

Column catalog please click

Introduction

Let's look at this picture first,
insert image description here
it can be simplified as follows

insert image description here

query process

  • First of all, MysQL is a typical C/S architecture, that is, Client/Serverthe architecture used by server-side programs mysqld.
  • Regardless of the communication method used by the client process and the server process, the final effect is: the client process sends a piece of text (SQL statement) to the server process, and the server process sends a piece of text to the client process after processing (processing result) .
  • Specifically, we can see the following figure

insert image description here

  1. We will find that the whole process can be divided into three major parts
    1. connection management
    2. Analysis and optimization
    3. storage engine

There is no query cache step in mysql8.0. The files on the physical disk in the file system are first loaded into the storage engine.

  1. Therefore, the above figure can be roughly divided into the following three layers.
    insert image description here
  2. Let's go over these modules in detail

connection management

  • Each successful client connection will have a thread in the server process, and the server will cache the thread, which can only run in a certain CPU in turn, so there is no need to create and destroy threads

  • Accessing MysQL through sDK essentially interacts with MysQL through the MysQL protocol on a TCP connection.

Connectors

  1. Connectors refer to the interaction with MYSQL in different languages.
  2. Before the system (client) accesses the MySQL server, the first thing it does is to establish a TCP connection. After the three-way handshake establishes the connection successfully, the MysQL server performs identity authentication and permission acquisition on the account password transmitted by TCP.
  3. After the TCP connection receives the request, it must be assigned to a thread to interact with the client. So there will be a thread pool to go through the following processes. Each connection obtains threads from the thread pool, eliminating the overhead of creating and destroying threads, as shown in the figure belowinsert image description here

Parsing and optimizing queries

This belongs to the second layer of service layer

  • At this layer, the server parses the query and creates a corresponding internal parse tree, which is optimized accordingly
    • For example, determine the order of query tables, whether to
      use indexes, etc., and finally generate corresponding execution operations.
    • If it is a SELECT statement, the server will also query the internal cache.

SQL Interface

SQL interface

  1. It is used to receive the user's SQL command and return the result that the user needs to query. The query statement is to callSQL Interface
  2. It supports multiple SQL languages ​​such as DML, DDL, stored procedures, views, triggers, and custom functions.

Parser

parser

  1. In the parser, the SQL statement is parsed and semantically analyzed , the SQL statement is decomposed into a data structure, and this structure is passed to the subsequent steps. The subsequent transmission and processing of the SQL statement is based on this structure.
  2. If an error is encountered in the decomposition, it means that the SQL statement is unreasonable.
  3. When the SQL command is passed to the parser, it will be verified and parsed by the parser, and a syntax tree will be created for it, and the query syntax tree will be enriched according to the data dictionary, and it will be verified whether the client has the authority to execute the query.
  4. After the syntax tree is created, MYSQL will also optimize the syntax of the SQL query and rewrite the query.

Optimizer

query optimizer

  1. After the SQL syntax is parsed and before the query, the query optimizer will be used to determine the execution path of the SQL statement and generate an execution plan .
  2. This execution plan indicates which indexes should be used for query (full table index or index retrieval), what is the order of links between tables, and finally, the steps in the execution plan will call the method provided by the storage engine to actually execute the query, and will Query results are returned to the user

query strategy

He is using 选取-投影-链接the strategy of the query

SELECT id,name FROM student WHERE gender = '男';
  1. He will first selectWHERE the sentence ,
  2. Then perform attribute projection based on id and name
  3. Link the above two query conditions to generate the final query result

Caches & Buffers

Query Cache Component

  1. MySQL maintains some Cache and Buffer internally
  2. This caching mechanism is composed of a series of small caches. Such as table cache, record cache, key cache, permission cache, etc., and can be shared between different clients
  3. After MySQL5.7.20, it is recommended to use query cache and delete it in MySQL8.0

storage

this belongs to the third layer

  1. The storage engine layer is really responsible for the storage and extraction of data in MYSql, and performs operations on the dungeon data maintained at the physical server level.
  • Storage Engine Detailed Click

storage layer

  1. All the data, the content of each row of the database, the table, and the index are stored on the file system in the form of files, and complete the interaction with the storage engine.
  2. Some storage engines do not support direct management of raw devices using file systems, such as InnoDB.
  3. The file system can use local disks, or various storage systems such as DAS, NAS, and SAN

reference

Guess you like

Origin blog.csdn.net/youhebuke225/article/details/129966122