I'm working on a school project now that needs to characterize the performance of MySQL with regards to different isolation levels. I've tested things on READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE. Now I'd like to test things using snapshot isolation.
I understand that when using the default for REPEATABLE READ in InnoDB, snapshot isolation is used in conjunction, but I'm wondering, is it's possible to set the isolation level to snapshot isolation only? How would I do that?
To set the global isolation level at server startup, use the --transaction-isolation= level option on the command line or in an option file. Values of level for this option use dashes rather than spaces, so the permissible values are READ-UNCOMMITTED , READ-COMMITTED , REPEATABLE-READ , or SERIALIZABLE .
You need to enable snapshot isolation by setting the ALLOW_SNAPSHOT_ISOLATION database option in order to use it. The READ_COMMITTED_SNAPSHOT database option determines the behavior of the default READ COMMITTED isolation level when snapshot isolation is enabled in a database.
Snapshot isolation has been adopted by several major database management systems, such as InterBase, Firebird, Oracle, MySQL, PostgreSQL, SQL Anywhere, MongoDB and Microsoft SQL Server (2005 and later).
The default isolation level for InnoDB is REPEATABLE READ . A user can change the isolation level for a single session or for all subsequent connections with the SET TRANSACTION statement.
There is no global snapshot isolation level. From MySQL docs, START TRANSACTION
syntax:
You can also begin a transaction like this:
START TRANSACTION WITH CONSISTENT SNAPSHOT;
The
WITH CONSISTENT SNAPSHOT
option starts a consistent read for storage engines that are capable of it. This applies only to InnoDB. The effect is the same as issuing aSTART TRANSACTION
followed by aSELECT
from any InnoDB table. See Section 13.6.8.2, “Consistent Nonlocking Reads”. TheWITH CONSISTENT SNAPSHOT
option does not change the current transaction isolation level, so it provides a consistent snapshot only if the current isolation level is one that permits consistent read (REPEATABLE READ
orSERIALIZABLE
).
So, you'll have to set isolation level to REPEATABLE READ
or SERIALIZABLE
and start your transactions with the above syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With