• Mindscape ๐Ÿ”ฅ
    • Playlist ๐ŸŽง
  • ๐Ÿง  Algorithm

    • Python ์‹œ๊ฐ„ ์ดˆ๊ณผ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ํŒ
    • C++ std::vector ์‚ฌ์šฉ๋ฒ• ์ •๋ฆฌ
    • Vim ์‚ฌ์šฉ ๋งค๋‰ด์–ผ
    • 1018๋ฒˆ: ์ฒด์ŠคํŒ ๋‹ค์‹œ ์น ํ•˜๊ธฐ
    • 1966๋ฒˆ: ํ”„๋ฆฐํ„ฐ ํ
  • ๐Ÿ—‚๏ธ Database System

    • 1. Introduction
    • 2. Relational Model
    • 3. SQL
    • 6. E-R Model
    • 7. Relational Database Design (1)
    • 7. Relational Database Design (2)
    • 13. Data Storage Structures
    • 14. Indexing
    • 15. Query Processing
    • 16. Query Optimization
    • 17. Transactions
    • 18. Concurrency control
  • ๐Ÿง Operating System

    • 7. Deadlocks
    • 8. Memory Management (1)
    • 9. Memory Management (2)
    • 10. Virtual Memory(1)
    • 11. Virtual Memory (2)
    • 12. File System
    • 13. Mass Storage Management
    • 14. I/O Systems

17. Transactions

  • Transaction
    • System's view: ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ(Data items)์— ์ ‘๊ทผํ•˜๊ณ  ๊ฐฑ์‹ ํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ๋‹จ์œ„
    • User's view: ๋…ผ๋ฆฌ์ ์ธ ์ž‘์—… ๋‹จ์œ„(Logical unit of work)
    • ์˜ˆ์‹œ
      • ์€ํ–‰: ๊ณ„์ขŒ A์—์„œ B๋กœ $50 ์ด์ฒด
      • ํ•™๊ต: ํ•™์ƒ #4321์— ๋Œ€ํ•ด ๊ฐ•์ขŒ #409.433 ๋“ฑ๋ก
      • ํšŒ์‚ฌ: ๋ชจ๋“  ์ง์›์˜ ๊ธ‰์—ฌ๋ฅผ 5% ์ธ์ƒ
  • Transaction ์˜ˆ์‹œ: "๊ณ„์ขŒ A์—์„œ ๊ณ„์ขŒ B๋กœ $50 ์ด์ฒด"
    read(A)
    A := A - 50
    write(A)
    read(B)
    B := B + 50
    write(B)
    
  • ๋‹ค๋ฃจ์–ด์•ผ ํ•  ๋‘ ๊ฐ€์ง€ ์ฃผ์š” ์ด์Šˆ
    • Hardware failure ๋ฐ system crash์™€ ๊ฐ™์€ ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜์˜ Failures
    • ๋‹ค์ˆ˜ transaction์˜ concurrent execution(๋™์‹œ ์‹คํ–‰)

Transaction concept

  • ๊ณ„์ขŒ A์—์„œ ๊ณ„์ขŒ B๋กœ $50๋ฅผ ์ด์ฒดํ•˜๋Š” transaction
    read(A)
    A := A - 50
    write(A)
    read(B)
    B := B + 50
    write(B)
    
  • Atomicity requirement (์›์ž์„ฑ ์š”๊ตฌ์‚ฌํ•ญ)
    • ๋งŒ์•ฝ transaction์ด 3๋‹จ๊ณ„ ์ดํ›„, 6๋‹จ๊ณ„ ์ด์ „์— ์‹คํŒจํ•  ๊ฒฝ์šฐ, ๋ˆ์ด "์†Œ์‹ค"๋˜์–ด Inconsistent ํ•œ database ์ƒํƒœ๊ฐ€ ๋จ
    • Failure๋Š” software ๋˜๋Š” Hardware๋กœ ์ธํ•ด ๋ฐœ์ƒ ๊ฐ€๋Šฅ
    • System์€ ๋ถ€๋ถ„์ ์œผ๋กœ ์‹คํ–‰๋œ transaction์˜ ์—…๋ฐ์ดํŠธ๊ฐ€ database์— ๋ฐ˜์˜๋˜์ง€ ์•Š๋„๋ก ๋ณด์žฅํ•ด์•ผ ํ•จ (Transaction roll back)
  • Durability requirement (์ง€์†์„ฑ ์š”๊ตฌ์‚ฌํ•ญ)
    • ์‚ฌ์šฉ์ž๊ฐ€ transaction์ด ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋Š” ํ†ต์ง€(์ฆ‰, $50 ์ด์ฒด ๋ฐœ์ƒ)๋ฅผ ๋ฐ›์€ ํ›„์—๋Š”, software ๋˜๋Š” Hardware failure๊ฐ€ ๋ฐœ์ƒํ•˜๋”๋ผ๋„ transaction์— ์˜ํ•œ database ์—…๋ฐ์ดํŠธ๊ฐ€ ์ง€์†(Persist)๋˜์–ด์•ผ ํ•จ.

