In This Lecture. Exam revision. Main topics. Exam format. Particular topics. How to revise. Exam format Main topics How to revise

Similar documents
Last Lecture. More Concurrency. Concurrency So Far. In This Lecture. Serialisability. Schedules. Database Systems Lecture 15

More Concurrency. Database Systems Lecture 17 Natasha Alechina

Answers to G51DBS exam

Chapter 22. Transaction Management

Concurrency Control. Transaction Management. Lost Update Problem. Need for Concurrency Control. Concurrency control

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 1. Textbook. Practicalities: assessment. Aims and objectives of the course

Concurrency Control. Data Base Management Systems. Inherently Concurrent Systems: The requirements

A7-R3: INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

DATABASE DESIGN I - 1DL300

Database Management Systems Paper Solution

Transaction Processing Concurrency control

For more Articles Go To: Whatisdbms.com CONCURRENCY CONTROL PROTOCOL


Chapter 7 (Cont.) Transaction Management and Concurrency Control

L i (A) = transaction T i acquires lock for element A. U i (A) = transaction T i releases lock for element A

Techno India Batanagar Computer Science and Engineering. Model Questions. Subject Name: Database Management System Subject Code: CS 601


CMSC 461 Final Exam Study Guide

DATABASE MANAGEMENT SYSTEMS

Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition. Chapter 13 Managing Transactions and Concurrency

Babu Banarasi Das National Institute of Technology and Management

Transactions. ACID Properties of Transactions. Atomicity - all or nothing property - Fully performed or not at all

TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION TRANSACTION PROCESSING PROPERTIES OF A TRANSACTION 4/3/2014

Attach extra pages as needed. Write your name and ID on any extra page that you attach. Please, write neatly.

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Last Class. Last Class. Faloutsos/Pavlo CMU /615

In This Lecture. Transactions and Recovery. Transactions. Transactions. Isolation and Durability. Atomicity and Consistency. Transactions Recovery

Chapter 13 : Concurrency Control

Concurrency Control Algorithms

Introduction to Database Systems. Announcements CSE 444. Review: Closure, Key, Superkey. Decomposition: Schema Design using FD

Lecture 22 Concurrency Control Part 2

DB2 Lecture 10 Concurrency Control

Transaction Management. Pearson Education Limited 1995, 2005

Concurrency Control 9-1

Delhi Noida Bhopal Hyderabad Jaipur Lucknow Indore Pune Bhubaneswar Kolkata Patna Web: Ph:

CMP-3440 Database Systems

! A lock is a mechanism to control concurrent access to a data item! Data items can be locked in two modes :

Chapter 15 : Concurrency Control

Today s Class. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Formal Properties of Schedules. Conflicting Operations

Chapter 9: Concurrency Control

Concurrency Control Overview. COSC 404 Database System Implementation. Concurrency Control. Lock-Based Protocols. Lock-Based Protocols (2)

CSE 344 MARCH 25 TH ISOLATION

CSC 261/461 Database Systems Lecture 21 and 22. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

CHAPTER 3 RECOVERY & CONCURRENCY ADVANCED DATABASE SYSTEMS. Assist. Prof. Dr. Volkan TUNALI

Multiversion schemes keep old versions of data item to increase concurrency. Multiversion Timestamp Ordering Multiversion Two-Phase Locking Each

CS Reading Packet: "Transaction management, part 2"

Multi-User-Synchronization

Transaction Management

Implementing Isolation

In This Lecture. Normalisation to BCNF. Lossless decomposition. Normalisation so Far. Relational algebra reminder: product

Transactions. Kathleen Durant PhD Northeastern University CS3200 Lesson 9

Chapter 12 : Concurrency Control

Transaction Management


CSCE 4523 Introduction to Database Management Systems Final Exam Fall I have neither given, nor received,unauthorized assistance on this exam.

Introduction to Data Management CSE 344

Introduction to Data Management CSE 414

Distributed Databases Systems

