Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set InnoDB in MySQL to the snapshot isolation level

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?

like image 347
user1251858 Avatar asked Mar 26 '12 22:03

user1251858


People also ask

How do I change the isolation level in MySQL?

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 .

How do I enable snapshot isolation?

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.

Does MySQL use snapshot isolation?

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).

Which of the following is default isolation level in MySQL InnoDB?

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.


1 Answers

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 a START TRANSACTION followed by a SELECT from any InnoDB table. See Section 13.6.8.2, “Consistent Nonlocking Reads”. The WITH 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 or SERIALIZABLE).

So, you'll have to set isolation level to REPEATABLE READ or SERIALIZABLE and start your transactions with the above syntax.

like image 51
ypercubeᵀᴹ Avatar answered Oct 15 '22 19:10

ypercubeᵀᴹ