Example of Fund transfer

  • Consistency requirement (์ผ๊ด€์„ฑ ์š”๊ตฌ์‚ฌํ•ญ)
    • Transaction ์‹คํ–‰์— ์˜ํ•ด A์™€ B์˜ ํ•ฉ๊ณ„๊ฐ€ ๋ณ€ํ•˜์ง€ ์•Š์•„์•ผ ํ•จ.
    • ์ผ๋ฐ˜์ ์ธ consistency requirement ํฌํ•จ ์‚ฌํ•ญ
      • Primary keys ๋ฐ Foreign keys์™€ ๊ฐ™์ด ๋ช…์‹œ์ ์œผ๋กœ ์ง€์ •๋œ Integrity constraints
      • ์•”๋ฌต์ ์ธ Integrity constraints
      • ์˜ˆ: ๋ชจ๋“  ๊ณ„์ขŒ ์ž”์•ก์˜ ํ•ฉ์—์„œ ๋Œ€์ถœ ๊ธˆ์•ก์˜ ํ•ฉ์„ ๋บ€ ๊ฐ’์€ ๋ณด์œ  ํ˜„๊ธˆ ๊ฐ€์น˜์™€ ๊ฐ™์•„์•ผ ํ•จ.
    • Transaction์€ consistent ํ•œ database๋ฅผ ํ™•์ธํ•ด์•ผ ํ•จ (Transaction ์‹คํ–‰ ์ค‘์—๋Š” database๊ฐ€ ์ผ์‹œ์ ์œผ๋กœ Inconsistent ํ•  ์ˆ˜ ์žˆ์Œ)
    • Transaction์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜๋ฉด database๋Š” consistent ํ•ด์•ผ ํ•จ.
    • ์ž˜๋ชป๋œ transaction ๋กœ์ง์€ Inconsistency๋ฅผ ์ดˆ๋ž˜ํ•  ์ˆ˜ ์žˆ์Œ.
    • ๊ฐœ๋ณ„ transaction์— ๋Œ€ํ•œ consistency ๋ณด์žฅ์€ transaction์„ ์ž‘์„ฑํ•˜๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๊ทธ๋ž˜๋จธ์˜ ์ฑ…์ž„
    • Integrity constraints์— ๋Œ€ํ•œ ์ž๋™ ํ…Œ์ŠคํŠธ(4.4์ ˆ)๊ฐ€ ์ด ์ž‘์—…์„ ์šฉ์ดํ•˜๊ฒŒ ํ•จ.
  • Isolation requirement (๊ณ ๋ฆฝ์„ฑ ์š”๊ตฌ์‚ฌํ•ญ)
    • ๋งŒ์•ฝ 3๋‹จ๊ณ„์™€ 6๋‹จ๊ณ„ ์‚ฌ์ด์—, ๋‹ค๋ฅธ transaction T2T_2T2โ€‹๊ฐ€ ๋ถ€๋ถ„์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ๋œ database์— ์ ‘๊ทผํ•˜๋„๋ก ํ—ˆ์šฉ๋œ๋‹ค๋ฉด, T2T_2T2โ€‹๋Š” Inconsistent ํ•œ database๋ฅผ ๋ณด๊ฒŒ ๋จ (A + B์˜ ํ•ฉ์ด ์›๋ž˜๋ณด๋‹ค ์ ๊ฒŒ ๋จ)
    • ์˜ˆ์‹œ ํ๋ฆ„
      • T1T_1T1โ€‹: read(A) โ†’ A := a โ€“ 50 โ†’ write(A)
      • T2T_2T2โ€‹: read(A) โ†’ read(B) โ†’ print(A + B) (์ด ์‹œ์ ์˜ ๋ฌธ์ œ)
      • T1T_1T1โ€‹: read(B) โ†’ B := B + 50 โ†’ write(B)
    • Isolation์€ transaction์„ ์ˆœ์ฐจ์ ์œผ๋กœ(Serially, ํ•˜๋‚˜์”ฉ ์ฐจ๋ก€๋กœ) ์‹คํ–‰ํ•จ์œผ๋กœ์จ ๊ฐ„๋‹จํžˆ ๋ณด์žฅ ๊ฐ€๋Šฅ
    • ๊ทธ๋Ÿฌ๋‚˜ ๋‹ค์ˆ˜์˜ transaction์„ concurrent ํ•˜๊ฒŒ(๋™์‹œ์—) ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์€ ์ƒ๋‹นํ•œ ์ด์ ์ด ์žˆ์Œ(๋‚˜์ค‘์— ํ™•์ธ)

ACID properties

  • ๋ฐ์ดํ„ฐ์˜ ๋ฌด๊ฒฐ์„ฑ(Integrity)์„ ๋ณด์กดํ•˜๊ธฐ ์œ„ํ•ด, database system์€ transaction์˜ ๋‹ค์Œ ์†์„ฑ๋“ค์„ ๋ณด์žฅํ•ด์•ผ ํ•จ.
    • Atomicity: transaction์˜ ๋ชจ๋“  ์—ฐ์‚ฐ์ด database์— ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ฐ˜์˜๋˜๊ฑฐ๋‚˜, ์ „ํ˜€ ๋ฐ˜์˜๋˜์ง€ ์•Š์Œ (All-or-nothing)
    • Consistency: ๊ณ ๋ฆฝ๋œ ์ƒํƒœ(์ฆ‰, ๋™์‹œ์— ์‹คํ–‰๋˜๋Š” ๋‹ค๋ฅธ transaction ์—†์ด)์—์„œ์˜ transaction ์‹คํ–‰์€ database์˜ consistency๋ฅผ ๋ณด์กดํ•จ (Correctness)
    • Isolation: ๋‹ค์ˆ˜์˜ transaction์ด concurrent ํ•˜๊ฒŒ ์‹คํ–‰๋  ์ˆ˜ ์žˆ์ง€๋งŒ, ๊ฐ transaction์€ ๋™์‹œ์— ์‹คํ–‰๋˜๋Š” ๋‹ค๋ฅธ transaction์„ ์ธ์ง€ํ•˜์ง€ ๋ชปํ•ด์•ผ ํ•จ.
      • ์ค‘๊ฐ„ ๋‹จ๊ณ„์˜ transaction ๊ฒฐ๊ณผ๋Š” ๋™์‹œ์— ์‹คํ–‰๋˜๋Š” ๋‹ค๋ฅธ transaction์—๊ฒŒ ์ˆจ๊ฒจ์ ธ์•ผ ํ•จ.
      • ์ฆ‰, ๋ชจ๋“  transaction ์Œ TiT_iTiโ€‹์™€ TjT_jTjโ€‹์— ๋Œ€ํ•ด, TiT_iTiโ€‹์—๊ฒŒ๋Š” TjT_jTjโ€‹๊ฐ€ TiT_iTiโ€‹ ์‹œ์ž‘ ์ „์— ์‹คํ–‰์„ ๋งˆ์ณค๊ฑฐ๋‚˜, TiT_iTiโ€‹๊ฐ€ ๋๋‚œ ํ›„์— ์‹คํ–‰์„ ์‹œ์ž‘ํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์—ฌ์•ผ ํ•จ.
    • Durability: transaction์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋œ ํ›„์—๋Š”, system failure๊ฐ€ ์žˆ๋”๋ผ๋„ database์— ์ˆ˜ํ–‰ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์ง€์†๋จ

Transaction state

  • Transaction์€ ๋‹ค์Œ ์ƒํƒœ ์ค‘ ํ•˜๋‚˜์—ฌ์•ผ ํ•จ.
    • Active: ์ดˆ๊ธฐ ์ƒํƒœ; transaction์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ ์ด ์ƒํƒœ ์œ ์ง€
    • Partially committed: ๋งˆ์ง€๋ง‰ ๋ช…๋ น๋ฌธ์ด ์‹คํ–‰๋œ ์งํ›„
    • Failed: ์ •์ƒ์ ์ธ ์‹คํ–‰์ด ๋” ์ด์ƒ ์ง„ํ–‰๋  ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒƒ์ด ๋ฐœ๊ฒฌ๋œ ํ›„
    • Aborted: transaction์ด roll back ๋˜๊ณ  database๊ฐ€ transaction ์‹œ์ž‘ ์ „ ์ƒํƒœ๋กœ ๋ณต์›๋œ ํ›„. aborted ๋œ ํ›„ ๋‘ ๊ฐ€์ง€ ์˜ต์…˜ ์กด์žฌ:
      • Transaction ์žฌ์‹œ์ž‘(Restart): ๋‚ด๋ถ€์ ์ธ ๋…ผ๋ฆฌ ์˜ค๋ฅ˜๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ์—๋งŒ ๊ฐ€๋Šฅ
      • Transaction ๊ฐ•์ œ ์ข…๋ฃŒ(Kill)
    • Committed: ์„ฑ๊ณต์ ์ธ ์™„๋ฃŒ ํ›„