Sankalchand Patel College of Engineering, Visnagar B.E. Semester III (CE/IT) Database Management System Question Bank / Assignment

CS 370 Concurrency worksheet. T1:R(X); T2:W(Y); T3:R(X); T2:R(X); T2:R(Z); T2:Commit; T3:W(X); T3:Commit; T1:W(Y); Commit

Graph-based protocols are an alternative to two-phase locking Impose a partial ordering on the set D = {d 1, d 2,..., d h } of all data items.

UNIT-IV TRANSACTION PROCESSING CONCEPTS

Sample Exam for CSE 480 (2016)

A lock is a mechanism to control concurrent access to a data item Data items can be locked in two modes:

Last Class Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

Comp 5311 Database Management Systems. 14. Timestamp-based Protocols

Concurrency Control! Snapshot isolation" q How to ensure serializability and recoverability? " q Lock-Based Protocols" q Other Protocols"

T ransaction Management 4/23/2018 1

CS/B.Tech/CSE/New/SEM-6/CS-601/2013 DATABASE MANAGEMENENT SYSTEM. Time Allotted : 3 Hours Full Marks : 70

Transactions and Concurrency Control

CS352 Lecture - Concurrency

Advanced Databases. Lecture 9- Concurrency Control (continued) Masood Niazi Torshiz Islamic Azad University- Mashhad Branch

CS Final Exam Review Suggestions

Database design and implementation CMPSCI 645. Lectures 18: Transactions and Concurrency

CS352 Lecture - Concurrency

Database Systems CSE 414

TRANSACTION PROCESSING CONCEPTS

Transaction Processing: Concurrency Control. Announcements (April 26) Transactions. CPS 216 Advanced Database Systems

Concurrency Control. Concurrency Control Ensures interleaving of operations amongst concurrent transactions result in serializable schedules

Database Architectures

CSE 344 MARCH 9 TH TRANSACTIONS

Transactions and Concurrency Control

What are Transactions? Transaction Management: Introduction (Chap. 16) Major Example: the web app. Concurrent Execution. Web app in execution (CS636)

CSCE 4523 Introduction to Database Management Systems Final Exam Spring I have neither given, nor received,unauthorized assistance on this exam.

Applied Databases. Sebastian Maneth. Lecture 5 ER Model, Normal Forms. University of Edinburgh - January 30 th, 2017

Transaction Management: Introduction (Chap. 16)

Security Mechanisms I. Key Slide. Key Slide. Security Mechanisms III. Security Mechanisms II

UNIT 2 Set Operators

Database Tuning and Physical Design: Execution of Transactions

Introduction to Data Management CSE 344

Module 6: Process Synchronization. Operating System Concepts with Java 8 th Edition

SQL Interview Questions

Unit 10.5 Transaction Processing: Concurrency Zvi M. Kedem 1

Concurrency control CS 417. Distributed Systems CS 417

References. Concurrency Control. Administração e Optimização de Bases de Dados 2012/2013. Helena Galhardas e

The University of Nottingham

Database Technology. Topic 9: Concurrency Control

The transaction. Defining properties of transactions. Failures in complex systems propagate. Concurrency Control, Locking, and Recovery

Lecture 13 Concurrency Control

Sample Exam for CSE 480 (2017) KEY

How Oracle Does It. No Read Locks

Transcription:

In This Lecture Exam format Main topics How to revise Database Systems Lecture 18 Natasha Alechina Exam format Answer three questions out of five Each question is worth 25 points I will only mark three questions in the order you answer them (So cross out any answers you don t want marked) Final mark for the module is your coursework mark (at most 25) plus your exam mark (at most 75). Main topics hat is a database, what is a DBMS, data manipulation language, data definition language, data control language Relational model Relations, attributes, domains candidate keys, primary keys, foreign keys, entity integrity, referential integrity) Relational algebra SQL (the kind of questions you did in cw2, cw3, cw4) Normalisation (1NF, 2NF, 3NF, BCNF) Security, privileges (how to grant and revoke them) Transactions, recovery Concurrency How to revise Particular topics Do all the exercises, then check the model solutions Remember SQL syntax you will have to write SQL queries in the exam Look at the previous exam papers (for G51DBS06-07, G51DBS07-08, G51DBS08-09 and G52DBS) Normalisation Relational Algebra Concurrency control: 2PL and Timestamping Exam for last year and answers are now on the web If you get stuck with some previous exam paper questions, send me an email I will either answer by email or, if I get a lot of similar questions, arrange a tutorial 1

