A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Isolation Level: REPEATABLE READ

College Depth 102 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
407prerequisites beneath it
See this on the map →
Concurrency Control in DatabasesIsolation Level: SERIALIZABLE→→Phantom Read Anomaly: New Rows Appearing
isolation concurrency anomalies

Core Idea

REPEATABLE READ prevents dirty reads and non-repeatable reads by holding read locks for the duration of the transaction, but allows phantom reads (new rows matching a WHERE clause).

How It's Best Learned

Demonstrate that the same query in a transaction returns the same rows, even if another session inserts new matching rows.

Explainer

You already understand that concurrency control allows multiple transactions to run simultaneously while maintaining the illusion that each runs in isolation. Different isolation levels make different tradeoffs between how much isolation you get and how much concurrency the system can support. REPEATABLE READ sits in the middle of this spectrum — it provides stronger guarantees than READ COMMITTED but weaker ones than SERIALIZABLE.

The guarantee of REPEATABLE READ is this: if your transaction reads a row, and you read that same row again later in the same transaction, you will see the same data both times. No other transaction can modify or delete that row while yours is in progress. Under READ COMMITTED, by contrast, a second read could return different values if another transaction committed a change in between — this is the non-repeatable read anomaly, and REPEATABLE READ eliminates it. The mechanism varies by database: some use read locks held for the entire transaction duration (so no one else can modify the rows you've read), while others like PostgreSQL use snapshot isolation (your transaction sees a consistent snapshot of the database as of when it began, so other transactions' changes are simply invisible to you).

The important limitation of REPEATABLE READ is that it does not prevent phantom reads. While no existing row you've read can change, a different transaction can *insert new rows* that would match your query's WHERE clause. If you run `SELECT * FROM orders WHERE customer_id = 42` twice in the same transaction, both queries return the same values for the rows they find, but the second query might return additional rows that didn't exist when the first query ran. This matters in scenarios like reporting or inventory checks where you need the set of matching rows to be stable, not just the values within individual rows. To prevent phantoms, you need SERIALIZABLE isolation, which typically adds range locks or serialization conflict detection.

In practice, REPEATABLE READ is the default isolation level in MySQL/InnoDB and a commonly chosen level in other systems. It provides a good balance: your transaction sees a consistent view of any data it has touched, which prevents most concurrency anomalies that trip up application logic, while still allowing enough concurrent access that throughput remains high. The key design question for your application is whether phantom reads matter for your use case — if you are updating individual rows based on their values, REPEATABLE READ is usually sufficient; if you are making decisions based on the entire *set* of rows matching a condition, you may need SERIALIZABLE.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Process Creation: fork() and exec() → Process Termination and Resource Cleanup → Process States and State Transitions → Threads and Concurrency → The Critical Section Problem and Race Conditions → Mutual Exclusion and Locks → Concurrency Control in Databases → Isolation Level: SERIALIZABLE → Isolation Level: REPEATABLE READ

Longest path: 103 steps · 407 total prerequisite topics

Prerequisites (2)

Leads To (1)