Transaction atomicity and durability

  • Transaction์ด committed ๋˜๋Š” aborted ๋˜๋ฉด ์ข…๋ฃŒ(Terminated)๋œ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ
  • Committed ๋œ ๊ฒฝ์šฐ, durability๊ฐ€ ์ค‘์š”
    • Database์— ๋Œ€ํ•œ transaction์˜ ํšจ๊ณผ๋Š” durableํ•˜๊ณ  ๊ณต๊ฐœ์ ์ด์–ด์•ผ ํ•จ.
    • ์ด๋ฅผ ์œ„ํ•ด Partially committed ์ƒํƒœ ๋„์ž… ํ•„์š”
    • ๋งˆ์ง€๋ง‰ ๋ช…๋ น๋ฌธ์„ ์‹คํ–‰ํ•œ ํ›„์—๋„, ์‹ค์ œ ์ถœ๋ ฅ์€ Main memory(์ฆ‰, Buffer)์— ๋‚จ์•„ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, Hardware failure ์‹œ ์†์‹ค๋  ์ˆ˜ ์žˆ์Œ.
    • (Recovery๋ฅผ ์œ„ํ•œ) ์ถฉ๋ถ„ํ•œ ์ •๋ณด๋ฅผ disk์— ๊ธฐ๋กํ•œ ํ›„์—์•ผ transaction์€ Committed ์ƒํƒœ๋กœ ์ง„์ž…. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด Failed ํ›„ Abort ์ƒํƒœ๋กœ ์ง„์ž…
    • Failure๊ฐ€ ๋ฐœ์ƒํ•˜๋”๋ผ๋„, system์ด ์žฌ์‹œ์ž‘๋  ๋•Œ ํ•ด๋‹น ์ •๋ณด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ transaction์ด ์ˆ˜ํ–‰ํ•œ ์—…๋ฐ์ดํŠธ๋ฅผ ์žฌ์ƒ์„ฑ ๊ฐ€๋Šฅ
  • Aborted ๋œ ๊ฒฝ์šฐ, atomicity๊ฐ€ ์ค‘์š”
    • Aborted transaction์€ database ์ƒํƒœ์— ์•„๋ฌด๋Ÿฐ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์•„์•ผ ํ•จ.
    • Transaction์— ์˜ํ•ด ์ˆ˜ํ–‰๋œ database์˜ ๋ชจ๋“  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์€ ์ทจ์†Œ(Undone)๋˜์–ด์•ผ ํ•จ.
    • ์ทจ์†Œ(Undone)๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด, aborted transaction์€ roll back ๋˜์—ˆ๋‹ค๊ณ  ํ•จ.
    • Transaction abort๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์€ recovery scheme์˜ ์ฑ…์ž„
    • ์ผ๋ฐ˜์ ์œผ๋กœ Log๋ฅผ ์œ ์ง€ํ•จ์œผ๋กœ์จ ์ˆ˜ํ–‰
    • ์ž์„ธํ•œ ๋‚ด์šฉ์€ chapter 19 (Recovery systems) ์ฐธ์กฐ

Transaction Isolation

  • System์—์„œ ๋‹ค์ˆ˜์˜ transaction์ด concurrent ํ•˜๊ฒŒ ์‹คํ–‰๋˜๋Š” ๊ฒƒ์ด ํ—ˆ์šฉ๋จ. ์žฅ์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Œ:
    • CPU ๋ฐ disk ํ™œ์šฉ๋„(Utilization) ์ฆ๊ฐ€๋กœ ๋” ๋‚˜์€ transaction throughput ๋„์ถœ
      • ์˜ˆ: ํ•œ transaction์ด cPU๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋™์•ˆ ๋‹ค๋ฅธ transaction์€ disk์—์„œ ์ฝ๊ฑฐ๋‚˜ ์“ธ ์ˆ˜ ์žˆ์Œ.
    • Transaction์˜ ํ‰๊ท  ์‘๋‹ต ์‹œ๊ฐ„(Response time) ๋‹จ์ถ•: ์งง์€ transaction์ด ๊ธด transaction ๋’ค์—์„œ ๊ธฐ๋‹ค๋ฆด ํ•„์š” ์—†์Œ.
  • Concurrency control schemes: Isolation์„ ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ฉ”์ปค๋‹ˆ์ฆ˜
    • ์ฆ‰, concurrent transaction๋“ค์ด database์˜ consistency๋ฅผ ํŒŒ๊ดดํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๊ทธ๋“ค ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ์ œ์–ดํ•จ.
    • ์ด๋ฒˆ chapter์—์„œ concurrent execution์˜ correctness ๊ฐœ๋…์„ ํ•™์Šตํ•œ ํ›„, chapter 18 (Concurrency control)์—์„œ ํ•™์Šต ์˜ˆ์ •