Normalisation General idea: given a relation R Find all candidate keys in R Find all non-trivial functional dependencies in R Decomposing to NF: for every functional dependency A B which is bad with respect to NF, decompose R into AB (R) and AC (R) where C is the rest of R s attributes. Candidate keys A set of attributes A (can be a singleton set) is a candidate key for relation R if it has properties of Uniqueness: no two different tuples in R can have the same values for attributes in A Minimality: no subset of A has the uniqueness property A set of attributes is a superkey if it includes a candidate key e call an single attribute a key attribute if it is part of a candidate key. Example (coursework 5) Functional dependencies (Cinema,Film,Day,Time) is a candidate key: It uniquely identifies each tuple: there are no two tuples which agree on these four attributes and have different values for other attributes (in this case, there is only one other attribute Certificate). It is minimal (removing one of the attributes with make the resulting set not unique). (Cinema, Film, Day, Time) and (Cinema, Film, Day, Time, Certificate) are superkeys. Cinema is a key attribute. Certificate is a non-key attribute. A, B are sets of attributes of relation R. A functional dependency A B holds for R if for every two tuples in R, if they have the same values for A, then they have the same values for B. Non-trivial functional dependency: A B is non-trivial if B is not a subset of A. Example (coursework 5) Bad functional dependencies {Film} {Certificate} is a non-trivial functional dependency {Cinema, Film} {Certificate} is also a non-trivial functional dependency So is {Film} {Certificate} for any {Cinema,Day,Time} {Film, Certificate} {Certificate} is a trivial functional dependency For 2NF: A B where A is a part of a candidate key and B is a non-key attribute (so, a table is in 2NF if it has no such dependencies) For 3NF: A B, B C where C is a not a key attribute (alternative definition of 3NF: bad fd A B is where A is not a superkey and B is non-key attribute) For BCNF: non-trivial A B where A is not a superkey. Example of 3NF but not BCNF: R(A,B,C), candidate keys (A,B) and (A,C), fd B C. 2

Example (coursework 5) Revision of relational algebra Relation Listing is not in 2NF because it has a functional dependency {Film} {Certificate} where Film is part of a candidate key and Certificate is a non-key attribute. Operations: (union), (difference), (product), (projection), (selection) Other operations are definable using the ones above: (intersection), (natural join can be defined using, and ) Revision of relational algebra Example: not union-compatible Union-compatible relations: same number of attributes/columns, with the same domains For named relations (as SQL tables, where columns have names), also the names of the attributes/columns should be the same email telephone Bob Chris bbb ccc 222222 333333 Sam Steve DOB 1985 1986 Example: not union-compatible Example: union-compatible (different domains for the second column) Email (domain: char(3)) DOB (domain: int) DOB DOB Bob bbb Sam 1985 Bob 1971 Sam 1985 Chris ccc Steve 1986 Chris 1972 Steve 1986 3

