As of MySQL 5.6.4,
InnoDB can avoid the
overhead associated with setting up the
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 reduces the size of internal data
structures that are consulted each time a query or DML statement
constructs a read view.
InnoDB detects read-only
The transaction is started with the
READ ONLY statement. In this case, attempting to
make changes to the database (for
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.
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
LOCK IN SHARED MODE
Thus, for a read-intensive application such as a report
generator, you can tune a sequence of
queries by grouping them inside
START TRANSACTION READ
COMMIT, or by
turning on the
setting before running the
or simply by avoiding any DML
statements interspersed with the queries.
For information about
Section 13.3.1, “START TRANSACTION, COMMIT, and ROLLBACK Syntax”.
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
INNODB STATUS output.
Copyright © 1997, 2015, Oracle and/or its affiliates. All rights reserved. Legal Notices