Schedules

  • Schedule
    • Concurrent transaction๋“ค์˜ ๋ช…๋ น์–ด๋“ค์ด ์‹คํ–‰๋˜๋Š” ์‹œ๊ฐ„์  ์ˆœ์„œ๋ฅผ ๋ช…์‹œํ•˜๋Š” ๋ช…๋ น์–ด ์‹œํ€€์Šค
    • ์ผ๋ จ์˜ transaction๋“ค์— ๋Œ€ํ•œ schedule์€ ํ•ด๋‹น transaction๋“ค์˜ ๋ชจ๋“  ๋ช…๋ น์–ด๋กœ ๊ตฌ์„ฑ๋˜์–ด์•ผ ํ•จ.
    • ๊ฐ ๊ฐœ๋ณ„ transaction ๋‚ด์— ๋‚˜ํƒ€๋‚˜๋Š” ๋ช…๋ น์–ด๋“ค์˜ ์ˆœ์„œ๋Š” ๋ณด์กด๋˜์–ด์•ผ ํ•จ.
  • ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰์„ ์™„๋ฃŒํ•œ transaction์€ ๋งˆ์ง€๋ง‰ ๋ฌธ์žฅ์œผ๋กœ commit ๋ช…๋ น์–ด๋ฅผ ๊ฐ€์ง
    • ๊ธฐ๋ณธ์ ์œผ๋กœ, transaction์€ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„๋กœ commit ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค๊ณ  ๊ฐ€์ •
  • ์‹คํ–‰ ์™„๋ฃŒ์— ์‹คํŒจํ•œ transaction์€ ๋งˆ์ง€๋ง‰ ๋ฌธ์žฅ์œผ๋กœ abort ๋ช…๋ น์–ด๋ฅผ ๊ฐ€์ง
  • T1T_1T1โ€‹์ด A์—์„œ B๋กœ $50 ์ด์ฒด, T2T_2T2โ€‹๊ฐ€ A์—์„œ B๋กœ ์ž”์•ก์˜ 10%๋ฅผ ์ด์ฒดํ•œ๋‹ค๊ณ  ๊ฐ€์ •
  • Schedule 1: T1T_1T1โ€‹ ๋’ค์— T2T_2T2โ€‹๊ฐ€ ๋”ฐ๋ฅด๋Š” serial schedule
  • Schedule 2: T2T_2T2โ€‹ ๋’ค์— T1T_1T1โ€‹์ด ๋”ฐ๋ฅด๋Š” serial schedule
  • Schedule 3: schedule 1๊ณผ ๋™์ผํ•œ ํšจ๊ณผ๋ฅผ ๊ฐ–๋Š”(Equivalent) concurrent schedule
  • Schedule 4: Inconsistent state๋ฅผ ์ดˆ๋ž˜ํ•˜๋Š” concurrent schedule
    • Schedule 1, ~2, ~3์—์„œ๋Š” ํ•ฉ๊ณ„ A + B๊ฐ€ ๋ณด์กด๋˜์ง€๋งŒ, schedule 4์—์„œ๋Š” ๋ณด์กด๋˜์ง€ ์•Š์Œ.

Serializability

  • ๊ธฐ๋ณธ ๊ฐ€์ •(Basic assumption): ๊ฐ transaction์€ database consistency๋ฅผ ๋ณด์กดํ•จ.
    • ๋”ฐ๋ผ์„œ, ์ผ๋ จ์˜ transaction๋“ค์˜ serial execution(์ˆœ์ฐจ ์‹คํ–‰)์€ database consistency๋ฅผ ๋ณด์กดํ•จ.
  • Concurrent execution ํ•˜์—์„œ๋„ database์˜ consistency ๋ณด์žฅ ๊ฐ€๋Šฅ
    • ์‹คํ–‰๋˜๋Š” ๋ชจ๋“  schedule์ด concurrent execution ์—†์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” schedule๊ณผ ๋™์ผํ•œ ํšจ๊ณผ๋ฅผ ๊ฐ–๋„๋ก ํ•จ์œผ๋กœ์จ ๋‹ฌ์„ฑ
    • ์ฆ‰, schedule์€ serial schedule๊ณผ ๋“ฑ๊ฐ€(Equivalent)์—ฌ์•ผ ํ•จ.
  • (Concurrent ํ•  ์ˆ˜ ์žˆ๋Š”) ์–ด๋–ค schedule์ด serial schedule๊ณผ Equivalent ํ•˜๋‹ค๋ฉด, ์ด๋ฅผ serializableํ•˜๋‹ค๊ณ  ํ•จ.
  • Schedule์˜ serializability๋ฅผ ์–ด๋–ป๊ฒŒ ๊ฒฐ์ •ํ•˜๋Š”๊ฐ€?
    • Schedule equivalence์˜ ๋‹ค์–‘ํ•œ ํ˜•ํƒœ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐœ๋…๋“ค์„ ๋ฐœ์ƒ์‹œํ‚ด
      1. Conflict serializability
      2. View serializability (๋†’์€ ๋ณต์žก๋„๋กœ ์ธํ•ด ์‹ค์ œ๋กœ๋Š” ์‚ฌ์šฉ๋˜์ง€ ์•Š์Œ)
  • Transaction์˜ ๋‹จ์ˆœํ™”๋œ ๊ด€์ 
    • ๋‹จ์ˆœํ™”๋œ schedule์€ read์™€ write ๋ช…๋ น์–ด๋“ค๋กœ๋งŒ ๊ตฌ์„ฑ๋จ
    • ๋‹จ, transaction์€ read์™€ write ์‚ฌ์ด์— Local buffer์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•ด ์ž„์˜์˜ ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •

Conflicting Instructions

  • Transaction TiT_iTiโ€‹์™€ TjT_jTjโ€‹์˜ ๋ช…๋ น์–ด lil_iliโ€‹์™€ ljl_jljโ€‹๋Š” ๋‹ค์Œ ์กฐ๊ฑด์—์„œ ์ถฉ๋Œ(Conflict)ํ•จ.
    • lil_iliโ€‹์™€ ljl_jljโ€‹๊ฐ€ ๋ชจ๋‘ ์ ‘๊ทผํ•˜๋Š” ์–ด๋–ค ํ•ญ๋ชฉ Q๊ฐ€ ์กด์žฌํ•˜๊ณ ,
    • ์ด ๋ช…๋ น์–ด๋“ค ์ค‘ ์ ์–ด๋„ ํ•˜๋‚˜๋Š” write ์—ฐ์‚ฐ์ž„
      1. li=read(Q),ย lj=read(Q)l_i = read(Q), ~l_j = read(Q)liโ€‹=read(Q),ย ljโ€‹=read(Q): lil_iliโ€‹์™€ ljl_jljโ€‹๋Š” conflict ํ•˜์ง€ ์•Š์Œ.
      2. li=read(Q),ย lj=write(Q)l_i = read(Q), ~l_j = write(Q)liโ€‹=read(Q),ย ljโ€‹=write(Q): conflict ํ•จ.
      3. li=write(Q),ย lj=read(Q)l_i = write(Q), ~l_j = read(Q)liโ€‹=write(Q),ย ljโ€‹=read(Q): conflict ํ•จ.
      4. li=write(Q),ย lj=write(Q)l_i = write(Q), ~l_j = write(Q)liโ€‹=write(Q),ย ljโ€‹=write(Q): conflict ํ•จ.
  • lil_iliโ€‹์™€ ljl_jljโ€‹ ์‚ฌ์ด์˜ conflict๋Š” ๊ทธ๋“ค ์‚ฌ์ด์— (๋…ผ๋ฆฌ์ ์ธ) ์‹œ๊ฐ„์  ์ˆœ์„œ๋ฅผ ๊ฐ•์ œํ•จ.
    • ์ฆ‰, ์‹คํ–‰ ์ˆœ์„œ๊ฐ€ ์ค‘์š”ํ•˜๋ฉฐ ์ˆœ์„œ๋ฅผ ๋ฐ”๊พธ๋Š”(Swapping) ๊ฒƒ์ด ํ—ˆ์šฉ๋˜์ง€ ์•Š์Œ.
  • ๋งŒ์•ฝ lil_iliโ€‹์™€ ljl_jljโ€‹๊ฐ€ schedule ๋‚ด์—์„œ ์—ฐ์†์ ์ด๊ณ  ์„œ๋กœ conflict ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด, schedule ๋‚ด์—์„œ ์œ„์น˜๋ฅผ ์„œ๋กœ ๋ฐ”๊พธ๋”๋ผ๋„ ๊ฒฐ๊ณผ๋Š” ๋™์ผํ•˜๊ฒŒ ์œ ์ง€๋จ

