SQL-complete-tutorial
21 строка · 1005.0 Байт
1/*
2Database concurrency is the ability of a database to allow multiple
3users to affect multiple transactions. This is one of the main properties
4that separates a database from other forms of data storage, like spreadsheets.
5
6Concurrency problems:
71. lost updates
82. dirty reads
93. non-repeating reads
104. phantom reads
11*/
12
13SHOW VARIABLES LIKE 'transaction_isolation';
14SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE; -- only for the current session;
15SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE; -- set it globally;
16
17-- ISOLATION LEVELS --
18-- 1. READ UNCOMMITTED - the lowest isolation level with all concurrency problems;
19-- 2. READ COMMITTED - here we don't have dirty reads, but do have unrepeatable or inconsistent reads.
20-- 3. REPEATABLE READ - this is the DEFAULT isolation level in mysql, which solves most of the concurrency problems (not phantom reads);
21-- 4. SERIALIZABLE - solves all concurrency problems, but has more locks, recourses which can hurt performances and reliability.
22