InnoDB MVCC实现、Undo作用
2015-09-11 09:26
381 查看
Because
Internally,
InnoDBis a multi-versioned storage engine, it must keep information about old versions of rows in the tablespace. This information is stored in a data structure called a rollback segment (after an analogous data structure in Oracle).InnoDB是一个多版本的存储引擎,所以它必须在表空间中保存row的旧的版本。这些row的旧的版本被保存在称为rollback segment的数据结构中。
Internally,
InnoDBadds three fields to each row stored in the database. A 6-byte
DB_TRX_IDfield indicates the transaction identifier for the last transaction that inserted or updated the row. Also, a deletion is treated internally as an update where a special bit in the row is set to mark it as deleted. Each row also contains a 7-byte
DB_ROLL_PTRfield called the roll pointer. The roll pointer points to an undo log record written to the rollback segment. If the row was updated, the undo log record contains the information necessary to rebuild the content of the row before it was updated. A 6-byte
DB_ROW_IDfield contains a row ID that increases monotonically as new rows are inserted. If
InnoDBgenerates a clustered index automatically, the index contains row ID values. Otherwise, the
DB_ROW_IDcolumn does not appear in any index.为了支持MVCC, InnoDB内部实现的时候为每row增加了三个字段:1. 6 byte DB_TRX_ID: 代表最后插入或者更新该行的Transaction Identifier. 删除操作也被当做更新操作,只是在该行上加了一个特殊比特作为标志。2. 7 byte DB_ROLL_PTR:这个指向undo log的链表,如果该row被更新了,该row中原先内容将会被移到undo log中作为最前面的undo log的节点3. 6 byte DB_ROW_ID:当该row所在表新增加一行时, 新增row中的DB_ROW_ID会增加 。。。
InnoDBuses the information in the rollback segment to perform the undo operations needed in a transaction rollback. It also uses the information to build earlier versions of a row for a consistent read.undo log有两个作用:undo log链表的第一个节点可以用来rollback的时候恢复。undo log链表中其他节点用来在REPEATED_READ的情况下给哪些活的Transaction提供一致读的效果的。Undo logs in the rollback segment are divided into insert and update undo logs. Insert undo logs are needed only in transaction rollback and can be discarded as soon as the transaction commits. Update undo logs are used also in consistent reads, but they can be discarded only after there is no transaction present for which
InnoDBhas assigned a snapshot that in a consistent read could need the information in the update undo log to build an earlier version of a database row.Undo log分为insert和update两种。insert undo log当新insert row的时候产生的,这些undo log只有在Transaction rollback的时候用来删除前面insert的行,只要这个Transaction一commit或者discard,这个insert undo log就被丢弃掉了。 我们前面提的都是update undo log作用,就是前面说的“undo log”的两个作用,你想想,如果undo log链表中不是最前面的节点对应的Transaction已经不在了,这个节点还有存在的价值吗?因为没有tranaction去读它了。
相关文章推荐
- Mysql 索引概念及设计原则
- MySQL工具汇总
- mysql复制原理
- 数据库水平切分的实现原理解析
- Mysql数据表的优化
- MySQL HA方案
- 修改MySQL存储过程、函数、事件、触发器、视图的DEFINER
- 针对MySQL的Linux性能优化技巧
- Linux schedulers in tpcc like benchmark
- Impala:新一代开源大数据分析引擎
- 【第2周 项目3 - 体验复杂度(汉诺塔)】
- MySQL数据传递 Hadoop 非实时
- MySQL数据复制 Hadoop 实时复制
- 第二周 项目2-程序的多文件组织
- Android实现推送方式解决方案
- Eclipse安装SVN插件
- 12个免费学习编程的网站
- Java Applet基础讲解
- linux
- MySQL多版本并发控制分析