Conflict serializability

  • ๋งŒ์•ฝ schedule S๊ฐ€ non-conflicting ๋ช…๋ น์–ด๋“ค์˜ ์ผ๋ จ์˜ swap์„ ํ†ตํ•ด schedule S'๋กœ ๋ณ€ํ™˜๋  ์ˆ˜ ์žˆ๋‹ค๋ฉด, S์™€ S'๋Š” conflict equivalent ํ•˜๋‹ค๊ณ  ํ•จ.
  • ์–ด๋–ค schedule S๊ฐ€ serial schedule๊ณผ conflict equivalent ํ•˜๋‹ค๋ฉด, ๊ทธ schedule S๋Š” conflict serializableํ•˜๋‹ค๊ณ  ํ•จ.
    • Schedule 3์€ non-conflicting ๋ช…๋ น์–ด๋“ค์˜ ์ผ๋ จ์˜ swap์„ ํ†ตํ•ด T1T_1T1โ€‹ ๋’ค์— T2T_2T2โ€‹๊ฐ€ ๋”ฐ๋ฅด๋Š” serial schedule์ธ schedule 6๋กœ ๋ณ€ํ™˜๋  ์ˆ˜ ์žˆ์Œ.
    • ๋”ฐ๋ผ์„œ schedule 3์€ conflict serializable ํ•จ.
  • Conflict serializableํ•˜์ง€ ์•Š์€ schedule์˜ ์˜ˆ์‹œ:
    • ์œ„ schedule์—์„œ๋Š” ๋ช…๋ น์–ด๋ฅผ swap ํ•˜์—ฌ serial schedule <T3,ย T4>< T_3, ~T_4 ><T3โ€‹,ย T4โ€‹> ๋˜๋Š” serial schedule <T4,ย T3>< T_4, ~T_3 ><T4โ€‹,ย T3โ€‹>๋ฅผ ์–ป์„ ์ˆ˜ ์—†์Œ.

Testing for conflict serializability

  • ์ผ๋ จ์˜ transaction {T1,ย T2,ย ...,ย Tn}\{T_1, ~T_2, ~..., ~T_n\}{T1โ€‹,ย T2โ€‹,ย ...,ย Tnโ€‹}์— ๋Œ€ํ•œ schedule ๊ณ ๋ ค
  • Precedence graph (์šฐ์„ ์ˆœ์œ„ ๊ทธ๋ž˜ํ”„)
    • ์ •์ (Vertices)์ด transaction์ธ ๋ฐฉํ–ฅ์„ฑ ๊ทธ๋ž˜ํ”„(Directed graph)
    • TiT_iTiโ€‹์—์„œ TjT_jTjโ€‹๋กœ์˜ arc(ํ™”์‚ดํ‘œ)๋ฅผ ๊ทธ๋ฆฌ๋Š” ์กฐ๊ฑด:
      • ๋‘ transaction์ด conflict ํ•˜๊ณ , TiT_iTiโ€‹๊ฐ€ conflict๊ฐ€ ๋ฐœ์ƒํ•œ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์— TjT_jTjโ€‹๋ณด๋‹ค ๋จผ์ € ์ ‘๊ทผํ•œ ๊ฒฝ์šฐ
      • ์ฆ‰, ๋‹ค์Œ ์„ธ ๊ฐ€์ง€ ์กฐ๊ฑด ์ค‘ ํ•˜๋‚˜๊ฐ€ ์„ฑ๋ฆฝํ•  ๋•Œ:
        • TiT_iTiโ€‹๊ฐ€ TjT_jTjโ€‹์˜ read(Q) ์‹คํ–‰ ์ „์— write(Q) ์‹คํ–‰
        • TiT_iTiโ€‹๊ฐ€ TjT_jTjโ€‹์˜ write(Q) ์‹คํ–‰ ์ „์— read(Q) ์‹คํ–‰
        • TiT_iTiโ€‹๊ฐ€ TjT_jTjโ€‹์˜ write(Q) ์‹คํ–‰ ์ „์— write(Q) ์‹คํ–‰
    • ์ ‘๊ทผ๋œ ํ•ญ๋ชฉ์œผ๋กœ arc์— ๋ผ๋ฒจ์„ ๋ถ™์ผ ์ˆ˜ ์žˆ์Œ.
  • Precedence graph์— Tiโ†’TjT_i \to T_jTiโ€‹โ†’Tjโ€‹ Edge๊ฐ€ ์กด์žฌํ•˜๋ฉด, S์™€ Equivalent ํ•œ ์–ด๋–ค serial schedule S'์—์„œ๋„ TiT_iTiโ€‹๋Š” ๋ฐ˜๋“œ์‹œ TjT_jTjโ€‹๋ณด๋‹ค ๋จผ์ € ๋‚˜ํƒ€๋‚˜์•ผ ํ•จ.
  • Schedule์€ precedence graph๊ฐ€ acyclic(์‚ฌ์ดํด์ด ์—†์Œ)์ธ ๊ฒฝ์šฐ์—๋งŒ conflict serializable ํ•จ.
  • Cycle-detection ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ O(n2)O(n^2)O(n2) ์‹œ๊ฐ„์ด ์†Œ์š”๋จ (nnn์€ ๊ทธ๋ž˜ํ”„์˜ ์ •์  ์ˆ˜)
    • ๋” ๋‚˜์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ O(n+e)O(n + e)O(n+e) ์†Œ์š” (eee๋Š” Edge์˜ ์ˆ˜)
  • Precedence graph๊ฐ€ acyclic ์ด๋ฉด, serializability order๋Š” ๊ทธ๋ž˜ํ”„์˜ topological sorting(์œ„์ƒ ์ •๋ ฌ)์„ ํ†ตํ•ด ์–ป์„ ์ˆ˜ ์žˆ์Œ.
    • ์ด๋Š” ๊ทธ๋ž˜ํ”„์˜ partial order(๋ถ€๋ถ„ ์ˆœ์„œ)์™€ ์ผ์น˜ํ•˜๋Š” Linear order(์„ ํ˜• ์ˆœ์„œ)์ž„
    • Topological sorting์„ ํ†ตํ•ด ์—ฌ๋Ÿฌ ๊ฐœ์˜ Linear order๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Œ.
    • (b)์™€ (c)๋Š” (a)์˜ topological sorting์œผ๋กœ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ๋‘ ๊ฐ€์ง€ Linear order

