간단하게 SERIALIZABLE REPEATABLE READ Lock이 어떻게 걸리는지를 테스트 해 보았다.

 

-- 데이터를준비한다.

-- drop table tA

create table tA (col1 int)

 

insert into tA select 1

insert into tA select 5

insert into tA select 10

  

-- repeatable read TEST

set transaction isolation level repeatable read

begin tran

 

       select col1 from tA where col1 between 2 and 4

       -- 여기까지수행후 다른 spid로 접속해 sp_lock 수행

사용자 삽입 이미지

       select col1 from tA where col1 between 2 and 6
       -- 여기까지수행후 다른 spid로 접속해 sp_lock 수행
사용자 삽입 이미지

REPEATABLE READ의 경우 데이터가 있는 경우 SELECT를 하면 Row Lock 이 걸린다.

 

commit

 

 

-- serializable TEST

set transaction isolation level serializable

begin tran

 

       select col1 from tA where col1 between 2 and 4

       -- 여기까지수행후 다른 spid로 접속해 sp_lock 수행

사용자 삽입 이미지
 

       select col1 from tA where col1 between 2 and 6

       -- 여기까지수행후 다른 spid로 접속해 sp_lock 수행

사용자 삽입 이미지

             데이터가 있으나 없으나 무조건 Table Lock을 걸어 버린다.


commit


인덱스를 추가하면 Table Lock 대신 Range Lock을 건다!

 
하만철 / Ha Man cheol

AND