COMP 207

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/38

flashcard set

Earn XP

Description and Tags

databasesdatabasesdatabasesdatabases

39 Terms

1
New cards

What are transactions?

A sequence of SQL statements one after the other

2
New cards

What are the problems with transactions?

Many transactions may happen at the same time, and computers can fail

3
New cards

How do SQL queries behave in practice?

They do not exist in isolation

Many queries overlap in time

Queries may be coming from many computers at once

Computers can fail, leading to partial execution of SQL statements

4
New cards

What do transitions begin with?

What do transactions end with?

START TRANSACTION

END TRANSACTION

5
New cards

Why is COMMIT always necessary?

All changes to the database are tentative before COMMIT

6
New cards

What is the special case for transactions?

Each individual SQL statement is a transaction.

7
New cards

What do transactions ensure?

How are transactions executed?

What else can we state about transactions?

Serialisable behaviour

As if they are being executed in isolation from all other transactions

That it must be executed atomically

8
New cards

Translate the following into a low-level operation:

SELECT salary FROM Employees WHERE e_id = 1234;

UPDATE Employees SET salary = salary*1.1 WHERE e_id = 1234;

read(e_id=1234, salary);

salary = salary*1.1;

write(e_id=1234, salary);

9
New cards

Abstract the following:

read(e_id=1234, salary);

salary = salary*1.1;

write(e_id=1234, salary);

read(X);

X=X*1.1;

write(X);

10
New cards

What does the command read(X) do?

Explain this process

Reads a database item X into a program variable

  1. Find the address of the disk block that contains item X

  2. Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer)

  3. Copy item X from the buffer into the program variable X


11
New cards

What does the command write(X) do?

Explain this process

Writes the value of the program variable X into the database item named X

  1. find the address of the disk block that contains item X

  2. copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer)

  3. If it is not already in some main memory buffer, copy item X from the program variable X into its correct location in the buffer

  4. Store the updated block from the buffer back into disk either immediately or at some point later in time


12
New cards

What must the schedule preserve?

What are the two types of schedule?

What are the differences between these types of schedule?

That the operations in each transaction happen in the correct order

Serial and concurrent

Serial schedules execute transactions one after the other, whereas concurrent transactions can interleave operations from different transactions

13
New cards

Give the shorthand notation for the following:

Schedule

read(X) in transaction i

write(X) in transaction i

Commit in transaction i

Abort (rollback) in transaction i

  1. Sid

  2. ri(X)

  3. wi(X)

  4. ci

  5. ai


14
New cards

Are the following schedules serial or concurrent?

r1(X); w1(X); r2(X); r1(Y); w1(Y); c1; r2(Y); c2

r2(X); r2(Y); w2(X); c2; r1(X); w1(X); r1(Y); w1(Y); c1

  1. Concurrent

  2. Concurrent and serial (all serial schedules are concurrent)


15
New cards

What does ACID stand for?

Explain the definition of each term

Atomicity, consistency, isolation, and durability

  1. Transactions are an indivisible unit of execution, and are executed entirely, or not at all

  2. A correct execution of a transaction must take the database from one consistent state to another

    • transactions may not violate constraints

    • it should correctly transform the database state to reflect the effect of a real-world event

  3. A schedule satisfies isolation if it is serialisable

  4. Once a transaction commits and changes the database, these changes cannot be lost because of subsequent failure


16
New cards

What are the causes of failure in a database?

What steps does the database take in the event of an abort?

  • User aborts transaction

  • System aborts transaction

  • Transaction aborts itself

  • System crashes, network failure etc

We undo the work done up to the error point, and the system recreates the database state as it was before the start of the aborted transaction

17
New cards

What are the 4 levels of isolation, and what do they mean?

  1. Read uncommitted

    • essentially not having isolation at all

    • it is fine if you read data which has not been committed

  2. Read committed

    • everything you read must have been committed before you can use it

  3. Repeatable read

    • if you read the same thing twice in a transaction, you must get the same return value

  4. Serialisable

    • default meaning of isolation

    • requires that all of the earlier levels are satisfied


18
New cards

What are the two components to transaction management?

What components are used to satisfy ACID?

  1. Concurrency and control

  2. Logging and memory

A - via recovery control, logging and recovery

C - via scheduler, concurrency control

I - via scheduler, concurrency control

D - via recovery control

19
New cards

List the properties of serial schedules

List the properties of concurrent schedules

Execute correctly, maintain consistency of the database, inefficient in multi-user environments (transactions have to wait until others are finished)

May not execute correctly, may not guarantee consistency of the database or isolation, efficient in multi-user environments


20
New cards

What is a serialisable schedule?

What do serialisable schedules guarantee?

What is the problem with serialisable schedules?