Example schedule (Schedule A)

alt text

Recoverable schedules

  • Concurrently ์‹คํ–‰๋˜๋Š” transaction๋“ค์— ๋Œ€ํ•œ transaction failure์˜ ์˜ํ–ฅ
    • Transaction TiT_iTiโ€‹๊ฐ€ ์‹คํŒจํ•  ๋•Œ:
      • Serial execution๋งŒ ํ—ˆ์šฉ๋œ ๊ฒฝ์šฐ: TiT_iTiโ€‹์— ์˜ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ทจ์†Œ(Undoing)ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์ถฉ๋ถ„
      • Concurrent execution์ด ํ—ˆ์šฉ๋œ ๊ฒฝ์šฐ: atomicity ์†์„ฑ์€ TiT_iTiโ€‹์— ์˜์กด์ ์ธ(์˜ˆ: TiT_iTiโ€‹๊ฐ€ ์ž‘์„ฑํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์€) ๋ชจ๋“  transaction TjT_jTjโ€‹ ๋˜ํ•œ abort ๋  ๊ฒƒ์„ ์š”๊ตฌํ•จ.
    • Concurrent system์—์„œ ํ—ˆ์šฉ๋˜๋Š” schedule ์œ ํ˜•์— ์ œํ•œ์„ ๋‘˜ ํ•„์š”๊ฐ€ ์žˆ์Œ.
  • Recoverable schedule
    • ๋งŒ์•ฝ transaction TjT_jTjโ€‹๊ฐ€ transaction TiT_iTiโ€‹์— ์˜ํ•ด ์ด์ „์— ์“ฐ์—ฌ์ง„ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์„ ์ฝ๋Š”๋‹ค๋ฉด, TiT_iTiโ€‹์˜ commit ์—ฐ์‚ฐ์ด TjT_jTjโ€‹์˜ commit ์—ฐ์‚ฐ๋ณด๋‹ค ๋จผ์ € ๋‚˜ํƒ€๋‚˜์•ผ ํ•จ.
    • Schedule 11์€ recoverableํ•˜์ง€ ์•Š์Œ:
      • ๋งŒ์•ฝ T8T_8T8โ€‹์ด abort ํ•ด์•ผ ํ•œ๋‹ค๋ฉด, T9T_9T9โ€‹๋Š” ์ด๋ฏธ Inconsistent ํ•œ database ์ƒํƒœ๋ฅผ ์ฝ์—ˆ์Œ(๊ทธ๋ฆฌ๊ณ  ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ฃผ์—ˆ์„ ๊ฐ€๋Šฅ์„ฑ ์žˆ์Œ)
    • ๋”ฐ๋ผ์„œ, database๋Š” schedule์ด recoverableํ•˜๋„๋ก ๋ณด์žฅํ•ด์•ผ ํ•จ.

Cascadeless schedules

  • Cascading rollback
    • ๋‹จ์ผ transaction failure๊ฐ€ ์ผ๋ จ์˜ transaction rollback์„ ์œ ๋ฐœํ•˜๋Š” ํ˜„์ƒ
    • Schedule 10์„ ๊ณ ๋ คํ•  ๋•Œ, ์•„์ง ์–ด๋–ค transaction๋„ commit ํ•˜์ง€ ์•Š์Œ (๋”ฐ๋ผ์„œ recoverable ํ•จ)
    • ๋งŒ์•ฝ T10T_{10}T10โ€‹์ด ์‹คํŒจํ•˜๋ฉด, T11T_{11}T11โ€‹๊ณผ T12T_{12}T12โ€‹๋„ ๋ฐ˜๋“œ์‹œ roll back ๋˜์–ด์•ผ ํ•จ.
      • Schedule 10์€ partial schedule๋กœ, schedule ๋‚ด์˜ ์ ์–ด๋„ ํ•˜๋‚˜์˜ transaction์ด commit ๋˜๋Š” abort ์—ฐ์‚ฐ์„ ๊ฐ–์ง€ ์•Š์Œ.
    • Cascading rollback์€ ์ƒ๋‹นํ•œ ์–‘์˜ ์ž‘์—…์„ ์ทจ์†Œ(Undoing)ํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ฐ”๋žŒ์งํ•˜์ง€ ์•Š์Œ.
  • Cascadeless schedules
    • TiT_iTiโ€‹์— ์˜ํ•ด ์ด์ „์— ์“ฐ์—ฌ์ง„ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์„ ์ฝ๋Š” ๋ชจ๋“  transaction ์Œ TiT_iTiโ€‹์™€ TjT_jTjโ€‹์— ๋Œ€ํ•ด, TiT_iTiโ€‹์˜ commit ์—ฐ์‚ฐ์ด TjT_jTjโ€‹์˜ read ์—ฐ์‚ฐ๋ณด๋‹ค ๋จผ์ € ๋‚˜ํƒ€๋‚˜์•ผ ํ•จ.
    • Cascading rollback์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์—†์Œ.
    • ๋ชจ๋“  cascadeless schedule์€ ๋˜ํ•œ recoverable ํ•จ.
    • Schedule์„ cascadeless ํ•œ ๊ฒƒ๋“ค๋กœ ์ œํ•œํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋žŒ์งํ•จ.

Concurrency control

  • Database system์€ ๋ชจ๋“  schedule์ด ๋‹ค์Œ์„ ๋งŒ์กฑํ•˜๋„๋ก ๋ณด์žฅํ•˜๋Š” ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ์ œ๊ณตํ•ด์•ผ ํ•จ.
    • Database consistency๋ฅผ ์œ„ํ•ด conflict ๋˜๋Š” View serializableํ•˜๊ณ  recoverable ํ•ด์•ผ ํ•จ.
    • ์„ฑ๋Šฅ์„ ์œ„ํ•ด ๊ฐ€๊ธ‰์  cascadeless ํ•ด์•ผ ํ•จ.
  • ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์˜ transaction๋งŒ ์‹คํ–‰ํ•˜๋Š” ์ •์ฑ…
    • Serial schedule์„ ์ƒ์„ฑํ•˜์ง€๋งŒ, concurrency ์ •๋„(Degree)๊ฐ€ ๋‚ฎ์Œ.
  • ๋ชฉํ‘œ: concurrent schedule์„ ํ—ˆ์šฉํ•˜๋Š” concurrency control protocol ๊ฐœ๋ฐœ
    • Schedule์ด conflict ๋˜๋Š” View serializableํ•˜๋„๋ก ๋ณด์žฅ
    • ๊ทธ๋ฆฌ๊ณ  recoverableํ•˜๋ฉฐ cascadeless ํ•˜๋„๋ก ๋ณด์žฅ
  • Concurrency ์ •๋„(Degree)์™€ ์˜ค๋ฒ„ํ—ค๋“œ(Overhead) ๊ฐ„์˜ tradeoff
    • ์„œ๋กœ ๋‹ค๋ฅธ concurrency control protocol์€ ์„œ๋กœ ๋‹ค๋ฅธ tradeoff ์ œ๊ณต:
      • ์–ด๋–ค ๊ธฐ๋ฒ•์€ conflict-serializable schedule๋งŒ ์ƒ์„ฑ๋˜๋„๋ก ํ—ˆ์šฉํ•˜๋Š” ๋ฐ˜๋ฉด, ๋‹ค๋ฅธ ๊ธฐ๋ฒ•์€ conflict-serializableํ•˜์ง€ ์•Š์€ View-serializable schedule๋„ ํ—ˆ์šฉ
  • ์ผ๋ฐ˜์ ์œผ๋กœ concurrency control protocol์€
    • Precedence graph๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ๋™์•ˆ์—๋Š” ์ด๋ฅผ ๊ฒ€์‚ฌํ•˜์ง€ ์•Š์Œ.
    • ๋Œ€์‹ , protocol์€ non-serializable schedule์„ ํšŒํ”ผํ•˜๋Š” ๊ทœ์œจ(Discipline)์„ ๋ถ€๊ณผํ•จ (์„ธ๋ถ€ ์‚ฌํ•ญ์€ chapter 18 ์ฐธ์กฐ)

Weak Levels of consistency

  • ์ผ๋ถ€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ serializableํ•˜์ง€ ์•Š์€ schedule์„ ํ—ˆ์šฉํ•˜๋ฉด์„œ ์•ฝํ•œ ์ˆ˜์ค€์˜ consistency๋ฅผ ๊ฐ์ˆ˜ํ•จ.
  • ๋‚ฎ์€ ์ˆ˜์ค€์˜ consistency๋Š” database์— ๋Œ€ํ•œ ๋Œ€๋žต์ ์ธ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•˜๋Š” ๋ฐ ์œ ์šฉ
    • ์˜ˆ: ๋ชจ๋“  ๊ณ„์ขŒ์˜ ๋Œ€๋žต์ ์ธ ์ด ์ž”์•ก์„ ๊ตฌํ•˜๋Š” read-only transaction
    • ์˜ˆ: query optimization์„ ์œ„ํ•ด ๊ณ„์‚ฐ๋œ database ํ†ต๊ณ„๋Š” ๋Œ€๋žต์ ์ผ ์ˆ˜ ์žˆ์Œ.
    • ์ด๋Ÿฌํ•œ transaction์€ ๋‹ค๋ฅธ transaction์— ๋Œ€ํ•ด serializable ํ•  ํ•„์š”๊ฐ€ ์—†์Œ.
    • โ†’\rightarrowโ†’ ์ •ํ™•์„ฑ(Accuracy)๊ณผ ์„ฑ๋Šฅ(Performance)์˜ tradeoff
  • ์ผ๋ถ€ database system์€ ๊ธฐ๋ณธ์ ์œผ๋กœ serializable schedule์„ ๋ณด์žฅํ•˜์ง€ ์•Š์Œ.
    • ์˜ˆ: Oracle(๋ฐ ๋ฒ„์ „ 9 ์ด์ „์˜ postgreSQL)์€ ๊ธฐ๋ณธ์ ์œผ๋กœ snapshot isolation์ด๋ผ๋Š” consistency level ์ง€์› (SQL ํ‘œ์ค€์˜ ์ผ๋ถ€๋Š” ์•„๋‹˜)

Levels of consistency in SQL-92

  • SQL ํ‘œ์ค€์€ transaction์ด ๋‹ค๋ฅธ transaction์— ๋Œ€ํ•ด nonserializableํ•˜๊ฒŒ ์‹คํ–‰๋  ์ˆ˜ ์žˆ์Œ์„ ๋ช…์‹œํ•˜๋„๋ก ํ—ˆ์šฉ
  • SQL-92 ํ‘œ์ค€์— ๋ช…์‹œ๋œ Isolation levels:
    • SERIALIZABLE
      • ๋ณดํ†ต serializable execution ๋ณด์žฅ
      • ์ผ๋ถ€ system์€ ํŠน์ • ๊ฒฝ์šฐ์— nonseriablizable execution์„ ํ—ˆ์šฉํ•˜๋„๋ก ๊ตฌํ˜„ํ•˜๊ธฐ๋„ ํ•จ.
    • REPEATABLE rEAD
      • Committed data๋งŒ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ํ—ˆ์šฉํ•˜๋ฉฐ, ์ถ”๊ฐ€์ ์œผ๋กœ transaction ๋‚ด์—์„œ ๋ฐ์ดํ„ฐ ํ•ญ๋ชฉ์„ ๋‘ ๋ฒˆ ์ฝ์„ ๋•Œ, ๋‹ค๋ฅธ transaction์ด ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์—†๋„๋ก ์š”๊ตฌํ•จ.
      • ์ฆ‰, ๋™์ผํ•œ ๋ ˆ์ฝ”๋“œ์˜ ๋ฐ˜๋ณต ์ฝ๊ธฐ๋Š” ๋ฐ˜๋“œ์‹œ ๊ฐ™์€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ด์•ผ ํ•จ.
      • ๊ทธ๋Ÿฌ๋‚˜ transaction์€ ๋‹ค๋ฅธ transaction์— ๋Œ€ํ•ด serializableํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ.
    • READ cOMMITTED: committed data๋งŒ ์ฝ์„ ์ˆ˜ ์žˆ๋„๋ก ํ—ˆ์šฉํ•˜์ง€๋งŒ, repeatable read๋Š” ์š”๊ตฌํ•˜์ง€ ์•Š์Œ โ†’\rightarrowโ†’ ์—ฐ์†์ ์ธ ์ฝ๊ธฐ๊ฐ€ ์„œ๋กœ ๋‹ค๋ฅธ(ํ•˜์ง€๋งŒ committed ๋œ) ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•  ์ˆ˜ ์žˆ์Œ.
    • READ UNCOMMITTED: Uncommitted data๊นŒ์ง€ ์ฝ์„ ์ˆ˜ ์žˆ์Œ (๊ฐ€์žฅ ๋‚ฎ์€ Isolation level)

