0% found this document useful (0 votes)
48 views23 pages

DBMS Question Bank For 3rd IAT

The document discusses transaction concepts in database systems including: 1) The ACID properties of atomicity, consistency, isolation, and durability. 2) Concurrency control problems like lost updates, dirty reads, and incorrect summaries that can occur without proper locking protocols. 3) Transaction states and how transactions transition between states like begin, read/write, commit, rollback. 4) Recovery concepts like write-ahead logging, backups, and undo/redo operations to recover transactions after failures. 5) Timestamp ordering techniques for concurrency control to serialize transactions based on timestamps.

Uploaded by

wishfor178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views23 pages

DBMS Question Bank For 3rd IAT

The document discusses transaction concepts in database systems including: 1) The ACID properties of atomicity, consistency, isolation, and durability. 2) Concurrency control problems like lost updates, dirty reads, and incorrect summaries that can occur without proper locking protocols. 3) Transaction states and how transactions transition between states like begin, read/write, commit, rollback. 4) Recovery concepts like write-ahead logging, backups, and undo/redo operations to recover transactions after failures. 5) Timestamp ordering techniques for concurrency control to serialize transactions based on timestamps.

Uploaded by

wishfor178
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

1 a) What are the ACID Properties?

Explain with example

ACID properties

· Atomicity
A transaction is an atomic unit of processing; it is either performed in its
entirety or not performed at all.

· Consistency preservation

A transaction is consistency preserving if its complete execution takes the


database from one consistent state to another

· Isolation
The execution of a transaction should not be interfered with by any other
transactions executing concurrently

· Durability
The changes applied to the database by a committed transaction must persist
in the database. These changes must not be lost because of any failure

b) What is Concurrency? Explain the types of problem during occurs due concurrency.

DBMS has a Concurrency Control sub-system to assure database remains in consistent state
despite concurrent execution of transactions

Three problems are occurs during concurrency

1. The lost update problem


2. The temporary update (dirty read) problem
3. Incorrect summary problem

Lost Update Problem


Temporary Update (Dirty Read)

Incorrect Summary Problem


2. Define lock. Write and explain the algorithm to control the concurrency using Two-Phase
Locking Protocol.

Lock

• A variable associated with a data item

• Describes status of the data item with respect to operations that can be
performed on it

Types of locks

• Binary locks

• Locked/unlocked

• Enforces mutual exclusion

Multiple-mode locks:

• Each data item can be in one of three lock states


1. Read lock or shared lock

2. Write lock or exclusive lock

3. Unlock

Two-Phase Locking (2PL) Protocol

Transaction is said to follow the two-phase-locking protocol if all locking operations precede the
first unlock operation

• Expanding (growing) phase

• Shrinking phase

During the shrinking phase no new locks can be acquired

• Downgrading ok

• Upgrading is not

2PL Example
• Both T1’ and T2’ follow the 2PL protocol
• Any schedule including T1’ and T2’ is guaranteed to be serializable
• Limits the amount of concurrency
• Two-phase locking protocol (2PL)
All lock operations precede the first unlock operation
• Expanding phase and shrinking phase
• Upgrading of locks must be done in expanding phase and downgrading of
locks must be done in shrinking phase
• If every transaction in a schedule follows 2PL protocol then the schedules is
guaranteed to be serializable.
• Variants of 2PL
Basic, conservative, strict, and rigorous
3 a) List the transaction states. Draw and explain state transition diagram of the transaction.

Transaction states

• BEGIN_TRANSACTION: marks start of transaction


• READ or WRITE: two possible operations on the data
• END_TRANSACTION: marks the end of the read or write operations; start
checking whether everything went according to plan
• COMIT_TRANSACTION: signals successful end of transaction; changes can be
“committed” to DB
• Partially committed
• ROLLBACK (or ABORT): signals unsuccessful end of transaction, changes applied
to DB must be undone
b) Describe the list of steps include during the transaction read and write operations

• A database is represented as a collection of named data items


• Read-item (X)
1. Find the address of the disk block that contains item X
2. Copy the disk block into a buffer in main memory
3. Copy the item X from the buffer to the program variable named X
• Write-item (X)
1. Find the address of the disk block that contains item X.
2. Copy that disk block into a buffer in main memory
3. Copy item X from the program variable named X into its correct location in
the buffer.
4. Store the updated block from the buffer back to disk (either immediately or
at some later point in time).

