Mysql Advanced-Storage Engine

MySQL architecture

Compared with other databases, MySQL is a bit different. Its architecture can be applied and work well in many different scenarios. Mainly reflected in the storage engine, the plug-in storage engine architecture separates query processing from other system tasks and data storage and extraction. This architecture allows the selection of appropriate storage engines based on business needs and actual needs.

 1).Connection layer The top layer is some clients and link services, including local sock communication and most client/service-based Communication similar to TCP/IP implemented by terminal tools. It mainly completes some connection processing, authorization authentication, and related security solutions. The concept of thread pool is introduced on this layer to provide threads for clients that securely access through authentication. SSL-based secure links can also be implemented on this layer. The server also verifies the operation permissions it has for each client that securely accesses it.

2). Service layer The second layer architecture mainly completes most of the core service functions, such as SQL interface, and completes cached queries. , SQL analysis and optimization, execution of some built-in functions. All cross-storage engine functions are also implemented in this layer, such as procedures, functions, etc. At this layer, the server will parse the query and create the corresponding internal parse tree, and complete the corresponding optimization such as determining the order of table queries, whether to use indexes, etc., and finally generate the corresponding execution operations. If it is a select statement, the server will also query the internal cache. If the cache space is large enough, this can greatly improve the performance of the system in an environment that solves a large number of read operations.

3). Engine layer Storage engine layer. The storage engine is really responsible for the storage and extraction of data in MySQL. The server uses API and Communicate with the storage engine. Different storage engines have different functions, so we can choose the appropriate storage engine according to our needs. Indexes in the database are implemented at the storage engine layer.

4). Storage layer The data storage layer mainly stores data (such as: redolog, undolog, data, index, binary log, Error logs, query logs, slow query logs, etc.) are stored on the file system and interact with the storage engine.

Storage engine introduction

I believe everyone is unfamiliar with the term storage engine, but everyone has heard of the term engine. An engine is an engine and is the core component of a machine. For example, for carrier-based aircraft, helicopters, and rockets, they all have their own engines, which are their most core components. When we choose an engine, we need to choose the appropriate storage engine in the appropriate scenario, just like on a helicopter, we cannot choose the engine of a carrier-based aircraft. The same goes for the storage engine. It is the core of the MySQL database. We also need to choose the appropriate storage engine in the appropriate scenario. That is, select an appropriate storage engine based on the needs of the business table. Note that the storage engine is based on tables. So the storage engine can also be called a table type. We can specify the selected storage engine when creating a table. If not specified, the default storage engine will be automatically selected.

Specify the storage engine when creating the table. If no storage engine is specified,mysql5.5 and later will automatically specify InnoDB as the default storage engine

CREATE TABLE table name(

Field 1 Field 1 type [COMMENT field 1 comment], ...

Field n Field n type [COMMENT Field n comment] )

ENGINE = INNODB [COMMENT table comment];

 Query the storage engines supported by the current database

show engines

 We can view the storage engine through the design table options

Through the sql statement, you can view the sql statement for creating the table, and you can also see the storage engine.

show create table table name

 

 Storage engine features

InnoDB 

introduce

InnoDB is a general-purpose storage engine that combines high reliability and high performance. After MySQL 5.5, InnoDB is the default MySQL storage engine.

Features

DML operations follow the ACID model and support transactions. The four major characteristics of transactions are atomicity, isolation, persistence, and consistency;

Row-level lock, improve concurrent access performance;

Supports foreign key FOREIGN KEY constraints to ensure data integrity and correctness;

document

xxx.ibd: xxx represents the table name. Each table in the innoDB engine will correspond to such a table space file, which stores the table structure (frm-early version, sdi-new version), data and indexes of the table.

We directly open the data folder of mysql, that is, the database file. We can see that there are many ibd files in it. Each ibd file corresponds to a table. For example: we have a table account, and there is such an account.ibd file. , and this ibd file not only stores the table structure and data, but also stores the index information corresponding to the table. The file is based on binary storage and cannot be opened directly based on Notepad. We can use an instruction ibd2sdi provided by mysql, through which the sdi information can be extracted from the ibd file, and the sdi data dictionary information contains this table 1 show variables like 'innodb_file_per_table'; table structure.

logical storage structure

 

Table space: The highest level of the logical structure of the InnoDB storage engine. The ibd file is actually a table space file. Can contain multiple Segment segments.

Segment: Table space is composed of various segments. Common segments include data segment, index segment, rollback segment, etc. The management of segments in InnoDB is done by the engine itself and does not require human control. A segment contains multiple areas.

Area: The area is the unit structure of the table space, and the size of each area is 1M. By default, the InnoDB storage engine page size is 16K, that is, there are 64 consecutive pages in one area.

Page: Page is the smallest unit that makes up an area. Page is also the smallest unit of disk management of InnoDB storage engine. The default size of each page is 16KB. In order to ensure page continuity, the InnoDB storage engine applies for 4-5 areas from the disk at a time.

rows: InnoDB storage engine isrow-oriented, which means that data is stored by rows, in each row, in addition to the fields specified when defining the table, there are also two hidden fields

 MyISAM

1)MyISAM is the early default storage engine of MySQL.

2) Features: Does not support transactions, does not support foreign keys, supports table locks, does not support row locks, and has fast access speed

3)Documents

xxx.sdi: Store table structure information

xxx.MYD: Store data

xxx.MYI: Existence index

 

Memory

1).Memory engine table data is stored in memory. Due to hardware problems or power outages, these tables can only be used astemporary tables or Cache usage.

2). Features Memory storage hash index (default)

3).File xxx.sdi: stores table structure information

 Differences and features

Guess you like

Origin blog.csdn.net/weixin_64133130/article/details/133979482