Challenge - 5 Problems
Read Phenomena Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What output shows a dirty read scenario?
Consider two transactions:
Transaction 1 updates a row but does not commit.
Transaction 2 reads the updated row before commit.
Which query result best illustrates the dirty read phenomenon?
Transaction 1 updates a row but does not commit.
Transaction 2 reads the updated row before commit.
Which query result best illustrates the dirty read phenomenon?
SQL
BEGIN TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE id = 1; -- no commit yet -- In parallel SELECT balance FROM accounts WHERE id = 1;
Attempts:
2 left
💡 Hint
Dirty reads happen when a transaction reads uncommitted changes from another transaction.
✗ Incorrect
A dirty read occurs when a transaction reads data that has been modified by another transaction but not yet committed. Option D describes this situation.
❓ query_result
intermediate2:00remaining
Which output best illustrates a phantom read?
Transaction 1 runs a query to count rows matching a condition.
Transaction 2 inserts a new row matching that condition and commits.
Transaction 1 runs the same query again.
What is the expected result?
Transaction 2 inserts a new row matching that condition and commits.
Transaction 1 runs the same query again.
What is the expected result?
SQL
BEGIN TRANSACTION; SELECT COUNT(*) FROM orders WHERE status = 'pending'; -- returns 5 -- In parallel INSERT INTO orders (id, status) VALUES (101, 'pending'); COMMIT; -- Back in Transaction 1 SELECT COUNT(*) FROM orders WHERE status = 'pending';
Attempts:
2 left
💡 Hint
Phantom reads happen when new rows appear in repeated queries within the same transaction.
✗ Incorrect
Phantom reads occur when a transaction re-executes a query and sees new rows inserted by another committed transaction. Here, the count changes from 5 to 6.
🧠 Conceptual
advanced2:00remaining
Which isolation level prevents dirty reads but allows phantom reads?
Choose the SQL transaction isolation level that stops dirty reads but still permits phantom reads.
Attempts:
2 left
💡 Hint
Think about which isolation level blocks reading uncommitted data but does not lock range scans.
✗ Incorrect
READ COMMITTED prevents dirty reads by only reading committed data but does not prevent phantom reads because new rows can appear in repeated queries.
📝 Syntax
advanced2:00remaining
Which SQL snippet correctly sets the isolation level to prevent phantom reads?
You want to set the transaction isolation level to SERIALIZABLE to avoid phantom reads.
Which SQL command is correct?
Which SQL command is correct?
Attempts:
2 left
💡 Hint
The correct syntax follows the pattern: SET TRANSACTION ISOLATION LEVEL ...
✗ Incorrect
Option A uses the correct standard SQL syntax to set the isolation level to SERIALIZABLE.
🔧 Debug
expert3:00remaining
Why does this transaction still experience phantom reads despite using REPEATABLE READ?
Transaction 1:
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SELECT * FROM products WHERE category = 'books';
-- returns 10 rows
Transaction 2:
INSERT INTO products (id, category) VALUES (101, 'books');
COMMIT;
Transaction 1:
SELECT * FROM products WHERE category = 'books';
-- returns 11 rows
Why does Transaction 1 see the new row?
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SELECT * FROM products WHERE category = 'books';
-- returns 10 rows
Transaction 2:
INSERT INTO products (id, category) VALUES (101, 'books');
COMMIT;
Transaction 1:
SELECT * FROM products WHERE category = 'books';
-- returns 11 rows
Why does Transaction 1 see the new row?
Attempts:
2 left
💡 Hint
Some databases implement REPEATABLE READ differently regarding phantom reads.
✗ Incorrect
In some database systems like MySQL InnoDB, REPEATABLE READ prevents non-repeatable reads but phantom reads can still occur because it does not lock range scans fully.