CS FundamentalsModerateTCS NQT · Infosys pattern
A transaction executes `BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT;` and the system crashes after the first UPDATE is written to disk but before COMMIT. What should recovery do?
- A. Leave the database in whatever state the crash left it, with no recovery action needed
- B. Keep the first UPDATE's effect and skip the second, since partial progress is better than none
- C. Roll back the first UPDATE's effect entirely, since the transaction never committed — atomicity requires all-or-nothing
- D. Apply the second UPDATE automatically to 'complete' the transaction
Correct answer: C. Roll back the first UPDATE's effect entirely, since the transaction never committed — atomicity requires all-or-nothing
Atomicity guarantees a transaction's effects are either entirely applied or entirely undone. Since COMMIT was never reached, recovery's undo pass must reverse the first UPDATE (using the log's before-image/undo information) so the transaction has no partial, inconsistent effect on the database.
More DBMS and SQL questions
- A relation R(A, B, C, D, E) has candidate key AB and no other candidate keys. Which of the following dependencies, if it existed, would…
- A relation R(A, B, C, D) has candidate key AB. If C and D are both non-prime, and B → C holds (B alone, part of the key, determines C)…
- A query optimizer estimates the selectivity of WHERE age = 30 using a histogram on the age column rather than assuming a uniform…
- A table has 1,000,000 rows, and a column's selectivity (distinct values / total rows) is estimated as 1/100,000. Roughly how many rows…
- A B+ tree index on a column is said to have a 'fan-out' of 100 (each internal node has up to 100 children). For a table with 10,000,000…
- Which of these is the best reason a database might choose to use a bitmap index rather than a B+ tree index on a column?