(Optional) transaction definition in SQL

  • SQL์—์„œ transaction์€ ์•”์‹œ์ ์œผ๋กœ ์‹œ์ž‘๋จ
  • SQL์—์„œ transaction์€ ๋‹ค์Œ์„ ํ†ตํ•ด ์ข…๋ฃŒ๋จ:
    • Commit work: ํ˜„์žฌ transaction์„ commit ํ•˜๊ณ  ์ƒˆ๋กœ์šด transaction ์‹œ์ž‘
    • Rollback work: ํ˜„์žฌ transaction์„ abort ์‹œํ‚ด
  • ๊ฑฐ์˜ ๋ชจ๋“  database system์—์„œ, ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  SQL ๋ฌธ์€ ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰๋˜๋ฉด ์•”์‹œ์ ์œผ๋กœ commit ๋จ (Automatic commit)
    • ์—ฌ๋Ÿฌ ๋ฌธ์žฅ์„ ํ•˜๋‚˜์˜ transaction์œผ๋กœ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์ด๋ฅผ ๊บผ์•ผ(Turn off) ํ•จ.
  • Automatic commit์ด ๋น„ํ™œ์„ฑํ™”๋œ ๊ฒฝ์šฐ, start transaction ๋ถ€ํ„ฐ commit(๋˜๋Š” rollback)๊นŒ์ง€๊ฐ€ ํ•˜๋‚˜์˜ ๋‹จ์ผ transaction์œผ๋กœ ์‹๋ณ„๋จ (๋ช…๋ น์–ด ์ด๋ฆ„์€ system๋งˆ๋‹ค ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Œ)
  • Isolation level์€ database ์ˆ˜์ค€์—์„œ ์„ค์ • ๊ฐ€๋Šฅ
  • Isolation level์€ transaction ์‹œ์ž‘ ์‹œ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ
    • ์˜ˆ: SQL์—์„œ set transaction isolation level serializable

(Optional) transactions as SQL statements

  • ์˜ˆ์‹œ
    • T1T_1T1โ€‹: select ID, name from instructor where salary > 90000;
    • T2T_2T2โ€‹: insert into instructor values ('11111', 'James', 'Marketing', 100000);
  • ๊ฐ€์ •
    • T1T_1T1โ€‹์ด ์‹œ์ž‘๋˜์–ด Index๋ฅผ ์‚ฌ์šฉํ•ด (salary > 90000)์ธ tuple์„ ์ฐพ์•„ Lock์„ ๊ฒ€
    • ๊ฑฐ์˜ ๊ฐ™์€ ์‹œ๊ฐ„์—, T2T_2T2โ€‹๊ฐ€ ์ƒˆ๋กœ์šด tuple์„ ์‚ฝ์ž… (salary > 90000 ์กฐ๊ฑด ๋งŒ์กฑ)
  • ์ด๋•Œ T1T_1T1โ€‹๊ณผ T2T_2T2โ€‹๋Š” conflict ํ•˜๋Š”๊ฐ€?
    • ์ง๊ด€์ ์œผ๋กœ๋Š” conflict ํ•จ์ด ๋ช…ํ™•ํ•˜์ง€๋งŒ, ์šฐ๋ฆฌ์˜ ๋‹จ์ˆœํ•œ ๋ชจ๋ธ์—์„œ๋Š” ํฌ์ฐฉ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ.
    • Phantom phenomenon์˜ ์‚ฌ๋ก€: "Phantom" ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ conflict ์กด์žฌ
    • ๋งŒ์•ฝ T2T_2T2โ€‹๊ฐ€ ๋จผ์ € ์˜ค๋ฉด, T2โ†’T1T_2 \to T_1T2โ€‹โ†’T1โ€‹ Edge๊ฐ€ ์กด์žฌํ•˜๊ณ  ์ง๋ ฌํ™”๋จ(Serialized)
    • ํ•˜์ง€๋งŒ T1T_1T1โ€‹์ด ๋จผ์ € ์˜ค๋ฉด, T1T_1T1โ€‹์ด T2T_2T2โ€‹ ์ด์ „์— ์ง๋ ฌํ™”๋˜๋„๋ก ๊ฐ•์ œํ•˜๋Š” phantom data์— ๋Œ€ํ•œ ์‹ค์ œ conflict๊ฐ€ ์žˆ์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  precedence graph์— Edge๊ฐ€ ์—†์Œ.
  • ์œ„ ์˜ˆ์ œ๋Š” concurrency control์ด transaction์— ์˜ํ•ด ์ ‘๊ทผ๋˜๋Š” tuple ๋งŒ์„ ๊ณ ๋ คํ•˜๋Š” ๊ฒƒ์œผ๋กœ๋Š” ์ถฉ๋ถ„ํ•˜์ง€ ์•Š์Œ์„ ๋ณด์—ฌ์คŒ
    • Tuple์„ ์ฐพ๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์ •๋ณด(์˜ˆ: Index)๊ฐ€ Insert, delete ๋˜๋Š” Update์— ์˜ํ•ด ๊ฐฑ์‹ ๋  ์ˆ˜ ์žˆ์Œ.
    • ์˜ˆ๋ฅผ ๋“ค์–ด Locking์ด concurrency control์— ์‚ฌ์šฉ๋˜๋Š” ๊ฒฝ์šฐ, relation์˜ tuple์„ ์ถ”์ ํ•˜๋Š” ์ž๋ฃŒ ๊ตฌ์กฐ์™€ Index ๊ตฌ์กฐ ๋˜ํ•œ ์ ์ ˆํ•˜๊ฒŒ Lock ๋˜์–ด์•ผ ํ•จ.
์ตœ๊ทผ ์ˆ˜์ •: 25. 11. 30. ์˜คํ›„ 2:45
Contributors: kmbzn
Prev
16. Query Optimization
Next
18. Concurrency control

BUILT WITH

CloudflareNode.jsGitHubGitVue.jsJavaScriptVSCodenpm

All trademarks and logos are property of their respective owners.
ยฉ 2025 kmbzn ยท MIT License