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

Non-Repeatable Read Anomaly

College Depth 103 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
410prerequisites beneath it
See this on the map →
Isolation Level: READ COMMITTEDDirty Read Anomaly: Reading Uncommitted Changes→→Phantom Read Anomaly: New Rows Appearing
concurrency anomalies isolation-problems

Core Idea

A non-repeatable read occurs when a transaction reads a row, another transaction modifies it, and the first transaction re-reads the same row and sees different data.

Explainer

You already understand that under READ COMMITTED isolation, a transaction only sees data that has been committed — no dirty reads. But READ COMMITTED makes a subtle promise that is weaker than many people assume: it guarantees a consistent snapshot *per statement*, not per transaction. Each SQL statement you execute within a transaction sees the latest committed data at the moment *that statement* begins. If another transaction commits a change between your first and second SELECT, your second SELECT sees the new value. This is the non-repeatable read anomaly.

Here is a concrete scenario. Suppose you are building a banking application, and transaction T1 needs to check an account balance twice during its work — first to verify the account has sufficient funds, and later to compute a transfer amount. T1 reads the balance and sees $1000. Meanwhile, transaction T2 withdraws $800 and commits. When T1 reads the balance again, it now sees $200. T1's logic assumed the balance was $1000 throughout, but the ground shifted beneath it. The read was not "repeatable" — the same query on the same row returned different results within the same transaction.

The anomaly is called "non-repeatable" because the original read cannot be repeated with the same result. This differs from a dirty read (which sees uncommitted data) and from a phantom read (which sees new rows appearing in a range query). A non-repeatable read involves a specific row that you already read, whose *value* changed because another committed transaction modified or deleted it. All three anomalies involve interference between concurrent transactions, but they target different aspects: dirty reads concern uncommitted writes, non-repeatable reads concern committed updates to existing rows, and phantoms concern committed inserts of new rows.

To prevent non-repeatable reads, you need the REPEATABLE READ isolation level or higher. Under REPEATABLE READ, each transaction sees a consistent snapshot taken at the start of the transaction (or at the start of the first statement, depending on the implementation). No matter how many times T1 reads that account balance within its transaction, it will always see the value as of its snapshot — T2's committed change is invisible until T1 commits or rolls back and starts a new transaction. The cost is reduced concurrency: in lock-based systems, shared read locks are held for the duration of the transaction rather than released after each statement, which increases the chance of blocking and deadlocks. In MVCC systems, the cost is more subtle — long-running transactions may force the database to retain old row versions longer, increasing storage overhead. The design decision is always the same tradeoff: stronger consistency guarantees versus higher concurrency and throughput.

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: READ UNCOMMITTED (Dirty Reads) → Dirty Read Anomaly: Reading Uncommitted Changes → Non-Repeatable Read Anomaly

Longest path: 104 steps · 410 total prerequisite topics

Prerequisites (2)

Leads To (1)