DELAPARRA
Index
Color
NL
Category: SQL

dirty read

Explained by Updated

What is dirty read?

dirty read: Reading data another transaction has written but NOT committed — it might be rolled back, so you read a value that never existed. A dirty read happens when one transaction reads data another transaction has changed but not committed yet. If that other transaction rolls back, the first one has seen a value that officially never existed.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about dirty read

How is dirty read used in practice?

Imagine one process lowers a stock count but then fails and rolls back. A second process that read the lowered number in between may have told a customer the product is sold out.

What should you keep in mind with dirty read?

Dirty reads only happen at the lowest isolation level, READ UNCOMMITTED. MySQL defaults to REPEATABLE READ and PostgreSQL to READ COMMITTED, both of which prevent them. So you mainly need to know about dirty reads when someone lowers the isolation level for speed. That trade-off is rarely worth it for data that drives decisions.

What does an example of dirty read look like?

-- T1 updates row, T2 reads it, T1 rolls back -- T2 saw a phantom value

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with D

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.