← RGPV CS-502 DBMS November 2022 solved question paper
RGPV CS-502 (GS) | November 2022 | Q6(b) | 7 marks
Question (restated): Explain the effect of an account insertion committed by T1 between two average-balance queries in T2.
Answer
| T1 | T2 |
|---|---|
| SELECT AVG(balance) FROM account | |
| INSERT (222,40000); COMMIT | |
| SELECT AVG(balance) FROM account; COMMIT |
The two queries in T2 evaluate the same predicate over a set of rows. T1 inserts a new row and commits between the queries. Under an isolation level that allows a fresh committed snapshot for each statement, the second query may see an additional row. This is a phantom-read phenomenon, rather than a dirty read, because the new row is committed.
Illustrative calculation
Suppose the initial account balances are 10000 and 20000. The first average is (10000+20000)/2 = 15000. After insertion of 40000, the second average is (10000+20000+40000)/3 = 23333.33. The difference is caused by a change in the qualifying set, not an update of an existing balance. If the inserted value equals the old average, the numeric result can remain unchanged despite the phantom.
Prevention
Serializable isolation prevents executions that cannot be explained by a serial ordering. Predicate or range locking can block conflicting insertions; snapshot-based systems can provide a stable transaction snapshot, with serializable implementations detecting additional conflicts. Read committed commonly permits the phenomenon; repeatable read behavior varies by DBMS. A dirty read instead observes uncommitted data, while a nonrepeatable read concerns a changed existing row.
Further reading: Silberschatz, Korth and Sudarshan, Database System Concepts.
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion