READ COMMITTED CLASS with READ COMMITTED INSTANCES

비교적 낮은 격리 수준(2)으로서 더티 읽기는 발생하지 않지만, 반복 불가능한 읽기와 유령 읽기는 발생할 수 있다. 즉, 위에 설명한 REPEATABLE READ CLASS with READ COMMITTED INSTANCES(수준 4)와 유사하지만, 테이블 스키마에 대해서는 다르게 동작한다. 트랜잭션 T1이 조회 중인 테이블에 대해 다른 트랜잭션 T2가 스키마를 변경할 수 있으므로, 테이블 스키마 갱신에 의한 반복 불가능한 읽기가 발생할 수 있다.

다음과 같은 규칙이 적용된다.

이 격리 수준은 배타 잠금에 대해서는 2단계 잠금을 따른다. 하지만 행에 대한 공유 잠금은 행이 조회된 직후 바로 해제되고, 테이블에 대한 의도 잠금도 바로 해제되므로 반복 불가능한 읽기가 발생될 수 있다.

예제

다음은 동시에 수행되는 트랜잭션의 격리 수준이 READ COMMITTED CLASS with READ COMMITTED INSTANCES인 경우 한 트랜잭션에서 객체 읽기를 수행하는 동안 다른 트랜잭션이 새로운 레코드를 추가 또는 갱신할 수 있으므로 유령 읽기 및 반복 불가능한 읽기가 발생할 수 있고, 테이블 스키마에 대해서도 반복 불가능한 읽기가 발생할 수 있음을 보여주는 예제이다.

session 1

session 2

;autocommit off

AUTOCOMMIT IS OFF

 

SET TRANSACTION ISOLATION LEVEL 2

;xr

 

Isolation level set to:

READ COMMITTED SCHEMA, READ COMMITTED INSTANCES.

;autocommit off

AUTOCOMMIT IS OFF

 

SET TRANSACTION ISOLATION LEVEL 2

;xr

 

Isolation level set to:

READ COMMITTED SCHEMA, READ COMMITTED INSTANCES.

--creating a table

 

CREATE TABLE isol2_tbl(host_year integer, nation_code char(3));

CREATE UNIQUE INDEX on isol2_tbl(nation_code, host_year);

INSERT INTO isol2_tbl VALUES (2008, 'AUS');

 

COMMIT;

;xr

 

 

--selecting records from the table

SELECT * FROM isol2_tbl;

;xr

 

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2008  'AUS'

 

1 rows selected.

INSERT INTO isol2_tbl VALUES (2004, 'AUS');

 

INSERT INTO isol2_tbl VALUES (2000, 'NED');

;xr

 

2 rows affected.

 

 

/* able to insert new rows even if tran 2 uncommitted */

 

 

SELECT * FROM isol2_tbl;

;xr

 

/* phantom read may occur when tran 1 committed */

COMMIT;

;xr

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2008  'AUS'

         2004  'AUS'

         2000  'NED'

 

3 rows selected.

INSERT INTO isol2_tbl VALUES (1994, 'FRA');

;xr

 

1 rows affected.

 

 

SELECT * FROM isol2_tbl;

;xr

 

/* unrepeatable read may occur when tran 1 committed */

DELETE FROM isol2_tbl

WHERE nation_code = 'AUS' and

host_year=2008;

;xr

 

1 rows affected.

 

/* able to delete rows even if tran 2 uncommitted */

 

COMMIT;

;xr

=== <Result of SELECT Command> ===

    host_year  nation_code

===================================

         2004  'AUS'

         2000  'NED'

         1994  'FRA'

 

3 rows selected.

ALTER TABLE isol2_tbl

ADD COLUMN gold INT;

;xr

 

1 command(s) successfully processed.

 

/* able to alter the table schema even if tran 2 is uncommitted yet*/

 

 

/* unrepeatable read may occur so that result shows different schema */

 

SELECT * FROM isol2_tbl;

;xr

COMMIT;

;xr

=== <Result of SELECT Command > ===

host_year  nation_code  gold

===================================

  2004  'AUS'           NULL

  2000  'NED'           NULL

  1994  'FRA'           NULL

 

3 rows selected.