InnoDB引擎结构
内存结构
data buffer(缓存数据)
redo buffer(缓存redo)
insert buffer(缓存二级索引)
AHI(缓存hash index)
double write buffer(缓存物理更改页副本)
additional mem buffer pool
dictionary cache(缓存数据字典)
LRU(根据最近使用先后排序的page列表)
flush list(需要刷到磁盘的脏页列表)
free list(空闲page列表)
线程(默认15个)
master thread 1个
1S
刷redo
check point
merge insert buffer
dirty page clean
clean unused table cache
10S
刷redo
check point
merge insert buffer
dirty page clean
clean undo
io thread
read/write thread 默认各4个(读写数据)
log thread 默认1个(处理log)
insert thread 默认1个(处理insert buffer)
lock monitor thread 默认1个(监控锁)
error monitor thread 默认1个(监控错误)
page cleaner thread 默认1个(刷脏页)
purge thread 默认1个(清楚undo等)
物理存储
tablespace
系统表空间(数据字典、undo space、rollback segment、insert buffer、double write buffer等)
独立表空间(独立ibd文件,存储表数据)
临时表空间(存储SQL执行产生的临时表,ibtmp1)
undo表空间(5.6以后)
undo回滚段总是大于33个
truncate undo
通用表空间
- 类似oracle
segment
- 若干个extent及32个零散page组成
extent
- 64个page组成,1M
page
- 默认16KB
row
rowid:6B
trx_id:6B
roll_ptr:7B
最小值(虚拟)
最大值(虚拟)
行格式4种
MVCC
通过UNDO和回滚段来保证
mvcc可见性判断
insert undo&update undo
2PC
事务写入redo log buffer;
redo log写TRX PREPARE标记;
将log buffer刷新到redo log;
写binlog;
在redo log写入TRX COMMIT标记;
将写binlog成功的标记写入redo log
XID PREPARE->write redo log->write binlog->XID COMMIT->write sync binlog to redo log
double write
解决partial write问题
double write写入过程
InnoDB优化(重要参数)
innodb_buffer_pool_size
innodb_buffer_pool_instance
innodb_flush_log_at_trx_commit三个值
innodb_buffer_pool_load_at_startup(数据预热)
innodb_buffer_pool_dump_at_shutdown(数据预热)
innodb_data_file_path
sync_binlog
innodb_max_dirty_pages_pct
innodb_thread_concurrency
innodb_flush_method
innodb_log_file_size
innodb_log_files_in_group
innodb_log_buffer_size
innodb_fast_shutdown三个值
innodb_force_recovery六个值
innodb_io_capacity