mysql readonly事务_InnoDB Read-Only Transactions_只读事务

InnoDB Read-Only Transactions_只读事务

‍As of(自从) MySQL 5.6.4, InnoDB can avoid the overhead associated with setting up the transaction ID (TRX_ID field) for transactions that are known to be read-only.A transaction ID is only needed for a transaction that might perform write operations or locking reads such as SELECT ... FOR UPDATE.Eliminating(排除) unnecessary transaction IDs(不必要的transaction id) reduces(降低) the size of internal data structures that are consulted(商量,顾及) each time a query or DML(数据操纵语言) statement constructs a read view.

Currently, InnoDB detects(发现,发觉) read-only transactions when:

The transaction is started with the START TRANSACTION READ ONLY statement.In this case, attempting to make changes to the database (for InnoDB, MyISAM, or other types of tables) causes an error, and the transaction continues in read-only state:

ERROR 1792 (25006): Cannot execute statement in a READ ONLY transaction.

You can still make changes to session-specific temporary(临时的) tables in a read-only transaction, or issue locking queries for them, because those changes and locks are not visible to any other transaction.

The autocommit setting is turned on(打开), so that the transaction is guaranteed to be a single statement, and the single statement making up the transaction is a “non-locking” SELECT statement.That is, a SELECT that does not use a FOR UPDATE or LOCK IN SHARED MODE clause.

InnoDB默认的read only有两种方式:

The transaction is started with the START TRANSACTION READ ONLY statement.

The autocommit setting is turned on(打开).

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 DML statements interspersed(散开的) with the queries.

==================END==================

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值