Set-B: - A Single Unit of Work
Set-B: - A Single Unit of Work
Set-B: - A Single Unit of Work
set-b
Explain in detail the role of immediate update in Recovery.
Explain with neat diagram the concept of Shadow paging Recovery algorithm
Identify and explain the deadlock detection methods in concurrency control 5m Illustrate
locking protocol detailing Strict Two-Phase Locking protocol. 10m
Detail the importance of timestamping in concurrency control 5m Demonstrate the role of
binary locks and shared locks in two phase locking 10m
Set c
Detail the importance of timestamping in concurrency control. Explain one algorithm using
this method.
What is a serial schedule? What is a serializable schedule? Illustrate Why is a serial schedule
considered correct .Illustrate Why is a serializable schedule considered correct
Explain Write-Ahead Logging, Steal/No-Steal, and Force/No-Force 10m Distinguish between
serial and interleave schedule with an example. 5m
Explain atomicity, durability, isolation 5m Explain with neat diagram the concept of
Shadow paging Recovery algorithm 10m
1`}
• A transaction is a single unit of work that can be completed on the whole or which is not
done at all.
• It is important to maintain the information about when a transaction starts, commits or
aborts.
• States of a transaction:
– Active state
– Partially committed state
– Committed state
– Failed state
– Terminated State
• A recovery manager maintains the following operations:
begin_transaction, read or write and end_transaction.
• Recovery techniques use the following operators:
Redo and Undo
State Transition Diagram that depicts the states for executing a transaction.
• It maintains the operations of all the transactions.
• By using a unique transaction id, we can identify a transaction.
• Types of log record----
[start_transaction,T]
[write_item,T,X,old_value,new_value]
[read_item,T,X]
[commit,T]
[abort,T]
• A transaction may enter into commit point when all its operations are executed successfully
and the effect of these operations on the database was recorded in the system log.
• Roll Back of transactions:
This is needed for all the transactions that has a [start_transaction,T] entry into the system log but no
entry [commit,T] of commit into the log.
• Redoing
• Force writing a transaction
• Atomicity − This property states that a transaction must be treated as an atomic unit, that is,
either all of its operations are executed or none. There must be no state in a database where
a transaction is left partially completed. States should be defined either before the execution
of the transaction or after the execution/abortion/failure of the transaction. (all or Nothing)
• Consistency − The database must remain in a consistent state after any transaction. No
transaction should have any adverse effect on the data residing in the database. If the
database was in a consistent state before the execution of a transaction, it must remain
consistent after the execution of the transaction as well. (remain same before and after)
• Durability − The database should be durable enough to hold all its latest updates even if the
system fails or restarts. If a transaction updates a chunk of data in a database and commits,
then the database will hold the modified data. If a transaction commits but the system fails
before the data could be written on to the disk, then that data will be updated once the
system springs back into action. (withstand)
• Isolation − In a database system where more than one transaction are being executed
simultaneously and in parallel, the property of isolation states that all the transactions will be
carried out and executed as if it is the only transaction in the system. No transaction will
affect the existence of any other transaction.
2}
Lock-based Protocols
Lock Based Protocols in DBMS is a mechanism in which a transaction cannot Read or Write
the data until it acquires an appropriate lock. Lock based protocols help to eliminate the
concurrency problem in DBMS for simultaneous transactions by locking or isolating a
particular transaction to a single user.
A lock is a data variable which is associated with a data item. This lock signifies that operations
that can be performed on the data item. Locks in DBMS help synchronize access to the database
items by concurrent transactions.
All lock requests are made to the concurrency-control manager. Transactions proceed only once
the lock request is granted.
Binary Locks: A Binary lock on a data item can either locked or unlocked states.
Shared/exclusive: This type of locking mechanism separates the locks in DBMS based on their
uses. If a lock is acquired on a data item to perform a write operation, it is called an exclusive
lock.
A shared lock is also called a Read-only lock. With the shared lock, the data item can be shared
between transactions. This is because you will never have permission to update data on the data
item.
For example, consider a case where two transactions are reading the account balance of a
person. The database will let them read by placing a shared lock. However, if another
transaction wants to update that account’s balance, shared lock prevent it until the reading
process is over.
With the Exclusive Lock, a data item can be read as well as written. This is exclusive and can’t
be held concurrently on the same data item. X-lock is requested using lock-x instruction.
Transactions may unlock the data item after finishing the ‘write’ operation.
For example, when a transaction needs to update the account balance of a person. You can
allows this transaction by placing X lock on it. Therefore, when the second transaction wants to
read or write, exclusive lock prevent this operation.
This type of lock-based protocols allows transactions to obtain a lock on every object before
beginning operation. Transactions may unlock the data item after finishing the ‘write’ operation.
4. Pre-claiming Locking
Pre-claiming lock protocol helps to evaluate operations and create a list of required data items
which are needed to initiate an execution process. In the situation when all locks are granted, the
transaction executes. After that, all locks release when all of its operations are over.
Starvation
Starvation is the situation when a transaction needs to wait for an indefinite period to acquire a
lock.
Following are the reasons for Starvation:
Deadlock
Deadlock refers to a specific situation where two or more processes are waiting for each other to
release a resource or more than two processes are waiting for the resource in a circular chain.
In the first phase, when the transaction begins to execute, it requires permission for the
locks it needs.
The second part is where the transaction obtains all the locks. When a transaction
releases its first lock, the third phase starts.
In this third phase, the transaction cannot demand any new locks. Instead, it only
releases the acquired locks.
The Two-Phase Locking protocol allows each transaction to make a lock or unlock request in
two steps:
Growing Phase: In this phase transaction may obtain locks but may not release any
locks.
Shrinking Phase: In this phase, a transaction may release locks but not obtain any new
lock
It is true that the 2PL protocol offers serializability. However, it does not ensure that deadlocks
do not happen.
In the above-given diagram, you can see that local and global deadlock detectors are searching
for deadlocks and solve them with resuming transactions to their initial states.
Centralized 2PL
In Centralized 2 PL, a single site is responsible for lock management process. It has only one
lock manager for the entire DBMS.
Distributed 2PL
In this kind of two-phase locking mechanism, Lock managers are distributed to all sites. They
are responsible for managing locks for data at that site. If no data is replicated, it is equivalent to
primary copy 2PL. Communication costs of Distributed 2PL are quite higher than primary copy
2PL
Timestamp-based Protocols
Timestamp based Protocol in DBMS is an algorithm which uses the System Time or Logical
Counter as a timestamp to serialize the execution of concurrent transactions. The Timestamp-
based protocol ensures that every conflicting read and write operations are executed in a
timestamp order.
The older transaction is always given priority in this method. It uses system time to determine
the time stamp of the transaction. This is the most commonly used concurrency protocol.
Lock-based protocols help you to manage the order between the conflicting transactions when
they will execute. Timestamp-based protocols manage conflicts as soon as an operation is
created.
Example:
Disadvantages:
1. Read Phase
2. Validation Phase
3. Write Phase
Read Phase
In the Read Phase, the data values from the database can be read by a transaction but the write
operation or updates are only applied to the local data copies, not the actual database.
Validation Phase
In Validation Phase, the data is checked to ensure that there is no violation of serializability
while applying the transaction updates to the database.
Write Phase
In the Write Phase, the updates are applied to the database if the validation is successful, else;
the updates are not applied, and the transaction is rolled back.
• Shadow paging is a technique for providing atomicity and durability in database systems.
• Shadow paging is a copy-on-write technique for avoiding in-place updates of pages. Instead,
when a page is to be modified, a shadow page is allocated.
• Since the shadow page has no references (from other pages on disk), it can be modified
liberally, without concern for consistency constraints, etc. When the page is ready to become
durable, all pages that referred to the original are updated to refer to the new replacement page
instead. Because the page is "activated" only when it is ready, it is atomic.
• This increases performance significantly by avoiding many writes on hotspots high up in the
referential hierarchy (e.g.: a file system superblock) at the cost of high commit latency.
Shadow paging considers:
1. The database is partitioned into fixed-length blocks referred to as PAGES.
2. Page table has n entries – one for each database page.
3. Each contain pointer to a page on disk (1 to 1st page on database and so on…).
The idea is to maintain 2 pages tables during the life of transaction.
1. The current page table
2. The shadow page table
When transaction starts, both page tables are identical
1. The shadow page table is never changed over the duration of the transaction
2. The current page table may be changed when a transaction performs a write operation.
3. All input and output operations use the current page table to locate database pages on
disk.
Advantages:
• No Overhead for writing log records.
• No Undo / No Redo algorithm.
• Recovery is faster.
Disadvantages:
• Data gets fragmented or scattered.
• After every transaction completion database pages containing old version of modified data
need to be garbage collected.
• Hard to extend algorithm to allow transaction to run concurrently.
R(A)
W(A)
R(B)
W(B)
R(A)
R(B)
Give a set. of FDs for the relation schema R(A,B,C,Dj with prilnary key AB under which R is in 1NF but not in
2NF
Consider a table of hospital management and show the difference between 2NF and 3NF 10m Define all the
rules followed in 3NF 5m
Create a table with library management details and show the difference between 4NF and 5NF 10m Describe
all the rules followed in 5NF 5
iscuss the main heuristics that are applied during query optimization.
hat is the difference between conflict equivalence and view equivalence 5m Normalize the following
schema, with given constraints, to 4NF. books(accessionno, isbn, title, author, publisher) users(userid,
name, deptid, deptname) accessionno→isbn isbn→title isbn→publisher isbn→→author userid→name
userid→deptid deptid→deptname 10m
Illustrate Hash function with example 10m What is the difference between a primary index and a secondary
index 5m
OPEN s1
3. Fetch Data from cursor.
There are total 6 methods to access data from cursor. They are as
follows :
FIRST is used to fetch only the first row from cursor table.
LAST is used to fetch only last row from cursor table.
NEXT is used to fetch data in forward direction from cursor table.
PRIOR is used to fetch data in backward direction from cursor table.
ABSOLUTE n is used to fetch the exact nth row from cursor table.
RELATIVE n is used to fetch the data in incremental way as well as
decremental way.
Syntax : FETCH NEXT/FIRST/LAST/PRIOR/ABSOLUTE
n/RELATIVE n FROM cursor_name
4. FETCH FIRST FROM s1
5. FETCH LAST FROM s1
6. FETCH NEXT FROM s1
7. FETCH PRIOR FROM s1
8. FETCH ABSOLUTE 7 FROM s1
9. FETCH RELATIVE -2 FROM s1
10. Close cursor connection.
Syntax : CLOSE cursor_name
CLOSE s1
11. Deallocate cursor memory.
Syntax : DEALLOCATE cursor_name
DEALLOCATE s1