Union of two relations Let R and S be two union-compatible relations. Then their union R S is a relation which contains tuples from both relations: R S = {x: x R or x S}. Example: shopping lists R S R S Price Milk 0.80 Bread 0.60 Eggs 1.20 Soap 1.00 Price Price Cream 5.00 Milk 0.80 Bread 0.60 Eggs 1.20 Soap 1.00 Cream 5.00 Difference of two relations Let R and S be two union-compatible relations. Then their difference R S is a relation which contains tuples which are in R but not in S: R S = {x: x R and x S}. Example R S R S Price Milk 0.80 Bread 0.60 Eggs 1.20 Soap 1.00 Price Price Soap 1.00 Milk 0.80 Bread 0.60 Eggs 1.20 (Extended Cartesian) product of relations A relation containing all tuples of the form: <tuple from R, tuple from S>: R S = {<c 1,,c n, c n+1,,c n+m >: <c 1,,c n > R, <c n+1,,c n+m > S} (this assumes R has n columns and S has m columns) Price Milk 0.80 Bread 0.60 Eggs 1.20 Soap 1.00 Example R S R S Calories Milk 200 Bread 300 Price Cal Milk 0.80 Milk 200 Bread 0.60 Milk 200 Eggs 1.20 Milk 200 Soap 1.00 Milk 200 Cheese 1.34 Bread 300 Milk 0.80 Bread 300 Bread 0.60 Bread 300 Eggs 1.20 Bread 300 Soap 1.00 Bread 300 4

Projection Example:,Telephone (R) Let R be a relation with n columns, and is a set of column names. Then projection of R on is a new relation (R) which only has columns from. R: Email Telephone Bob bbb@cs.nott.ac.uk 0115222222 Chris ccc@cs.nott.ac.uk 0115333333 Example:,Telephone (R) Selection,Telephone (R): Bob Chris Telephone 0115222222 0115333333 Let R be a relation and is a property of tuples from R. Selection from R subject to condition is defined as follows: (R) = {<a 1,,a n > R: (a 1,,a n )} Example: selection ear < 2002 and Director = Nolan (R) R Title Director ear Insomnia Nolan 2002 Magnolia Anderson 1999 Insomnia Skjoldbjaerg 1997 Memento Nolan 2000 Gattaca Niccol 1997 Example: selection ear < 2002 and Director = Nolan (R) Title Director ear Memento Nolan 2000 5

Example (small) exam question hat is the result of R.,S. ( R.Tel = S.Tel (R S) ), where R and S are: R S Tel Tel Anne 111111 Chris 333333 Example exam question R S R. R.Tel S. S.Tel Anne Anne 111111 Chris 111111 Dan 333333 111111 Bob 222222 Chris 333333 Bob 222222 Dan 111111 Bob 222222 Dan 111111 Example exam question R.Tel = S.Tel (R S) Example exam question R.,S. ( R.Tel = S.Tel (R S) ) R. R.Tel S. S.Tel Anne 111111 Dan 111111 R. Anne S. Dan Revision of concurrency Lost Update Transactions running concurrently may interfere with each other, causing various problems (lost updates etc.) Concurrency control: the process of managing simultaneous operations on the database without having them interfere with each other. = - 5 This update rite() Is lost COMMIT = + 5 Only this update rite() succeeds COMMIT 6

Uncommitted Update ( dirty read ) Inconsistent analysis = - 5 rite() ROLLBACK = + 5 rite() COMMIT This reads the value of which it should not have seen = - 5 rite() = + 5 Sum = + Summing up data while it is being updated Schedules A schedule is a sequence of the operations by a set of concurrent transactions that preserves the order of operations in each of the individual transactions A serial schedule is a schedule where operations of each transaction are executed consecutively without any interleaved operations from other transactions (each transaction commits before the next one is allowed to begin) Serial schedules Serial schedules are guaranteed to avoid interference and keep the database consistent However databases need concurrent access which means interleaving operations from different transactions Serialisability Serial and Serialisable Two schedules are equivalent if they always have the same effect. A schedule is serialisable if it is equivalent to some serial schedule. For example: if two transactions only read some data items, then the order is which they do it is not important If reads and updates and reads and updates a different data item, then again they can be scheduled in any order. Interleaved Schedule Read() Read() This schedule is serialisable: Serial Schedule Read() Read() 7

