innodb中应该尽量把多条语句放在单个事务中执行

默认情况下,一个写操作就是一次事务

如果一次业务操作包含三次DB写操作,三个写操作就是三个事务,三个事务导致三次log flush(磁盘读写,代价较高):

引用
InnoDB must flush the log to disk at each transaction commit if that transaction made modifications to the database.

所以应该把这三次DB写操作合在一个事务里,这样只需要做一次flush disk。

Leave a Comment

Your email address will not be published.

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