5. When the deadlock and Starvation occurs? Explain these problems can
resolved.
Deadlocks and Starvation in 2PL

• 2PL can produce deadlocks

• Deadlock and starvation in 2PL

Deadlock occurs when each transaction T in a set of two or more transactions is waiting
for some item that is locked by some other transaction T’ in the set.

Deadlock prevention protocols

• Conservative 2PL, lock all needed items in advance

• Ordering all items in the database

Possible actions if a transaction is involved in a possible deadlock situation

• Block and wait

• Abort and restart

• Preempt and abort another transaction

Two schemes that prevent deadlock (Timestamp based)

Wait-die
An older transaction is allowed to wait on a younger transaction whereas a younger
transaction requesting an item from held by an older transaction is aborted and restarted with
the same timestamp

Wound-wait

A younger transaction is allowed to wait on an older transaction whereas an older


transaction requesting an item from held by a younger transaction preempts the younger
transaction by aborting it.

Starvation
A transaction cannot proceed for an infinite period of time while other transactions in the
system continue normally

• Unfair waiting scheme

• Victim selection

5. How to recover the transaction from failure? Explain the list of recovery concepts.

• Keeps information about operations made by transactions:

– Before-image (undo entry) of updated items

– After-image (redo entry) of updated items

• Enables restoring a consistent state after non-catastrophic failure


(forward/backward).

• Alternatives:

– undo/no-redo

– no-undo/redo

– undo/redo

– no-undo/no-redo.

Write-Ahead Logging (WAL)


(1) No overwrite of disk data before undo-type
log records are forced to disk.

(2) Both undo- and redo-type log records


(= before- and after-images) must
be forced to disk before end of commit.

Backup

• Copy of database on archival storage


(off-line, often on tape).

• Enables partial recovery from catastrophic failures:

– For committed transactions:


Load backup and apply redo operations from the
log (if the log survived).

– Non-committed transactions must be restarted


(= re-executed).

Cache

• In-memory buffer for database pages.

• A directory (page table) keeps track of pages


in cache.

• Page-replacement strategy needed, e.g.


FIFO (First-In-First-Out), or
LRU (Least Recently Used)

• Dirty bit tells for each page, if it has changed

• Flushing means (force-)writing buffer pages to disk.

• Pin/unpin bit tells if the page can be written

Rollback

• At failure, apply undo-type log records (before-images) to updated items.

• A recoverable schedule may allow cascading rollback.


• Most practical protocols avoid cascading rollbacks. Then no read-entries are
required in the log (no dirty reads).

6. Explain the timestamp ordering techniques for concurrency control.

Timestamp --- a unique identifier created by the DBMS to identify a transaction

• read-TS(X)

• The largest timestamp among all the timestamps of transactions that


have successfully read item X

• write-TS(X)

• The largest timestamp among all the timestamps of transactions that


have successfully written item X

Timestamp Ordering (TO) algorithms

• Basic timestamp ordering

• Strict timestamp ordering

• Thomas’s write rule

Basic timestamp ordering algorithm


Order transactions based on their timestamps

• T issues a write(X)

• If read-TS(X) > TS(T) or if write-TS(X) > TS(T) the abort and rollback
T and reject the operation.

• If condition above does not occur then execute the operation and set
write-TS(X) = TS(T)

• T issues a read(X)

• If write-TS(X) > TS(T) then abort and rollback T and reject the
operation.

• If write-TS(X) £ TS(T) then execute the operation and set


read-TS(X) = max ( read-TS(X), TS(T) )
• The schedules produced by basic TO are guaranteed to be conflict serializable

• No deadlocks but cyclic restart are possible (hence starvation)

Strict Timestamp Ordering (strict TO)

• A transaction T that issues a read-item(X) or write-item(X) such that TS(T) >


write-TS(X) has its read or write operation delayed until the transaction T’
that wrote the value of X (hence TS(T’ ) = write-TS(X)) has committed or
aborted.

• No deadlocks, since T waits for T’ only if TS(T) > TS(T’)

• Strict TO ensures that the schedules are both strict (for easy recoverability)
and (conflict) serializable

Thomas’s write rule

• It rejects fewer write operations, by modifying the basic TO checks for the
write-item(X) operation as follows:

