Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DB] Phantom Read?? #15

Open
NownS opened this issue Apr 8, 2022 · 1 comment
Open

[DB] Phantom Read?? #15

NownS opened this issue Apr 8, 2022 · 1 comment

Comments

@NownS
Copy link
Collaborator

NownS commented Apr 8, 2022

Phantom Read

- 하나의 트랜잭션에서 일정 범위의 같은 쿼리를 두 번 실행했을 경우, 
  첫 번째 쿼리에서 없던 유령 레코드가 두 번째 쿼리에서 나타나는 상황, 
  첫 번째 쿼리에서 있던 레코드가 두 번째 쿼리에서 사라지는 상황
- 예시
    1. T1이 특정 조건으로 데이터들을 검색하여 결과를 얻는다
    2. T2가 접근하여 해당 조건의 데이터 일부를 삭제하거나 추가한다
    3. T1이 다시 해당 조건으로 데이터들을 조회하면 결과가 변경된다
- 해결 방안
    - Serializable 격리 수준이 가장 좋지만, 성능 저하 문제로 사용하지 않음
    - MySQL의 InnoDB는 멀티 버전 동시성 제어를 통해 어느정도 극복(next key lock)

이러한 방식으로 조사를 해 봤는데, 그렇다면 Repeatable Read 상태로 현재 트랜잭션 이전의 commit 상태에서만 확인 가능해진다면, Phantom Read도 해결이 되는 게 아닌가요?? 조사를 하다 보니 내용이 충돌해서 질문합니다~

@NownS
Copy link
Collaborator Author

NownS commented Apr 17, 2022

  • 트랜잭션 격리 수준에 대해서 더 조사 해 본 결과
    • 이전의 commit 상태에서만 확인 가능한 것
      -> MySQL 특정 버전 이후의 DB 엔진인 InnoDB 엔진에서 구현되어 있는 방식
    • InnoDB 스토리지 엔진에서는 Repeatable Read 격리 수준에서도 이미 Phantom Read가 발생하지 않음.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants