当前位置:网站首页>MySQL InnoDB Architecture Principle
MySQL InnoDB Architecture Principle
2022-07-05 21:09:00 【A little dog】
MySQL InnoDB Framework principle

1. Architecture analysis
InnoDB It is mainly divided into : Structure in memory and Structure on disk
The memory structure is mainly : Buffer Pool (change Buffer 、adaptive hash index) log buffer
The disk structure is divided into : Tablespaces and redo logs
Table space :InnoDB The data dictionary 、 Double write buffer 、 Modify cache 、Undo journal .
Redo log : What's stored is Log buffer Data flushed to disk .
(.idb、.frm、undo.log、( Double write buffer (doublewrite buffer), Failure recovery mechanism (crash recovery))、 Locking mechanism 、Redo.log、)
2. InnoDB The structure in memory
Buffer Pool、(Change Buuffer、Adaptive Hash Index Occupied memory belongs to Buffer Pool)、Log Buffer
2.1 Buffer Pool
Mysql The server 80% Of memory will be allocated to Buffer Pool.
InnoDB The minimum unit of data management in is page , Default per page 16KB.
Through a page linked list , Less pages accessed will pass through the cache pool LRU The algorithm is eliminated .
Realization LRU Linked list
But different from the normal linked list , The buffer pool chain table is divided into 2 part ,New sublist( Default occupation 5/8 The cache pool ) and Old sublist( Default occupation 3/8) The cache pool ( adopt innodb_old_blocks_pct modify , The default value is 37)
The newly read page will be added Old sublist, And if the Old sublist If you visit the page in times , Will move to New sublist The head of .
2.1.1 The page list is not full , Add a new page

2.1.2 Old sublist Page in Be visited here

2.1.3 The page list is full , Add a new page , Trigger LRU Algorithm

2.2 Change Buffer
To reduce nonclustered indexes ( Secondary indexes ), Each modification is written directly to disk , There will be a lot of frequent IO.
Change buffer take Not unique The operation of the auxiliary index page is cached . If the secondary index page is already in the cache , It can be modified directly ( There is no need to IO), If not , Save the changes to Change Buffer, So as to merge and write disk files regularly, such as .idb.

2.3 Adaptive Hash Index
Although database record storage is not used hash surface , However, adaptive hash index is used for page lookup in memory (AHI) The general time complexity is O(1), As a way to reduce query data ( Indexes ) Page method .
2.4 LogBuffer
Log Buffer yes Redo log (Redo log) Buffer in memory , The default is 16M
2.4.1 Log first strategy (Redo log The role of )
InnoDB The log first strategy is used , Before persisting data files , Ensure that transactions are recorded as Redo log Written to disk .
Problem description : After logging to the database , The corresponding transaction can be returned to the user , Indicates that the transaction is complete . actually , The data may only be modified in memory , Did not brush to disk . If the program is abnormal or fails , The data in memory will disappear .
solve the problem : InnoDB At this point through Redo log To ensure data consistency . Obviously, it is not realistic to record all redo logs . The checkpoint mechanism is introduced , Ensure that the log has been written to disk , The next reply starts from the checkpoint .
2.4.2 Recover data from downtime ( from Redo Log and Log Buffer)
When data is modified , Will write memory space first , And then write Log Buffer, Will be log buffer The log of changes recorded in is written to the physical disk redo log In file .
However, the downtime data is written into memory , But it is not stored in the physical storage structure . At this time, the checkpoint mechanism will be used checkPoint, take redo log The data in the file is loaded into redo log buffer In the memory . Let's talk about the latest data writing mysql Disk data file , To update the data .
3. InnoDB Physical disk structure
3.1 Table space
3.1.1 InnoDB The data dictionary
After creating a database and a table , You can see test Database directory .
db.opt file : Saved data test Default character set
t.frm file : Save the data dictionary information of the table
t.idb file : Table data and index ( initialization 96K, The default page is 16K)
3.1.2 Undo journal ( To achieve atomicity Transaction commit rollback , Realization MVCC)
MySQL Of MVCC( Multi version concurrency control ) rely on Undo Log Realization .Mysql Table space file of t.ibd The latest value of the stored record . Each record has a rollback pointer ( See the picture above Roll Ptr), Point to the last entry in the record Undo Record , And each one Undo The record will point to the previous one Undo Record .

Undo Log During the execution of a transaction , Transactions are persisted only after they are committed , If the transaction is rolled back Undo Log It will also delete .
3.1.3 Double write cache (Double-Write Buffer)
When InnoDB After the record is updated , Because the log first strategy will go first Log Buffer Write data in memory , And then write to disk Redo log in .
Then, before writing to the physical table disk, it will enter the double write cache , At this time, if the writing process fails ( For example, the machine power down or the operating system crashes ).
3.1.3.1 Error writing to double write cache

3.1.3.2 Error writing to physical table file

4. InnoDB ACID Model
4.1 Atomicity
Mainly through the transaction mechanism
COMMITHE ROLLBACK sentence ( adopt Undo log Realization )
4.2 Consistency
Consistency assurance
InnoDB Double write buffer for (double write buffer Consistency assurance of disk storage )
InnoDB The failure recovery mechanism of (Redo log Consistency guarantee of data submission ,Undo log Consistency guarantee of transaction submission ,bin log Ensure the consistency and persistence of master-slave data )
4.3 Isolation
Isolation,
The isolation level of the transaction
InnoDB Locking mechanism
4.4 Durability
Durability guarantee
redo log Cache to disk
double write buffer Double write cache guarantee Data to disk
bin log Ensure the consistency and persistence of master-slave data
Please correct me if there is any mistake
边栏推荐
- R language [data management]
- hdu2377Bus Pass(构建更复杂的图+spfa)
- php中explode函数存在的陷阱
- Selenium's method of getting attribute values in DOM
- Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
- XML modeling
- 概率论机器学习的先验知识(上)
- 示波器探头对信号源阻抗的影响
- Talk about my fate with some programming languages
- 股票开户选择哪家证券公司比较好哪家平台更安全
猜你喜欢

示波器探头对信号源阻抗的影响

2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once

leetcode:1139. 最大的以 1 为边界的正方形

Influence of oscilloscope probe on measurement bandwidth

【案例】定位的运用-淘宝轮播图

Clion configures Visual Studio (MSVC) and JOM multi-core compilation

PVC 塑料片BS 476-6 火焰传播性能测定

PHP deserialization +md5 collision

Écrire une interface basée sur flask

第05章_存储引擎
随机推荐
Test of incombustibility of cement adhesives BS 476-4
When a user logs in, there is often a real-time drop-down box. For example, entering an email will @qq com,@163. com,@sohu. com
Pytorch实战——MNIST数据集手写数字识别
WPF gets the control in the datagridtemplatecolumn of the specified row and column in the DataGrid
POJ 3414 pots (bfs+ clues)
终端安全能力验证环境搭建和渗透测试记录
AITM 2-0003 水平燃烧试验
Learning robots have no way to start? Let me show you the current hot research directions of robots
PostGIS installation geographic information extension
Arcgis\qgis no plug-in loading (no offset) mapbox HD image map
Sophomore personal development summary
LeetCode: Distinct Subsequences [115]
Phpstudy Xiaopi's MySQL Click to start and quickly flash back. It has been solved
PHP deserialization +md5 collision
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
CareerCup它1.8 串移包括问题
水泥胶黏剂BS 476-4 不燃性测试
Web Service简单入门示例
Clion-MinGW编译后的exe文件添加ico图标
shell编程100例