1. If read-TS(X) > TS(T), then abort and roll back T and reject the
operation.

2. If write-TS(X) > TS(T), then do not execute the write operation but
continue processing.
[This is because some transaction with timestamp greater than
TS(T)—and hence after T in the timestamp ordering—has already
written the value of X. Hence, we must ignore the write_item(X)
operation of T because it is already outdated and obsolete. Notice that
any conflict arising from this situation would be detected by case (1).]

3. If neither the condition in part (1) nor the condition in part (2) occurs,
then execute the write-item(X) operation of T and set write-TS(X) to
TS(T).

Thomas’ write rule does not enforce conflict serializability


7.Define 4NF and 5NF. Explain with suitable example.

Fourth Normal Form (4NF)


Fourth Normal Form comes into picture when Multi-valued Dependency occur in any relation.
In this tutorial we will learn about Multi-valued Dependency, how to remove it and how to make
any table satisfy the fourth normal form.

A relation schema R is in 4NF with respect to a set of dependencies F (that includes functional
dependencies and multivalued dependencies) if, for every nontrivial multivalued dependency X
—>> Y in F+, X is a superkey for R.

c)The relation SUPPLY with no MVDs is in 4NF but not in 5NF if it has the JD(R1, R2, R3). (d)
Decomposing the relation SUPPLY into the 5NF relations R1, R2, and R3

For a table to satisfy the Fourth Normal Form, it should satisfy the following two conditions:

} A multivalued dependency (MVD) X —>> Y specified on relation schema R, where X


and Y are both subsets of R, specifies the following constraint on any relation state r
of R: If two tuples t1 and t2 exist in r such that t1[X] = t2[X], then two tuples t3 and t4
should also exist in r with the following properties, where we use Z to denote (R 2 (X
υ Y)):

· t3[X] = t4[X] = t1[X] = t2[X].

· t3[Y] = t1[Y] and t4[Y] = t2[Y].

· t3[Z] = t2[Z] and t4[Z] = t1[Z].


} An MVD X —>> Y in R is called a trivial MVD if (a) Y is a subset of X, or (b) X υ Y = R.

s_id course Hobby

1 Science Cricket

1 Maths Hockey

2 C# Cricket

2 Php Hockey

1. As you can see in the table above, student with s_id 1 has opted for two courses, Science and
Maths, and has two hobbies, Cricket and Hockey.
Fifth normal form (5NF)

A relation schema R is in fifth normal form (5NF) (or Project-Join Normal Form (PJNF)) with
respect to a set F of functional, multivalued, and join dependencies if, for every nontrivial join
dependency JD(R1, R2, ..., Rn) in F+ (that is, implied by F), every Ri is a superkey of R.

SUBJECT LECTURER SEMESTER


Computer Anshika Semester 1

Computer John Semester 1

Math John Semester 1

Math Akash Semester 2

Chemistry Praveen Semester 1

o In the above table, John takes both Computer and Math class for Semester 1 but he doesn't
take Math class for Semester 2. In this case, combination of all these fields required to
identify a valid data.

o Suppose we add a new Semester as Semester 3 but do not know about the subject and who
will be taking that subject so we leave Lecturer and Subject as NULL. But all three columns
together acts as a primary key, so we can't leave other two columns blank.

o So to make the above table into 5NF, we can decompose it into three relations P1, P2 & P3:

Lossless Decomposition
● If the information is not lost from the relation that is decomposed, then the decomposition
will be lossless.
● The lossless decomposition guarantees that the join of relations will result in the same
relation as it was decomposed.
● The relation is said to be lossless decomposition if natural joins of all the decomposition
give the original relation.

8. Write the short note on

i)Domain Key Normal form


} Defintion:A relation schema is said to be in DKNF if all constraints and dependencies
that should hold on the valid relation states can be enforced simply by enforcing the
domain constraints and key constraints on the relation.

} The idea is to specify (theoretically, at least) the “ultimate normal form” that takes into
account all possible types of dependencies and constraints. .

} For a relation in DKNF, it becomes very straightforward to enforce all database


constraints by simply checking that each attribute value in a tuple is of the
appropriate domain and that every key constraint is enforced.

} The practical utility of DKNF is limited

ii)Template Dependency

} Template dependencies provide a technique for representing constraints in relations


that typically have no easy and formal definitions.

} The idea is to specify a template—or example—that defines each constraint or


