Relations stored as unordered files. Index on first column of Students.
View (External Schema):
Course_info(cid:string, enrollment:integer)
Data Independence
Three levels of abstraction provides data independence.
Changes in one layer only affect one upper layer.
E.g., applications are not affected by changes in conceptual & physical schema.
Queries in DBMS
Sample queries on university database:
What is the name of the student with student ID 123456?
The key benefits of using a relational database are Easy to specify queries using a query language: Structured Query Language (SQL)
SELECT S.name FROM Students S WHERE S.sid = 123456
Efficient query processor to get answer
Transaction Management
• A transaction is an execution of a user program in a DBMS.
• Transaction management deals with two things:
Concurrent execution of transactions(并发事务处理)
Incomplete transactions and system crashes(事务回滚机制)
Concurrency Control
Example
two travel agents (A, B) are trying to book one remaining airline seat (two transactions), only one transaction can succeed in booking.
How to solve this?
Solution: use locking protocol(锁机制)
Transaction A: get exclusive lock on num_seats
Transaction B: wait until A releases lock on num_seats
Transaction A: if num_seats > 0, book & num_seat--;
// book the seat, num_seat is set to 0
Transaction A: release exclusive lock on num_seats
Transaction B: num_seats = 0, no booking;
// does not book the seat
Crash Recovery
Example:
a bank transaction transfers $100 from account A to account B
A = A - $100
<system crashes> // good for the bank!
B = B + $100
How to solve this?
Solution:use logging, meaning that all write operations are recorded in a log on a stable storage
A = A - $100 // recorded A value (checkpoint) in a log
<system crashes>
// start recovery: read the log from disk
//analyze, undo, & redo