{"componentChunkName":"component---src-templates-post-template-js","path":"/211208-database-transaction/","result":{"data":{"allMarkdownRemark":{"edges":[{"node":{"id":"08021c4c-bb34-5b08-8c1b-31962ef4022f","html":"<blockquote>\n<p>“정확성과 일관성”을 보장하기 위해 전체에서 완료해야 하는 데이터베이스 처리의 논리적(분할할 수 없는 작업) 단위를 Transaction이라 한다. 일반적으로 검색, 삽입, 삭제 및 업데이트와 같은 데이터베이스 commands가 포함된다.</p>\n</blockquote>\n<p>데이터베이스 트랜잭션을 실행하는 “대규모 데이터베이스” 및 “수백 명의 동시 사용자”가 있는 시스템을 <strong>트랜잭션 처리 시스템</strong>이라 한다.</p>\n<br />\n<div style=\"text-align:center;\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/144976532-f61797ac-e86f-4bfd-98e1-6018a102ba58.png\" width=\"600px\">\n</div>\n<p>(Scenario: 박지성 wants to send some money to 김연아.)</p>\n<h2>Terminology</h2>\n<h3>트랜젝션의 유형</h3>\n<ul>\n<li>\n<p><strong>Read-only</strong> transaction: 데이터베이스를 업데이트할 수 없다. (Lock이 필요없음)</p>\n</li>\n<li>\n<p><strong>Read-write</strong> transaction: 데이터베이스를 업데이트할 수 있다. (Lock이 필요함)</p>\n</li>\n</ul>\n<h3>트랜잭션 처리 개념의 주요 용어</h3>\n<ul>\n<li>\n<p><strong>Data item</strong>: “데이터베이스 레코드”(튜플), “디스크 블록”, “필드 값”, “전체 파일” 또는 “전체 데이터베이스”</p>\n<ul>\n<li>각 데이터 항목을 고유하게 식별하는 수단으로 사용되는 고유한 이름을 가진다.</li>\n</ul>\n</li>\n<li>\n<p><strong>Granularity</strong>: 데이터 항목의 크기로, 이에 따라 얼마나 정교한 Lock을 수행하는지 결정된다.</p>\n</li>\n<li>\n<p><strong>Database</strong>: “named data items” 모음</p>\n</li>\n</ul>\n<h3>트랜잭션에 포함될 수 있는 데이터베이스 접근 작업</h3>\n<ul>\n<li>\n<p><code class=\"language-text\">read_item(X)</code>: 데이터 항목 X를 프로그램 변수(x)로 읽는다.</p>\n</li>\n<li>\n<p><code class=\"language-text\">write_item(X)</code>: x의 값을 X라는 데이터 항목에 쓴다.</p>\n</li>\n</ul>\n<br />\n<h1>트랜잭션 및 시스템 개념, 트랜잭션의 바람직한 속성</h1>\n<hr />\n<h2>Transaction States (트랜잭션 상태)</h2>\n<p>(복구 관리자) DBMS는 다음 작업(<strong>start</strong>, <strong>terminate</strong>, <strong>commit</strong>, and/or <strong>abort</strong>)을 추적해야 한다.</p>\n<p><code class=\"language-text\">BEGIN_TRANSACTION</code>: 트랜잭션 실행의 <strong>시작</strong></p>\n<p><code class=\"language-text\">READ</code> or <code class=\"language-text\">WRITE</code>: 데이터베이스 항목에 대한 <strong>읽기</strong> 또는 <strong>쓰기</strong></p>\n<p><code class=\"language-text\">END_TRANSACTION</code>: <code class=\"language-text\">READ</code> 또는 <code class=\"language-text\">WRITE</code>의 트랜잭션 작업이 <strong>종료</strong></p>\n<ul>\n<li>해당 트랜잭션의 상태를 확인하는 데 필요하다: <strong>committed</strong> 또는 <strong>aborted</strong>.</li>\n</ul>\n<p><code class=\"language-text\">COMMIT_TRANSCATION</code>: 트랜잭션의 <strong>성공적인 종료</strong>. (영구적으로 기록된 변경 사항)</p>\n<p><code class=\"language-text\">ROLL_BACK</code> (or <code class=\"language-text\">ABORT</code>): 트랜잭션이 <strong>비성공적으로 종료</strong>. (실행을 취소해야 함)</p>\n<br/>\n<div style=\"text-align:center;\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/144978343-60718ef7-b3c2-4cc2-aa91-4dff7bb1a4fd.png\" width=\"700px\">\n</div>\n<br />\n<p><strong>Partially committed:</strong></p>\n<ul>\n<li>\n<p><strong>하나의 트랜젝션이 아니므로 real time으로 판단하여 작업을 선택해야 한다. 이로 인해 사용자에 대한 빠른 응답을 제공한다.</strong></p>\n</li>\n<li>\n<p>DBMS는 각 트랜잭션이 아닌 디스크의 변경 사항을 한 번에 반영한다.</p>\n</li>\n<li>\n<p>일부 <strong>concurrency control</strong> (동시성 제어) 프로토콜은 커밋 가능성을 추가로 확인한다.</p>\n</li>\n<li>\n<p>일부 <strong>recovery (복구) 프로토콜</strong>은 실패 및 데이터베이스에 대한 영향을 확인한다.</p>\n</li>\n</ul>\n<p><strong>Failed:</strong></p>\n<ul>\n<li>\n<p>check 중 하나가 실패하거나 트랜잭션이 중단된 경우이다.</p>\n</li>\n<li>\n<p>실패하거나 중단된 트랜잭션은 사용자에 의해 또는 자동으로 다시 시작될 수 있다.</p>\n</li>\n</ul>\n<p><strong>Terminated:</strong></p>\n<ul>\n<li>트랜잭션이 시스템을 떠난다.</li>\n</ul>\n<br />\n<h2>Why Recovery Is Needed?</h2>\n<p>트랜잭션이 실행을 위해 DBMS에 제출되면 해당 트랜잭션의 터미널 상태는 DBMS에 의해 결정되며 두가지 경우, <strong>Committed</strong>와 <strong>Aborted</strong>가 있다.</p>\n<p>트랜잭션이 일부 작업을 실행한 후 <strong>모든 작업을 실행하기 전에 실패하면 이미 실행된 작업을 취소해야 하며 지속 효과가 없어야 한다.</strong></p>\n<h3>Types of failures</h3>\n<ol>\n<li><strong>컴퓨터 장애</strong>: 거래 실행 중 컴퓨터 시스템에 하드웨어/소프트웨어/네트워크 오류가 발생한 경우 메모리 충돌</li>\n<li><strong>트랜잭션 또는 시스템 오류</strong>: 정수 오버플로, 0으로 나누기 등 또는 사용자 인터럽트</li>\n<li><strong>로컬 오류</strong> 또는 <strong>트랜잭션에 의해 감지된 예외 조건</strong>: 잔액 부족과 같은 예외 조건</li>\n<li><strong>동시성 제어 강제</strong>: 직렬성 위반 또는 교착 상태 감지로 인한 것</li>\n<li><strong>디스크 장애</strong>: 디스크 블록의 오작동</li>\n<li><strong>신체적 문제 및 재난</strong>: 화재, 도난, 정전 …</li>\n</ol>\n<p><strong>➡️ DBMS는 유형 1-4 장애(다른 것보다 일반적임)로부터 신속하게 복구할 수 있도록 충분한 정보를 유지해야 한다.</strong></p>\n<br />\n<h2>System Log (시스템 로그)</h2>\n<blockquote>\n<p>장애 복구를 위해 DBMS에서 유지 관리하며, 데이터베이스 항목의 값에 영향을 미치는 트랜잭션 작업을 추적한다.</p>\n</blockquote>\n<p>(디스크에 저장되는 <strong>sequential</strong>한 <strong>append-only</strong> 파일은 디스크 또는 치명적인 오류를 제외하고 안전하다.)</p>\n<p><strong>Log buffer</strong>: 로그를 기록하는 데 사용되는 하나 이상의 메인 메모리 버퍼</p>\n<ul>\n<li>로그 항목이 가득 차면 디스크의 로그 파일 “끝”에 추가된다.</li>\n</ul>\n<p><strong>로그 파일은 archival(기록) 스토리지에 주기적으로 백업됨으로, 치명적인 장애에 대비한다.</strong></p>\n<br/>\n<h3>Types of “Log Records”:</h3>\n<div>\n  <img src=\"https://user-images.githubusercontent.com/33220404/144980402-1c5ef275-1e2f-4c7c-a7d0-089276a8452f.png\" width=\"600px\">\n</div>\n<br />\n<p>시스템이 <strong>충돌</strong>하는 경우 로그를 검사하고 <strong>ARIES</strong>와 같은 복구 기술을 사용하여 일관된 데이터베이스 상태로 복구할 수 있다.</p>\n<br />\n<h3>UNDO operations: X를 old_value로 복원</h3>\n<ul>\n<li><strong>backward</strong>로 추적하여 T의 WRITE 작업의 효과를 취소한다.</li>\n</ul>\n<h3>REDO operations: X를 new_value로 업데이트</h3>\n<ul>\n<li>\n<p>트랜잭션의 업데이트가 로그에 기록되었지만 new_value를 데이터베이스에 기록하기 전에 오류가 발생한 경우 수행할 수 있다.</p>\n</li>\n<li>\n<p>ARIES에서 <strong>forward</strong> action을 취하는 데 사용된다.</p>\n</li>\n</ul>\n<br />\n<h2>Commit Point of Transaction T</h2>\n<blockquote>\n<p>데이터베이스에 액세스하는 모든 작업이 성공적으로 완료되고 작업의 효과가 로그에 기록될 때 발생한다. T는 커밋되었다고 한다.</p>\n</blockquote>\n<p><strong>T는 [commit, T] 커밋 레코드를 로그에 쓴다.</strong></p>\n<br />\n<p>장애가 발생했을 때,</p>\n<p><strong>1. T에 커밋 레코드가 있으면</strong> 로그 레코드에서 데이터베이스에 대한 <strong>redo effect</strong></p>\n<p><strong>2. T에 커밋 레코드가 없지만</strong> <code class=\"language-text\">start_transaction</code> 레코드가 있는 경우 복구 프로세스 동안 데이터베이스에 대한 <strong>undo effect</strong> (<strong>rollback</strong>)</p>\n<br />\n<p><strong>Force-writing</strong>: <strong>트랜잭션을 커밋하기 전에 디스크에 로그 버퍼를 flush한다.</strong></p>\n<ul>\n<li>\n<p>트랜잭션이 커밋 지점에 도달하기 전에 아직 디스크에 기록되지 않은 로그 부분을 디스크에 쓰는 것을 나타낸다.</p>\n</li>\n<li>\n<p>복구 중에 디스크에 저장된 로그 항목만 고려할 수 있다.</p>\n</li>\n</ul>\n<br />\n<h2>ACID Properties of Transaction</h2>\n<p><strong>Atomicity</strong> (원자성): <u>recovery subsystem</u>의 책임</p>\n<ul>\n<li>트랜잭션은 처리의 <strong>원자 단위</strong>이다(all or nothing).</li>\n</ul>\n<p><strong>Consistency</strong> (일관성): <u>프로그래머의</u> 책임</p>\n<ul>\n<li>트랜잭션은 <strong>일관성을 유지</strong>해야 한다: 간섭이 없는 경우 일관성 있는 데이터베이스</li>\n</ul>\n<p><strong>Isolation</strong> (격리): <u>동시성 제어 subsystem</u>에 의해 시행</p>\n<ul>\n<li>트랜잭션은 다른 <strong>트랜잭션과 분리되어 실행</strong>되는 것처럼 나타나야 한다. 실행이 다른 사람에 의해 중단되어서는 안 된다.</li>\n</ul>\n<p><strong>Durability</strong> (내구성): <u>recovery subsystem의</u> 책임</p>\n<ul>\n<li>커밋된 트랜잭션에 의해 적용된 변경 사항은 데이터베이스에서 지속되어야 한다. 즉, 어떤 실패로 인해 손실되지 않아야 한다.</li>\n</ul>\n<p><strong>➡️ 이 네 가지 속성은 모든 트랜잭션이 소유해야 한다(MUST).</strong></p>\n<br />\n<h1>Characterizing Schedules Based on Serializability</h1>\n<hr />\n<p>트랜젝션 작업을 ordering한다. 다른 트랜젝션의 작업은 <strong>Schedule</strong>에서 <strong>serial</strong> 또는 <strong>interleaved</strong>될 수 있다.</p>\n<ul>\n<li>\n<p>두 트랜잭션 T1 및 T2를 ”<strong>interleaving</strong>“하는 Schedule(S)의 예:</p>\n<p><strong>S</strong>: <span style=\"color:blue;\">r1(X); </span> <span style=\"color:red;\">w2(X); </span><span style=\"color:blue;\">w1(X); </span><span style=\"color:blue;\">r1(Y); </span><span style=\"color:red;\">w2(X); </span><span style=\"color:blue;\">w1(Y); </span></p>\n</li>\n</ul>\n<p><strong>S의 전체 작업 순서</strong>는 S의 두 작업에 대해 하나의 작업이 다른 작업보다 먼저 발생해야 하며, <strong>S의 부분 작업 순서</strong>는 특정 작업 사이의 시간 순서가 시스템에 의해 결졍되지 않은 경우 지정한다.</p>\n<br />\n<h2>Serial Schedule</h2>\n<p>S의 모든 트랜잭션 T에 대해 T의 모든 작업이 다른 작업의 interleaved 작업 없이 <strong>연속적으로 실행되는 경우</strong> Schedule S는 <strong>serial</strong>이다. 그렇지 않으면 <strong>nonserial</strong>이라고 한다.</p>\n<p>모든 serial schedule은 <strong>정확하지만</strong>, 작업의 인터리빙을 금지하여 concurrency(동시성)을 제한하며, 다른 트랜젝션이 완료될 때까지 기다릴 수 없다.</p>\n<p><strong>Solution</strong> ➡️ serial schedule과 <strong>“equivalent”</strong> 한 schedule을 결정하고 해당 schedule이 발생하도록 허용한다. <strong>그러나 어느 것이 equivalent하다고 판단하기는 쉽지 않다.</strong></p>\n<br />\n<h2>Conflicting Operations in a (Nonserial) Schedule</h2>\n<p><strong>Schedule의 두 operations은 다음과 같은 경우 충돌한다.</strong></p>\n<p><strong>1. Operations은 서로 다른 트랜잭션에 속한다.</strong></p>\n<p><strong>2. Operations은 동일한 항목 X에 access한다.</strong></p>\n<p><strong>3. Operations 중 적어도 하나는 <code class=\"language-text\">write_item(X)</code> 이다.</strong></p>\n<p><strong>(위의 세 가지 조건이 모두 충족되어야 충돌이 발생한다.)</strong></p>\n<br />\n<p>직관적으로, 순서를 변경하면 다른 결과가 발생하는 경우 두 operations이 충돌한다. 충돌의 두가지 유형으로 <strong>1) read-write</strong> or <strong>2) write-write</strong> 충돌이 있다.</p>\n<ul>\n<li>ex) <strong>S</strong>: <span style=\"color:blue;\">r1(X); </span> <span style=\"color:red;\">w2(X); </span><span style=\"color:blue;\">w1(X); </span><span style=\"color:blue;\">r1(Y); </span><span style=\"color:red;\">w2(X); </span><span style=\"color:blue;\">w1(Y); </span></li>\n</ul>\n<p>따라서 이러한 충돌뿐만 아니라 “others”을 해결하기 위해 정교한 <strong>Concurrency Control(동시성 제어)</strong> 기술이 필요하다.</p>\n<br />\n<h2>Why Concurrency Control Needed in a Schedule</h2>\n<h3>Types of Problems (1)</h3>\n<p>동시에 실행할 수 있는 다음 트랜잭션을 고려한다.</p>\n<br />\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145139932-79220725-ffc3-485f-87a1-70fed1f6e0d3.png\" width=\"500px\">\n</div>\n<h3>Types of Problems (2)</h3>\n<br />\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145140104-d97ec821-d34b-4bda-9836-74e0270ea1ee.png\" width=\"700px\">\n</div>\n<h3>Types of Problems (3)</h3>\n<p><strong>The lost update (갱신 손실) problem</strong></p>\n<ul>\n<li>“동일한” 데이터베이스 항목에 액세스하는 두 트랜잭션이 일부 데이터베이스 항목의 값을 <strong>부정확하게 만드는 방식으로 작업이 인터리브되는 경우 발생</strong>한다.</li>\n</ul>\n<br />\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145140348-842bc566-9a90-4151-b550-2856d9205217.png\" width=\"700px\">\n</div>\n<h3>Types of Problems (4)</h3>\n<p><strong>The dirty read (or temporary update) problem</strong></p>\n<ul>\n<li>\n<p>한 트랜잭션이 데이터베이스 항목을 업데이트한 다음 어떤 이유로 트랜잭션이 <strong>실패할 때 발생</strong>한다.</p>\n</li>\n<li>\n<p>한편, 업데이트된 항목은 원래 값으로 변경(or <strong>rolled back</strong>)되기 전에 다른 트랜잭션에서 읽는다.</p>\n</li>\n</ul>\n<br />\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145140596-71eae105-e0da-44a8-905c-48777fb66d70.png\" width=\"700px\">\n</div>\n<h3>Types of Problems (5)</h3>\n<p><strong>The incorrect summary problem (called phantom read)</strong></p>\n<ul>\n<li>\n<p>한 트랜잭션이 여러 데이터베이스 항목에 대한 <strong>aggregate summary(집계 요약) 기능을 계산하는 동안</strong> 다른 트랜잭션이 이러한 항목 중 일부를 업데이트하는 경우 발생.</p>\n<ul>\n<li>집계 함수는 값이 업데이트되기 전후에 요약을 계산할 수 있다.</li>\n</ul>\n</li>\n</ul>\n<br />\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145140828-f95ee818-c78f-401e-b2d2-44417e90c65a.png\" width=\"700px\">\n</div>\n<h3>Types of Problems (6)</h3>\n<p><strong>The unrepeatable(반복 불가능한) read problem</strong></p>\n<ul>\n<li>트랜잭션 T가 동일한 항목을 두 번 읽고 두 읽기 사이에 다른 트랜잭션 T’에 의해 항목이 변경된 경우 발생한다. 따라서 T는 <strong>두 읽기에 대해 다른 값을 받는다.</strong></li>\n</ul>\n<blockquote>\n<p><strong>이러한 문제를 해결하고 nonserial하지만 serializable schedule을 생성하려면 우수한 동시성 제어가 필요하다.</strong></p>\n</blockquote>\n<br />\n<h2>Serializable (직렬 가능한) Schedule</h2>\n<p>동일한 n개 트랜잭션의 일부 serial schedule과 동일하다.</p>\n<p>동시 트랜잭션을 직렬로 배치한다.</p>\n<ul>\n<li>\n<p>S1이 직렬 스케줄(T1;T2 | T2;T1)이고 S2가 비직렬 스케줄이라고 가정한다.</p>\n</li>\n<li>\n<p>만약, S1과 S2가 데이터베이스의 <strong>동일한</strong> 최종 상태를 생성하면 S1과 S2가 동일할 수 있다.</p>\n<ul>\n<li>이때, S2는 <strong>Serializable</strong> (직렬화 가능) 하다고 한다.</li>\n</ul>\n</li>\n</ul>\n<p><strong>동시 트랜잭션이 실행될 때 항상 올바른 것으로 간주된다. 이는 동시 실행의 이점을 제공한다.</strong></p>\n<br />\n<p>[주의] 초기값 X = 100에 대해 결과가 동일하지만 일반적으로 결과가 동일하지 않은 두 개의 스케줄</p>\n<div>\n  <img src=\"https://user-images.githubusercontent.com/33220404/145141723-daca9ae5-81a2-41ce-9a5a-03cc391c9a45.png\" width=\"300px\">\n</div>\n<br />\n<h3>예시</h3>\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145141921-28654368-56a1-4e10-a8bf-e45ebfe87109.png\" width=\"800px\">\n</div>\n<br />\n<h2>How to Ensure Serializablity?</h2>\n<h3><strong>Use concurrency control (CC) protocols:</strong></h3>\n<ul>\n<li>\n<p><strong>Two-phase locking (2PL)</strong> : 가장 일반적인 기술.</p>\n<ul>\n<li>\n<p>동시 트랜잭션이 서로 간섭하지 않도록 데이터 항목을 <strong>Lock</strong>한다.</p>\n<ul>\n<li>잠금은 세 가지 주요 문제를 나타낸다. <strong>1) 높은 overhead</strong> (lock 요청 후 read 또는 write), <strong>2) Deadlock</strong>, and <strong>3) Starvation</strong></li>\n</ul>\n</li>\n<li>\n<p>Two phases: <strong>growing</strong> (acquiring) and <strong>shrinking</strong> (releasing) phases on locks</p>\n</li>\n<li>\n<p>직렬성을 보장하는 추가 조건을 적용하지만, <strong>Deadlock(교착 상태)</strong> 를 방지할 수는 없다.</p>\n<ul>\n<li><strong>Deadlock</strong>은 집합의 각 트랜잭션 T가 집합의 다른 트랜잭션 T’에 의해 <strong>locked 일부 항목을 기다리고 있을 때 발생한다.</strong></li>\n</ul>\n<div style=\"text-align:center\">\n  <img src=\"https://user-images.githubusercontent.com/33220404/145142666-86b226b6-46d9-4152-ad3c-30543649e798.png\" width=\"600px\">\n</div>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Snapshot isolation</strong> : 일부 DBMS에서 사용 (2PL보다 적은 overhead)</p>\n<ul>\n<li>\n<p>트랜잭션은 시작될 때 데이터베이스 스냅샷에 있는 항목의 커밋된 값을 기반으로 읽은 데이터 항목을 본다.</p>\n</li>\n<li>\n<p>phantom 레코드 문제가 발생하지 않도록 한다.</p>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Timestamp ordering</strong></p>\n<ul>\n<li>각 트랜잭션에는 고유한 timestamp가 할당되며, 프로토콜은 충돌하는 작업이 트랜잭션 timestamp 순서대로 실행되도록 한다.</li>\n</ul>\n</li>\n<li>\n<p><strong>Multiversion concurrent control (MVCC) protocols</strong></p>\n<ul>\n<li>여러 버전의 데이터 항목 유지 관리 기반으로 한다.</li>\n</ul>\n</li>\n<li>\n<p><strong>Optimistic protocols</strong></p>\n<ul>\n<li>트랜잭션이 종료된 후 커밋이 허용되기 전에 직렬화 가능성 위반 가능성을 확인한다.</li>\n</ul>\n</li>\n</ul>\n<br />\n<h1>Transaction Support In SQL</h1>\n<hr />\n<p>일반적으로 명시적인 <code class=\"language-text\">Begin_Transaction</code> 문이 없다. 대신 모든 트랜잭션에는 명시적인 종료 문이 있다.</p>\n<ul>\n<li><code class=\"language-text\">COMMIT</code> | <code class=\"language-text\">ROLLBACK</code></li>\n</ul>\n<p>모든 트랜잭션에는 관련된 특정 특성이 있다.</p>\n<ul>\n<li>\n<p><strong>isolation level</strong>으로 지정할 수 있다.</p>\n</li>\n<li>\n<p>SQL에서 <strong>isolation level</strong>을 지정하는 방법 : <code class=\"language-text\">ISOLATION LEVEL &lt;isolation></code></p>\n<ul>\n<li>\n<p>isolation = <code class=\"language-text\">READ UNCOMMITTED</code> | <code class=\"language-text\">READ COMMITTED</code> (by default in <strong>Oracle</strong>)</p>\n</li>\n<li>\n<p>isolation = <code class=\"language-text\">REPEATABLE READ</code> | <code class=\"language-text\">SERIALIZABLE</code> (by default in <strong>most DBMSes</strong>)</p>\n</li>\n</ul>\n</li>\n</ul>\n<br />\n<h2>What Happens if Serializability is Violated?</h2>\n<p>트랜잭션이 <code class=\"language-text\">SERIALIZABLE</code> 보다 lowel level에서 실행되는 경우, 다음 세 가지 위반 사항 중 하나 이상이 발생할 수 있다.</p>\n<h3>Dirty read (오손 읽기)</h3>\n<ul>\n<li>\n<p>T1은 아직 커밋되지 않은 T2의 업데이트를 읽을 수 있다.</p>\n</li>\n<li>\n<p>T2가 중단되면 존재하지 않고 잘못된 값을 읽었을 것이다.</p>\n</li>\n</ul>\n<h3>Nonrepeatable read (반복 불가능)</h3>\n<ul>\n<li>\n<p>T1은 테이블에서 주어진 값을 읽을 수 있다.</p>\n</li>\n<li>\n<p>T2가 나중에 해당 값을 업데이트하면 T1이 해당 값을 다시 읽고 T1은 다른 값을 보게 된다.</p>\n</li>\n</ul>\n<h3>Phantoms (유령 데이터)</h3>\n<ul>\n<li>\n<p>T1은 SQL <code class=\"language-text\">WHERE</code> 절에 지정된 일부 조건에 따라 테이블에서 rows 집합을 읽을 수 있다.</p>\n</li>\n<li>\n<p>T2는 조건을 만족하는 새 레코드를 삽입한다.</p>\n</li>\n<li>\n<p>T1은 <strong>phantom</strong>이라고 하는 새 레코드를 동일한 테이블로 볼 수도 있다.</p>\n</li>\n<li>\n<p>T1은 시작할 때 레코드를 보지 못했다.</p>\n</li>\n</ul>\n<br />\n<h3><strong>SQL에 정의된 isolation levels에 따라 가능한 violation(위반)</strong></h3>\n<div>\n  <img src=\"https://user-images.githubusercontent.com/33220404/145144009-a911b98d-caa0-425f-ac79-1e771e91b650.png\" width=\"700px\">\n</div>\n<p><strong>위 표의 명시되어 있는 Isolation Level이 낮아질수록 Conccruency가 높아지며, 높아질수록 성능이 높아진다.</strong></p>\n<br/>","frontmatter":{"title":"[Database] Transaction","date":"2021.12.08.","category":"Data Science","categoryColor":"seagreen","tags":["DB","SQL"]}}}]}},"pageContext":{"slug":"/211208-database-transaction/","next":{"frontmatter":{"title":"[Database] Indexing Structures for Files"},"fields":{"slug":"/211207-database-indexing/"}},"previous":{"frontmatter":{"title":"[Deep Learning] DNN 기본 코드 이해"},"fields":{"slug":"/211210-dl-dnn/"}}}},"staticQueryHashes":[]}