background
MySQL version: MySQL 8.0 0
Reference: MySQL official website
1、 InnoDB official architecture

2、 Brief description
InnoDb
The architecture is divided intoMemory structure
andDisk structure
1. Memory structure
1.1 buffer pool
buffer pool
Is an area in main memory,InnoDB
Cache here when accessing table and index data.buffer pool
Allows direct access to commonly used data from memory, increasing processing speed. On a dedicated server, up to80%
Physical memory is usually allocated to the buffer pool.
For more information about buffer pool, please refer to-MySQL – InnoDB – understand buffer pool
1.2 change buffer
change buffer
It’s a kind ofSpecial data structure
, whenSecondary index page
be not inbuffer poole
When in, it caches changes toSecondary index page
。 Buffered changes (possibly byINSERT
、UPDATE
orDELETE
operation(DML)
Cause) merge later when pages are loaded into the buffer pool by other read operations.
For more information about buffer pool, please refer to-MySQL – InnoDB – understand change buffer
1.3 adaptive hash index
adaptive hash index
Make InnoDB
Can be inAppropriate workload combination
andBuffer pool enough memory
It is more like an in memory database without sacrificing transaction characteristics or reliability. Adaptive hash index passinnodb_adaptive_hash_index
Variable is enabled or passed when the server starts——skip-innodb- adaptive_hash -index
close.
Detailed introduction address: to be continued
1.4 log buffer
log buffer
An area is an area of memory that stores data to be written to a disk log file.log buffer
Size byinnodb_log_buffer_size
Variable definition. The default size is16MB
。 Regularlylog buffer
Refresh the contents of to disk. largelog buffer
Enables large transactions to run without having to commit the transaction before it is committedredo log
Write data to disk. Therefore, if you have transactions that update, insert, or delete many rows, addlog buffer
The size of can save disk I / O.
Detailed introduction address: to be continued
2. Disk structure
2.1 tables
Detailed introduction address: to be continued
2.2 indexes
Detailed introduction address: to be continued
2.3 tablespace
Tablespace
ContainsSYSTEM tablespace
、Independent table space
、Universal table space
、Temporary tablespace
as well asUndo tablespace
2.3.1 SYSTEM tablespace:
a、SYSTEM tablespace
Mainlychange buffer
Storage area of;
b. If the table is inSYSTEM tablespace
Created in instead of inIndependent table space
perhapsCreate in a common tablespace
Yes, thenSYSTEM tablespace
The created is also stored inTables and indexes
data
c. Inmysql8.0
Before version,mysql
ofdata dictionary
Also stored inSYSTEM tablespace
Of course, but8.0
After the version,mysql
Merged oneTransactional data dictionary
, metadata stored indata dictionary
Medium;
d. InMySQL 8.0.20
Before,double write buffer
The storage area is located in InnoDBSYSTEM tablespace
Yes. fromMySQL 8.0.20
Start,double write buffer
Storage area atdouble write
In the document;
Detailed introduction address: to be continued
2.3.2 independent tablespaces
Independent table space
InnoDB is included inTable data and index information
, stored inSingle independent tablespace file
in
Detailed introduction address: to be continued
2.3.3 common tablespaces
Universal table space
Refers to the use ofCREATE tablespace
Syntax createdShared InnoDB tablespace
Detailed introduction address: to be continued
2.3.4 temporary tablespaces
Used in InnoDBTemporary tablespace
Divided intoSession temporary tablespace
andGlobal temporary tablespace
Detailed introduction address: to be continued
2.3.5 undo tablespaces
undo tablespace
containUndo log
,Undo log
Is a collection of records that contain information about how to undo the latest changes made by a transaction to a clustered index record.
Detailed introduction address: to be continued
2.4 double write buffer
double write buffer
Is a storage area in which InnoDB writes from before writing pages to an appropriate location in the InnoDB data filebuffer pool
Page refreshed in. If an operating system, storage subsystem, or unexpected error occurs during page writingMysqld process exit
, InnoDB can recover from a crash during recoverydouble write buffer
Found a good copy of the page in.
Although the data is written twice, thedouble write buffer
It does not require twice the I / O overhead or twice the I / O operations. Data is written to the doublewrite buffer in a large sequential block through a single fsync () call to the operating system (unlessinnodb_flush_method
Set toO_DIRECT_NO_FSYNC
)。
stayMySQL 8.0.20
Before,double write buffer
The storage area is located in InnoDBSYSTEM tablespace
Yes. fromMySQL 8.0.20
Start,double write buffer
Storage area atdouble write
File.
Detailed introduction address: to be continued
2.5 redo log
redo log
Is a disk based data structure used to correct data written by incomplete transactions during crash recovery. During normal operation,redo log
Encode table data change requests generated by SQL statements or low-level API calls. Modifications that did not complete the data file update before the unexpected shutdown will be automatically replayed during initialization and before accepting the connection. aboutredo log
Role in crash recovery, seeSection 15.18.2 "InnoDB recovery"
。
By default,redo log
Physically, it consists of twoib_logfile0
andib_logfile1
File representation of. MySQL writes in a circular mannerredo log
File.redo log
The data in the are encoded according to the affected records; These data are collectively referred to as redo. Data passredo log
The channel is represented by increasing LSN values.
Detailed introduction address: to be continued
2.6 undo logs
undo log
Is associated with a single read-write transactionundo log
A collection of records.Undo record
Contains information about how to undo the latest changes made by a transaction to a clustered index record.
Detailed introduction address: to be continued
Unfinished to be continued