dependency.

} There are two types of templates: tuple-generating templates and constraint-generating


templates.
A template consists of a number of hypothesis tuples that are meant to show an example of
the tuples that may appear in one or more relations. The other part of the template is the
template conclusion.

Templates for some common types of dependencies.


(a) Template for functional dependency X –> Y.

(b) Template for the multivalued dependency X —>> Y .

(c) Template for the inclusion dependency R.X < S.Y.


iii) Inclusion Dependency

An inclusion dependency R.X < S.Y between two sets of attributes—X of relation schema R,
and Y of relation schema S—specifies the constraint that, at any specific time when r is a
relation state of R and s a relation state of S, we must have

pX(r(R)) Ê pY(s(S))

To formalize two types of interrelational constraints which cannot be expressed using F.D.s or
MVDs:

} Referential integrity constraints

} Class/subclass relationships

} Inclusion dependency inference rules

IDIR1 (reflexivity): R.X < R.X.

IDIR2 (attribute correspondence): If R.X < S.Y

where X = {A1, A2 ,..., An} and Y = {B1,


B2, ..., Bn} and Ai Corresponds-to Bi, then R.Ai < S.Bi

for 1 ≤ i ≤ n.

IDIR3 (transitivity): If R.X < S.Y and S.Y < T.Z, then R.X < T.Z.

iv) Shadow Paging

Shadow paging
Assumes an indirect addressing scheme:
References to database objects consist of
<page-no, slot-no> pairs, where page-no is
the index to a page table (’directory’), which contains the true physical addresses.

• Updated pages are written to different locations

• Two page tables are kept:

– Shadow (pointing to original pages on disk)

– Current (pointing to updated pages)

Advantages:

• Simple recovery, no log in single-user systems (in multi-user systems, logs and
checkpoints needed for concurrency control).

Disadvantages:
• Fragmentation of storage (clustering lost).

• Writing the shadow table to disk takes time.

• Garbage collection of pages needed.

v) Immediate Update recovery

Immediate update

• Updated values from the buffer first to the log, then to the database (even before
commit);
WAL-rule

• The most common in practice.

• Rollback (undo) may occur

• Two alternatives:

– All writes forced to disk before commit


(UNDO/NO-REDO)

– Some writes from buffer to disk after commit


(UNDO/REDO)
Need of concurrency control and recovery needed in DBMS:

Problems when two simple transactions run concurrently:

DBMS has a Concurrency Control sub-system to assure database remains in consistent state despite
concurrent execution of transactions
The DBMS must not permit some operations of a transaction T to be applied to the database while
other operations of T are not, because the whole transaction is a logical unit of database processing. If
a transaction fails after executing some of its operations but before executing all of them, the
operations already executed must be undone and have no lasting effect. Types of Failures. Failures are
generally classified as transaction, system, and media failures. There are several possible reasons for a
transaction to fail in the middle of execution:
1. A computer failure (system crash). A hardware, software, or network error occurs in the computer
system during transaction execution. Hardware crashes are usually media failures—for example, main
memory failure.
2. A transaction or system error. Some operation in the transaction may cause it to fail, such as integer
overflow or division by zero. Transaction failure may also occur because of erroneous parameter
values or because of a logical programming error.3 Additionally, the user may interrupt the transaction
during its execution.
3. Local errors or exception conditions detected by the transaction. During transaction execution,
certain conditions may occur that necessitate cancellation of the transaction. For example, data for the
transaction may not be found. An exception condition, such as insufficient account balance in a
banking database, may cause a transaction, such as a fund withdrawal, to be canceled. This exception
could be programmed in the transaction itself, and in such a case would not be considered as a
transaction failure.

4. Concurrency control enforcement. The concurrency control may abort a transaction because it
violates serializability ,or it may abort one or more transactions to resolve a state of deadlock among
several transactions (see Section Transactions aborted because of serializability violations or
deadlocks are typically restarted automatically at a later time.

5. Disk failure. Some disk blocks may lose their data because of a read or write malfunction or
because of a disk read/write head crash. This may happen during a read or a write operation of the
transaction. 6. Physical problems and catastrophes. This refers to an endless list of problems that
includes power or air-conditioning failure, fire, theft, sabotage, overwriting disks or tapes by mistake,
and mounting of a wrong tape by the operator.

You might also like