当前位置:网站首页>MySQL series: overview of the overall architecture

MySQL series: overview of the overall architecture

2022-06-23 15:24:00 yue_ xin_ tech

Preface

Use mysql For many years , But I haven't studied it deeply , Prepare to learn about mysql Relevant knowledge points of . See how this artifact in the programming world works .

mysql Architecture mode of

mysql It's using C/S framework , That is what we usually call the client - Server model . As we usually use workbench、nacivat Is the client , Of course , And command line tools .

They will be based on the specified ip、prot Connect to the server , Through a certain agreement SQL Implementation . These protocols include the most widely used TCP agreement , Sockets suitable for local communication are also included 、 Shared memory 、 Named pipeline and other protocols .

mysql There is a special thread on the server side to manage each connection , And the network IO The model is select/poll, Is not epoll.

Mainly because select/poll Good portability , Many systems support , and mysql The bottleneck is not the network connection , For fewer connections , And the connection is very active mysql for ,select/poll It's a better choice .
( notes :select、poll、epoll yes IO Multiplexing model , Can monitor multiple at the same time I/O The state of the event , Less occupied resources , High performance .)

mysql Of 2 Stages

When the server receives the client's request to connect , Will enter Connection phase and The command phase .

The connection phase mainly performs the following tasks :

  • Determine the current version of the client and server ;
  • Determine if... Is required SSL signal communication ;
  • The server authenticates the identity of the client ;

When the connection phase above ok after , Will enter the command phase , What we usually see SQL The operation is performed at this stage , Such as

  • COM_QUERY: Used to send an immediate message to the server SQL Inquire about
  • COM_CREATE_DB: Commands for creating databases

 Overview of the overall architecture

mysql Of 3 Layer architecture

above 2 The second stage is from mysql Divided by the connection life cycle , In fact, from the logical structure ,mysql Can be divided into 3 layer :

  • adjoining course : Mainly responsible for connection pool 、 Communication protocol 、 Certification and authorization ;
  • SQL layer : This floor is mysql Brain , The optimal solution of data operation is obtained through a series of components .
  • Storage layer : Responsible for the storage of data 、 retrieval .
    mysql Of 3 Layer architecture

SQL layer

The connection layer has been outlined earlier , Let's see SQL layer , After receiving the command ,mysql Not foolishly go straight to get the data , It will analyze the current sql Various execution efficiencies of statements , And then get an optimal execution plan .

stay SQL The layer is mainly divided into the following functions :

  • Query cache: Cache query result set , And the next query hit the cache , Then the following execution will be skipped , Returns the cached result directly .
  • Parser: Parser , according to SQL Statement to build an internally used parse tree , For easy access to SQL Information , Such as SQL Semantic and grammatical information .
  • Optimizer: Optimizer , By analyzing the operation cost of the storage engine and the statistics of the table , Output efficient execution plan . For example, in query analysis , Which of table scan or index scan is more efficient , Then choose which .

In addition to the above functions ,mysql Built in functions for 、 stored procedure 、 Triggers and views are also implemented in this layer .

Storage layer

As mentioned earlier, the optimizer will output the execution plan , The specific implementation is in the storage layer . The storage tier is mysql The design here is Can be inserted Plug in for , That is, as long as the standardized interface is met (API), Then you can implement your own storage engine .

The storage engine is used to store 、 To retrieve data , Different storage engines have different characteristics , image InnoDB Support transactions 、 Foreign keys , and MyISAM I don't support .

Generally, we don't need to care SQL Which storage engines are involved in the statement , As mentioned earlier , It has been abstracted through standardized interfaces . However, the optimizer layer may need to make different choices according to different storage engines .

summary

mysql The overall architecture of is described above , actually ,mysql There are still many important knowledge points to master , image Lock mechanism ,MVCC version control , Query optimization etc. , I got it , That's right mysql Have a general understanding , We will continue to study later , Share it with you !


Interested friends can search the official account 「 Read new technology 」, Pay attention to more push articles .
If you can , Just like it by the way 、 Leave a message 、 Under the share , Thank you for your support !
Read new technology , Read more new knowledge .
 Read new technology

原网站

版权声明
本文为[yue_ xin_ tech]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231438380818.html