격리 μμ€
β’
SERIALIZABLE λ§κ³ λ ν¬κ² μ±λ₯μ κ°μ μ΄λ μ ν λ°μ X
λΆμ ν© ν
μ΄λΈ
DRITY READ | NON-REPEATABLE READ | PHANTOM READ | |
READ UNCOMMITTED | λ°μ | λ°μ | λ°μ |
READ COMMITTED | μμ | λ°μ | λ°μ |
REPEATABLE READ | μμ | μμ | λ°μ(InnoDBλ μμ) |
SERIALIZABLE | μμ | μμ | μμ |
READ UNCOMMITTED
β’
dirty read: commit, rollback μ¬λΆμ μκ΄μμ΄ λ€λ₯Έ νΈλμμ
μμ λ³κ²½ λ΄μ©μ΄ 보μ΄λ νμ
# session 1
start transaction;
update morak.member set name='eden2' where id=1;
insert into member;
# session 2
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
select * from morak.member;
# commit μνλλ° λ³κ²½λ λ΄μ©μ΄ 보μΈλ€.
SQL
볡μ¬
READ COMMITTED
β’
μΈλλ‘κ·Έ λ°μ΄ν° λ°ν
β’
non-repeatable read: νλμ νΈλμμ
λ΄μμ λκ°μ μ‘°ν 쿼리λ₯Ό μ€ννμ λ νμ κ°μ κ²°κ³Όλ₯Ό κ°μ ΈμμΌ νλ€λ repeatable read μ ν©μ±μ μ΄κΈλλ νμ
# session 2
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
start transaction;
select * from member where name='eden2';
# κ²°κ³Ό μμ
# session 1
start transaction;
update morak.member set name='eden2' where id=1;
commit;
# session 2s
elect * from member where name='eden2';
# κ²°κ³Ό μ‘°νλ¨
SQL
볡μ¬
β’
μμ: νλμ νΈλμμ
μμ μ
κΈκ³Ό μΆκΈ μ²λ¦¬κ° κ³μ μ§νλ λ λ€λ₯Έ νΈλμμ
μμ μ€λ μ
κΈλ κΈμ‘μ μ΄ν©μ μ‘°νν λ λ¬Έμ
REPEATABLE READ
β’
InnoDB μ€ν λ¦¬μ§ μμ§ κΈ°λ³Έ 격리 μμ€
β’
λ°μ΄λ리 λ‘κ·Έλ₯Ό κ°μ§ MySQL μλ²μμλ μ΅μ REPEATABLE READ 격리 μμ€ μ΄μ μ¬μ©
β’
λ³κ²½νκΈ° μ λ μ½λλ₯Ό μΈλ 곡κ°μ λ°±μ
ν΄λκ³ λ μ½λ κ° λ³κ²½ -> MVCC λΌκ³ ν¨
β’
μΈλ μμμ λ°±μ
λ μ΄μ λ°μ΄ν°λ₯Ό νμ©νμ¬ λμΌ νΈλμμ
λ΄μμ λμΌ κ²°κ³Ό 보μ¬μ€ μ μκ² λ³΄μ₯
μΈλ μμ
β’
μ¬μ€ READ COMMITTED λ μΈλ λ‘κ·Έ μ‘°ν
β’
REPEATABLE READ μ READ COMMITTED μ μ°¨μ΄λ μΈλ μμμ λ°±μ
λ λ μ½λμ μ¬λ¬ λ²μ μ€ λͺ λ²μ§Έ μ΄μ λ²μ κΉμ§ μ°Ύμ λ€μ΄κ°λμ§
β’
μΈλ μμμ λ°±μ
λ λͺ¨λ λ μ½λμλ λ³κ²½μ λ°μμν¨ νΈλμμ
λ²νΈ ν¬ν¨
β’
μΈλ μμμ λ°±μ
λ λ°μ΄ν°λ InnoDB μ€ν λ¦¬μ§ μμ§μ΄ λΆνμνλ€κ³ νλ¨νλ μμ μ μ£ΌκΈ°μ μΌλ‘ μμ
β’
REPEATABLE READ 격리 μμ€μμλ MVCC λ₯Ό 보μ₯νκΈ° μν΄ μ€ν μ€μΈ νΈλμμ
μ€ κ°μ₯ μ€λλ νΈλμμ
λ²νΈλ³΄λ€ νΈλμμ
λ²νΈκ° μμ μΈλ μμμ λ°μ΄ν° μμ λΆκ°
β’
begin μΌλ‘ νΈλμμ
μ μμνκ³ μ₯μκ° νΈλμμ
μ μ’
λ£νμ§ μμΌλ©΄ μΈλ μμμ λ°μ΄ν°κ° 무μ ν μμΌ μ μλ€.
β’
μΈλ μμ λ μ½λμλ μ κΈμ κ±Έ μ μλ€
# session 2
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
start transaction;
select * from member;
# 6κ°μ row
# start transaction λ€ μ΄λ ν 쿼리λ μμΌλ©΄ transaction μ΄ λ±λ‘λμ§ μλλ€. κ·Έλμ ν¬ν
리λ ν
μ€νΈ λΆκ°λ₯
# session 1
start transaction;
insert into member;
commit;
# session 2
select * from member;
# 6κ°μ row
select * from member for update;
# 7κ°μ row
# μΈλ μμμλ μ κΈμ λͺ» κ±Έμ΄μ μ€μ ν
μ΄λΈμμ κ°μ Έ μμΌν΄μ κ·Έλ°λ―?
select * from member;
# 6κ°μ row
delete from member where id=7;
# Query OK, 1 row affected (0.01 sec)
SQL
볡μ¬
session 1 μΒ select * from member where name='eden' for updateΒ λ₯Ό κ±Έμλ€.
SERIALIZABLE
β’
κ°μ₯ μ격ν 격리 μμ€
β’
λμ μ²λ¦¬ μ±λ₯ μ΅ν
β’
μ½κΈ° μμ
λ 곡μ μ κΈμ νλν΄μΌ νλ€
SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
start transaction;
select * from morak.member where id=1;
# member μ id=1 μΈ λ μ½λμ S,REC_NOT_GAP λ½ κ±Έλ¦Ό
select * from morak.member;
# λͺ¨λ member λ μ½λμ S λ½ κ±Έλ¦Ό
update member where id=1;
# member μ id=1 μΈ λ μ½λμ X,REC_NOT_GAP λ½ κ±Έλ¦Ό
delete from member where name='zz';
# λͺ¨λ member λ μ½λμ X λ½ κ±Έλ¦Ό
SQL
볡μ¬