Professional Documents
Culture Documents
Dbms 11
Dbms 11
DBMS tasks: Managing large quantity of structured data Efficient retrieval and modification: query processing and optimization Sharing data: multiple users use and manipulate data Controlling the access to data: maintaining the data integrity An example of a database (relational): Relations (tables) Attributes (columns) Tuples (rows) Example query: Salesperson='Mary' AND Price>100.
Relational structure
Relations, attributes, tuples Primary key (unique combination of attributes for each tuple) Foreign keys: relationships between tuples (many-to-many). Example: SUPPLIES defines relations between ITEM and SUPPLIER tuples. Advantages: many-to-many relationships, high level declarative query language (e.g. SQL) SQL example (retrieve all items supplied by a supplier located in Troy): SELECT ItemName FROM ITEM, SUPPLIES, SUPPLIER WHERE SUPPLIER.City = "Troy" AND
Example: estimating Attribute=value with a given number of tuples and the size of the index.
Query optimization: finding the best plan (minimizing the computational cost and the size of the intermediate results), subsets of tuples, projection and join. Static and dynamic optimization
Database views
Creating user defined subsets of the database Improving the user interface Example:
CREATE VIEW MarySales(ItemName,Price) AS SELECT ItemName, Price FROM ITEM, SALES WHERE ITEM.Item#=SALES.Item# AND Salesperson="Mary" Then the query:
SELECT ItemName FROM ITEM, SALES WHERE ITEM.Item#=SALES.Item# AND Salesperson="Mary" AND Price>100
Data integrity
Integrity constraints: semantic conditions on the data Individual constraints on data items
Uniqueness of the primary keys Dependencies between relations
Concurrency control
Steps in executing a query Concurrent users of the database, interfering the execution of one query by another
Transaction: a set of operations that takes the database from one consistent state to another
Solving the concurrency control problem: making transactions atomic operations (one at a time) Concurrent transactions: serializability theory (two-phase locking), read lock (many), write lock (one). Serializible transactions: first phase - accumulating locks, second phase - releasing locks. Deadlocks: deadlock detection algorithms. Distributed execution problems: release a lock at one node (all locks accumulated at the other node?) strict two-phase locking
a) b)
Transaction to reserve three flights commits Transaction aborts when third flight is unavailable
Distributed Transactions
a) b)
Writeahead Log
x = 0; y = 0; BEGIN_TRANSACTION; x = x + 1; y=y+2 x = y * y; END_TRANSACTION; (a) Log Log Log
[x = 0 / 1]
[x = 0 / 1] [y = 0/2]
(b)
(c)
Serializability
BEGIN_TRANSACTION x = 0; x = x + 1; END_TRANSACTION (a) BEGIN_TRANSACTION x = 0; x = x + 2; END_TRANSACTION (b) BEGIN_TRANSACTION x = 0; x = x + 3; END_TRANSACTION (c)
x = 0; x = x + 1; x = 0; x = x + 2; x = 0; x = x + 3 x = 0; x = 0; x = x + 1; x = x + 2; x = 0; x = x + 3; x = 0; x = 0; x = x + 1; x = 0; x = x + 2; x = x + 3;
(d)
Two-phase locking.
Data integrity
Backup and recovery
The problem of keeping a transaction atomic: successful or failed
What if some of the intermediate steps failed? Log of database activity: use the log to undo a failed transaction. More problems: when to write the log, failure of the recovery system executing the log .