Conflict Serialisable Schedule Conflict Serialisability Interleaved Schedule rite() rite() This schedule is serialisable, even though and read and write the same resources and : they have a conflict Serial Schedule rite() rite() Two transactions have a conflict: NO If they refer to different resources NO If they are reads ES If at least one is a write and they use the same resource A schedule is conflict serialisable if transactions in the schedule have a conflict but the schedule is still serialisable Concurrency control Our aim is to constrain concurrent transactions so that all resulting schedules are conflict serialisable Two approaches: Locks Time stamps Locking Locking is a procedure used to control concurrent access to data (to ensure serialisability of concurrent transactions) In order to use a resource (table, row, etc) a transaction must first acquire a lock on that resource This may deny access to other transactions to prevent incorrect results Two types of locks Locking Two types of lock Shared lock (S-lock or read-lock) Exclusive lock (-lock or write-lock) Read lock allows several transactions simultaneously to read a resource (but no transactions can change it at the same time) rite lock allows one transaction exclusive access to write to a resource. No other transaction can read this resource at the same time. The lock manager in the DBMS assigns locks and records them in the data dictionary Before reading from a resource a transaction must acquire a read-lock Before writing to a resource a transaction must acquire a write-lock Locks are released on commit/rollback A transaction may not acquire a lock on any resource that is writelocked by another transaction A transaction may not acquire a write-lock on a resource that is locked by another transaction If the requested lock is not available, transaction waits 8

Two-Phase Locking Example A transaction follows the two-phase locking protocol (2PL) if all locking operations precede the first unlock operation in the transaction Two phases Growing phase where locks are acquired on resources Shrinking phase where locks are released follows 2PL protocol All of its locks are acquired before it releases any of them does not It releases its lock on and then goes on to later acquire a lock on read-lock() read-lock() write-lock() unlock() unlock() write-lock() = + = + unlock() unlock() Serialisability Theorem Any schedule of two-phased transactions is conflict serialisable Lost Update can t happen with 2PL read-lock() cannot acquire write-lock(): has readlock() = - 5 rite() COMMIT = + 5 rite() COMMIT read-lock() cannot acquire write-lock(): has read-lock() Uncommitted Update cannot happen with 2PL Inconsistent analysis cannot happen with 2PL read-lock() write-lock() Locks released = - 5 rite() ROLLBACK = + 5 rite() COMMIT aits till releases write-lock() read-lock() write-lock() read-lock() write-lock() = - 5 rite() = + 5 Sum = + aits till releases write-locks on and 9

Timestamping Timestamping Transactions can be run concurrently using a variety of techniques e looked at using locks to prevent interference An alternative is timestamping Requires less overhead in terms of tracking locks or detecting deadlock Determines the order of transactions before they are executed Each transaction has a timestamp, TS, and if starts before then TS() < TS() Can use the system clock or an incrementing counter to generate timestamps Each resource has two timestamps R(), the largest timestamp of any transaction that has read (), the largest timestamp of any transaction that has written Timestamp Protocol Timestamping Example If T tries to read If TS(T) < () T is rolled back and restarted with a later timestamp If TS(T) () then the read succeeds and we set R() to be max(r(), TS(T)) T tries to write If TS(T) < () or TS(T) < R() then T is rolled back and restarted with a later timestamp Otherwise the write succeeds and we set () to TS(T) Given and we will assume The transactions make alternate operations Timestamps are allocated from a counter starting at 1 goes first = + = - = + = - R TS = + = - R 1 TS 1 10

= + = - R 2 TS 1 2 = + = - R 2 1 TS 1 2 = + = - R 2 2 TS 1 2 = + = - R 2 2 TS 1 2 = + = - R 2 2 TS 1 2 = + = - R 2 2 TS 1 2 11

= + = - R 2 2 TS 3 2 = + = - R 2 2 TS 3 2 2 = + = - R 3 2 TS 3 2 2 = + = - R 3 3 TS 3 2 2 = + = - R 3 3 TS 3 2 2 = + = - R 3 3 3 TS 3 2 2 12

Timestamping Any questions? The protocol means that transactions with higher times take precedence Equivalent to running transactions in order of their final time values Transactions don t wait - no deadlock Problems Long transactions might keep getting restarted by new transactions - starvation Rolls back old transactions, which may have done a lot of work 13