トランザクション分離レベル (Transaction Isolation Levels)

トランザクション内の操作が他によるデータ変更をどのように観測するかを制御し、データ整合性と同時実行性のバランスを取ります。

分離レベルは同時実行トランザクションの相互作用を制御します。ANSI標準の4つのレベルは、READ UNCOMMITTED(ダーティリード許容)、READ COMMITTED(ダーティリード防止)、REPEATABLE READ(読み取り一貫性)、SERIALIZABLE(直列化可能)です。それぞれが同時実行性とデータ整合性のトレードオフとなります。MVCCベースのシステムはスナップショットを使用してノンブロッキング読み取りを提供します。

        graph LR
  Center["トランザクション分離レベル (Transaction Isolation Levels)"]:::main
  Rel_transaction["transaction"]:::related -.-> Center
  click Rel_transaction "/terms/transaction"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧒 5歳でもわかるように説明

Generated ELI5 content

🤓 Expert Deep Dive

Generated expert content

❓ よくある質問

What is a dirty read?

Reading data that has been modified but not yet committed by another transaction.

What is a non-repeatable read?

Reading the same data twice within a single transaction yields different results because another transaction committed changes in between.

What is a phantom read?

A new row matching a query appears in subsequent reads within the same transaction, due to inserts by other transactions.

Which isolation level prevents dirty reads?

READ COMMITTED or SERIALIZABLE (and REPEATABLE READ) prevent dirty reads.

How should I choose an isolation level?

Base the choice on the required balance between correctness guarantees and concurrency, adjusting per operation, and consider MVCC or locking behavior of your DBMS.

📚 出典