8.5.3 Optimizing InnoDB Read-Only Transactions优化InnoDB只读事务

InnoDB can avoid the overhead associated with setting up the transaction ID (TRX_ID field) for transactions that are known to be read-only. InnoDB可以避免为已知为只读的事务设置事务ID(TRX_ID字段)的开销。A transaction ID is only needed for a transaction that might perform write operations or locking reads such as SELECT ... FOR UPDATE. 事务ID仅适用于可能执行写入操作或锁定读取的事务,如SELECT ... FOR UPDATEEliminating unnecessary transaction IDs reduces the size of internal data structures that are consulted each time a query or data change statement constructs a read view.消除不必要的事务ID可以减少每次查询或数据更改语句构造读取视图时所参考的内部数据结构的大小。

InnoDB detects read-only transactions when:InnoDB在以下情况下检测只读事务:

Thus, for a read-intensive application such as a report generator, you can tune a sequence of InnoDB queries by grouping them inside START TRANSACTION READ ONLY and COMMIT, or by turning on the autocommit setting before running the SELECT statements, or simply by avoiding any data change statements interspersed with the queries.因此,对于报表生成器等读密集型应用程序,可以通过在START TRANSACTION READ ONLYCOMMIT中对InnoDB查询进行分组,或者在运行SELECT语句之前打开autocommit设置,或者简单地避免查询中出现任何数据更改语句,来优化InnoDB查询序列。

For information about START TRANSACTION and autocommit, see Section 13.3.1, “START TRANSACTION, COMMIT, and ROLLBACK Statements”.有关START TRANSACTIONautocommit的信息,请参阅第13.3.1节,“START TRANSACTION、COMMIT和ROLLBACK语句”

Note注意

Transactions that qualify as auto-commit, non-locking, and read-only (AC-NL-RO) are kept out of certain internal InnoDB data structures and are therefore not listed in SHOW ENGINE INNODB STATUS output.符合自动提交、非锁定和只读(AC-NL-RO)条件的事务不在某些InnoDB内部数据结构中,因此不会列在SHOW ENGINE INNODB STATUS输出中。