MySQL 5.7: Scope of SET TRANSACTION ISOLATION LEVEL for SELECT

isolation-levelMySQLoptimizationtransaction

The documentation states that without the GLOBAL or SESSION keyword, the isolation level will be valid for the next transaction and will be reverted to the session default after the transaction was commited.

With autocommit enabled, what is the scope of an transaction isolation level for a SELECT statement?

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT * FROM mytable WHERE id = 1;

Is a SELECT statement a complete transaction, meaning the isolation level will be reverted to session default after the SELECT was executed, or does a SELECT somehow not represent its own transaction, meaning that the isolation level will not be restored after a SELECT statement?

Best Answer

(To answer question in comment)

There are three ways to build a transaction:

(1)

BEGIN;
any number of statements  -- all in one transaction
COMMIT;

(2)

SET AUTOCOMMIT = ON;
...
statement  -- This is a transaction
...
statement  -- This is a different transaction

(3)

SET AUTOCOMMIT = OFF;
...
statement
statement
COMMIT;  -- 2 statements in a transaction

statement
statement
COMMIT;  -- another 2 statements in a different transaction