A schedule S is serialisable if there is a serial schedule S’ that has the same effect as S on every initial database state

Correctness and consistency

They are difficult to test


21
New cards

What is conflict-serialisability?

What is this based on?

Define this term

A stronger form of serialisability that is used/ enforced by most commercial DBMSs

Based on the notion of a conflict

A conflict in a schedule is a pair of operations from different transactions that cannot be swapped without changing the behaviour of at least one of the transactions (both access the same item, and at least one is a write operation)

22
New cards

What makes two schedules conflict-equivalent?

What makes a schedule conflict-serialisable?

Two schedules S and S’ are conflict-equivalent if S’ can be obtained from S by swapping any number of (1) consecutive (2) non-conflicting operations from (3) different transactions

A schedule is conflict-serialisable if you can in some way repeatedly swap consecutive pairs of non-conflicting operations from different transactions and get a serial schedule / the schedule is conflict-equivalent to a serial schedule

23
New cards

How is a precedence graph defined for a schedule S?

How do you test if a schedule S is conflict-serialisable?

The precedence graph for a schedule S is defined as follows:

  • it is a directed graph

  • its nodes are the transactions that occur in S

  • it has an edge from transaction Ti to transaction Tj if there is a conflicting pair of operations op1 and op2, such that:

    • op1 appears before op2 in S

    • op1 belongs to transaction Ti

    • op2 belongs to transaction Tj

  1. Construct the precedence graph for S

  2. If the precedence graph is not a cycle, then S is conflict-serialisable

  3. Otherwise not


24
New cards

What is a simple locking mechanism?

How are these locks achieved?

What are the conditions of these locks?

A transaction has to lock an item before it accesses it

Locks are requested from and granted by the scheduler

Each item is locked by at most one transaction at a time, and transactions must wait until a lock can be granted. Each lock has to be released (unlocked) eventually

25
New cards

What is the syntax for a lock and an unlock?

What are the rules for these locks?

  • li(X) - transaction i requests a lock for item X

  • ui(X) - transaction I unlocks item X

  1. For each ri(X)/wi(X) there is an earlier li(X) without any ui(X) occurring between li(X) and ri(X)/wi(X)

  2. For each li(X) there is a later ui(X)

  3. If li(X) comes before lj(X), then ui(X) occurs between li(X) and lj(X)


26
New cards

What is two-phase locking?

What is the condition for two-phase locking?

A modification of the simple locking mechanism that guarantees conflict-serialisability

In each transaction, all lock operations precede all unlocks

27
New cards

How do you test if a transaction is 2PL?

How can you tell whether a schedule is 2PL?

What does a 2PL schedule ensure?

Find the first unlock:

  • phase 1 is up to, but not including, that unlock

  • phase 2 is from that unlock until the end

A transaction is 2PL if phase 2 contains no lock

A schedule is 2PL if all transactions are 2PL

Conflict-serialisability

28
New cards

What problems could 2PL lead to?

Define this problem

How can we make 2PL more flexible?

Deadlocks

Transactions get stuck because multiple transactions are waiting for one of the others to release a lock

Implement different lock modes

29
New cards

List two types of locks

Define these, and their rules

Are there any additional rules?

Shared lock, exclusive lock

Shared lock: requested by transactions to read item x, granted to several transactions at the same time

Exclusive lock: requested by transactions to write to item x, granted to at most one transaction at a time

Shared lock on x is granted only if no other transactions hold an exclusive lock on x, exclusive lock on x is granted only if no other transactions have a lock on x of any kind

30
New cards

What is the shorthand notation for the following?

Transaction i requests a shared lock for item x

Transaction i requests an exclusive lock for item x

Transaction i requests an unlock for item x

  1. sli(X)

  2. xli(X)

  3. ui(X)


31
New cards

What are the problems with upgrading locks?

What does it mean to upgrade a lock?

How is this used?

Risk of deadlocks

A shared lock on an item X can later be upgraded to an exclusive lock on X

This is used to be friendly to other transactions

32
New cards

What is a solution to deadlocks?

How do these work?

What does this mean for shared locks?

Update locks

Requested by transactions to read (not write) an item, may be upgraded later to an exclusive lock. Granted to at most one transaction at a time

They can no longer be upgraded

33
New cards

What is the standard principle of 2PL with shared, exclusive, and update locks?

Describe each phase of 2PL with shared, exclusive, and update locks

What does this guarantee?

In each transaction, all lock operations precede all unlocks

Phase 1: request locks and possibly other read/write operations

Phase 2: unlock and possibly other read/write operations

Conflict-serialisability

34
New cards

List the different levels of granularity at which the DBMS may use locks

Relations

Disk blocks

Tuples

35
New cards
36
New cards
37
New cards
38
New cards
39
New cards