Unit 4: Transaction management
Relational Database Management System notes · PTU syllabus (PGCA1904)
On this page
Unit summary
Behind every query and transaction the DBMS optimises, coordinates, protects and recovers. This unit covers query processing, concurrency control, database security and database recovery.
After this unit you can
- Explain the steps of query processing and optimisation
- Explain concurrency control protocols
- Explain database security mechanisms
- Explain database recovery techniques
PTU syllabus topics
- Query processing
- concurrency control
- database security
- database recovery
Atomicity
All or nothing
Consistency
Rules always hold
Isolation
Concurrent transactions don't interfere
Durability
Committed data survives crashes
Topic 1
Query processing
- 1Parsing and translation
Check syntax and names; convert SQL to relational algebra
- 2Optimisation
Choose the cheapest evaluation plan using statistics
- 3Evaluation
Execute the plan with algorithms for each operator
- 4Result
Return rows to the user
- Selection
- Linear scan, or index scan (B+ tree, hash)
- Sorting
- External merge sort for large relations
- Join
- Nested-loop, block nested-loop, indexed nested-loop, merge join, hash join
- Pipelining
- Pass results between operators without writing to disk
- Query optimisation: heuristic rules (perform selections and projections early, replace Cartesian products with joins, choose a good join order) and cost-based estimation (disk block transfers and seeks, using table statistics). EXPLAIN shows the chosen plan.
Example
σ marks > 90 (student ⋈ course) is rewritten as (σ marks > 90 (student)) ⋈ course, so far fewer rows are joined.
Topic 2
Transactions and ACID properties
A transaction is a sequence of operations performed as a single logical unit of work (for example transferring ₹500 from account A to B).
Atomicity
All operations happen, or none
Consistency
Takes the database from one valid state to another
Isolation
Concurrent transactions don't interfere
Durability
Committed changes survive failures
Transaction states: active → partially committed → committed, or active → failed → aborted.
Topic 3
Concurrency control
A schedule is the order in which operations of concurrent transactions are executed. A serial schedule runs transactions one after another; a concurrent schedule interleaves them.
- A schedule is conflict serializable if it can be transformed into a serial schedule by swapping non-conflicting operations. Test: draw a precedence graph; if it has no cycle, the schedule is serializable.
- Two operations conflict if they belong to different transactions, access the same item, and at least one is a write.
- A recoverable schedule commits a transaction only after every transaction it read from has committed. A cascadeless schedule reads only committed data, avoiding cascading rollbacks.
Problems of uncontrolled concurrency: lost update, dirty read (reading uncommitted data), unrepeatable read and the phantom problem.
Topic 4
Lock-based protocols and two-phase locking
- Shared lock (S): for reading; many transactions can hold it together.
- Exclusive lock (X): for writing; only one transaction can hold it.
Two-phase locking (2PL) guarantees conflict serializability:
- 1Growing phase
Acquire locks, release none
- 2Lock point
All locks held
- 3Shrinking phase
Release locks, acquire none
Strict 2PL holds exclusive locks until commit, preventing cascading rollbacks. A lock manager keeps a lock table of granted and waiting requests. Locking has an overhead: more locking reduces concurrency and throughput.
Topic 5
Timestamp ordering
- Each transaction gets a timestamp; conflicting operations must follow timestamp order. If an older transaction tries to read data already written by a younger one, it is rolled back and restarted. Free from deadlock.
Topic 6
Deadlock handling
A deadlock occurs when transactions wait for each other's locks in a cycle. Methods:
- Prevention: wait-die and wound-wait schemes based on timestamps.
- Detection: build a wait-for graph; a cycle means deadlock; then abort a victim transaction.
- Timeouts: abort a transaction that waits too long.
- Multiversion concurrency control (MVCC): keeps several versions of data so readers never block writers — used by PostgreSQL, Oracle and MySQL InnoDB. Validation (optimistic) protocols check for conflicts only at commit.
Topic 7
Database security
Security goals: secrecy (only authorised users read data), integrity (only authorised changes) and availability. Discretionary access control (DAC) lets owners grant and revoke privileges:
sqlGRANT SELECT, INSERT ON student TO clerk;
REVOKE INSERT ON student FROM clerk;
GRANT SELECT ON student TO hod WITH GRANT OPTION;Mandatory access control (MAC) uses system-wide security labels (top secret, secret …); role-based access control grants privileges to roles rather than individuals.
- Threats: unauthorised access, SQL injection, privilege abuse, stolen backups, malware. Measures: authentication, encryption at rest and in transit, views to hide data, auditing, least privilege, statistical database controls.
- SQL injection: attackers insert SQL into inputs; prevent it with prepared statements and least-privilege accounts. Encryption protects data at rest (transparent data encryption) and in transit (TLS); auditing records who did what.
Topic 8
Database recovery
- Transaction failure
- Logical error (bad input) or system error (deadlock) aborts one transaction
- System crash
- Power or software failure loses main memory, disk survives
- Disk failure
- Head crash destroys stored data
- Catastrophe
- Fire, flood or earthquake destroys the site
- 1Analysis
Scan the log from the last checkpoint; find dirty pages and active transactions
- 2Redo
Repeat history — reapply all logged updates from the earliest needed point
- 3Undo
Roll back transactions that had not committed, writing compensation log records
Key terms
- Query optimisation
- Choosing the most efficient evaluation plan
- Serializability
- Concurrent schedule equivalent to a serial one
- Two-phase locking
- Growing phase then shrinking phase of locks
- MVCC
- Concurrency control keeping multiple data versions
- Write-ahead logging
- Log written before data changes reach disk
Quick revision
- Parsing, optimisation, evaluation; selection, sort and join algorithms; heuristics and cost.
- ACID; conflict and view serializability; recoverable and cascadeless schedules.
- 2PL, strict 2PL; timestamp ordering; deadlocks; MVCC; validation.
- DAC, MAC, RBAC; GRANT, REVOKE; SQL injection; encryption; auditing.
- Failures; log-based recovery; deferred and immediate update; checkpoints; shadow paging; ARIES.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Name the steps in query processing.
- Q2.State two heuristic optimisation rules.
- Q3.What is conflict serializability?
- Q4.Distinguish 2PL and strict 2PL.
- Q5.What is MVCC?
- Q6.What is a checkpoint?
Long-answer questions
- Q1.Explain query processing and optimisation.
- Q2.Explain lock-based and timestamp-based concurrency control.
- Q3.Explain database security mechanisms.
- Q4.Explain log-based recovery and the ARIES algorithm.
Stuck on this unit?
Message SBS on WhatsApp for help with Relational Database Management System, or to ask about studying M.Sc IT at Synetic.
