innodb: 两个事务在binlog文件中不会交叉

在innodb的binlog文件中,如果一个事务从第m行开始,在第n行结束;那么从m到n之间只会记录本事务的操作,不会记录其他事务的行为。

这是因为innodb中binary log entries总是以事务为单位整体写入文件的。

引用

Within an uncommitted transaction, all updates (UPDATE, DELETE, or INSERT) that change transactional tables such as BDB or InnoDB tables are cached until a COMMIT statement is received by the server. At that point, mysqld writes the entire transaction to the binary log before the COMMIT is executed.

推论:

1. 只有事务完成了,相关记录才会进入binlog文件

2. 一个写事务不应该太长,否则当它被整体写入binlog文件时,会长时间占用binlog,导致其他事务在这段时间内无法写入binlog,因而无法提交,最终影响并发性能。

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.