Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Find
the minimum cover for the given set of FDs be E: {B-> A, D->A, AB->D}
2. Prove that the below decomposition the relation R has the loseless join property and
dependency preserving property?
Atomicity
By this, we mean that either the entire transaction takes place at once or
doesn’t happen at all. There is no midway i.e. transactions do not occur
partially. Each transaction is considered as one unit and either runs to
completion or is not executed at all. It involves following two operations.
Consistency
The total amount before and after the transaction must be maintained.
Isolation
Durability:
This property ensures that once the transaction has completed execution,
the updates and modifications to the database are stored in and written to
disk and they persist even if system failure occurs. These updates now
become permanent and are stored in a non-volatile memory. The effects of
the transaction, thus, are never lost.
The log is kept on disk start_transaction(T): This log entry records that
transaction T starts the execution.
read_item(T, X): This log entry records that transaction T reads the
value of database item X.
commit(T): This log entry records that transaction T has completed all
accesses to the database successfully and its effect can be committed
(recorded permanently) to the database.
A transaction T reaches its commit point when all its operations that access
the database have been executed successfully i.e. the transaction has
reached the point at which it will not abort (terminate without completing).
Once committed, the transaction is permanently recorded in the database.
Commitment always involves writing a commit entry to the log and writing
the log to disk. At the time of a system crash, item is searched back in the
log for all transactions T that have written a start_transaction(T) entry into
the log but have not written a commit(T) entry yet; these transactions may
have to be rolled back to undo their effect on the database during the
recovery process
Undoing – If a transaction crashes, then the recovery manager may undo
transactions i.e. reverse the operations of a transaction. This involves
examining a transaction for the log entry write_item(T, x, old_value,
new_value) and setting the value of item x in the database to old-
value.There are two major techniques for recovery from non-catastrophic
transaction failures: deferred updates and immediate updates.
This is the method where all the transactions are executed in the primary
memory or the shadow copy of database. Once all the transactions
completely executed, it will be updated to the database. Hence, if there is
any failure in the middle of transaction, it will not be reflected in the
database. Database will be updated after all the transaction is complete.
(OR)
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.
Here, are some issues which you will likely to face while using the
Concurrency Control method:
Lost Updates occur when multiple transactions select the same row and
update the row based on the value selected
Example
Assume that two people who go to electronic kiosks at the same time to buy
a movie ticket for the same movie and the same show time.
However, there is only one seat left in for the movie show in that particular
theatre. Without concurrency control, it is possible that both moviegoers
will end up purchasing a ticket. However, concurrency control method does
not allow this to happen. Both moviegoers can still access information
written in the movie seating database. But concurrency control only
provides a ticket to the buyer who has completed the transaction process
first.
Lock-Based Protocols
Two Phase
Timestamp-Based Protocols
Validation-Based Protocols
Types of Serializability
1. Conflict Serializability
2. View Serializability
12. Write an algorithm for finding a minimal cover F for a set of functional
dependencies E. Find the minimum cover for the given set of FDs be E:
{AB-> D, B->C, AE->B, A->D, D->EF}
Now, recalling where we last left off, there are two types of Locks available
Shared S(a) and Exclusive X(a). Implementing this lock system without any
restrictions gives us the Simple Lock based protocol (or Binary Locking),
but it has its own disadvantages, they does not guarantee Serializability.
Schedules may follow the preceding rules but a non-serializable schedule
may result.
Growing Phase: New locks on data items may be acquired but none can
be released.
Shrinking Phase: Existing locks may be released but no new locks can be
acquired.
Note – If lock conversion is allowed, then upgrading of lock( from S(a) to
X(a) ) is allowed in Growing Phase and downgrading of lock (from X(a) to
S(a)) must be done in shrinking phase.
This is just a skeleton transaction which shows how unlocking and locking
works with 2-PL. Note for:
Transaction T1:
Lock Point at 3
Transaction T2:
Hey, wait!
The Point at which the growing phase ends, i.e., when transaction takes the
final lock it needs to carry on its work. Now look at the schedule, you’ll
surely understand.
I have said that 2-PL ensures serializablity, but there are still some
drawbacks of 2-PL. Let’s glance at the drawbacks:
Deadlock in 2-PL –
Drawing the precedence graph, you may detect the loop. So Deadlock is
also possible in 2-PL.
Two-phase locking may also limit the amount of concurrency that occur in
a schedule because a Transaction may not be able to release an item after it
has used it. This may be because of the protocols and other restrictions we
may put on the schedule to ensure serializability, deadlock freedom and
other factors. This is the price we have to pay to ensure serializability and
other factors, hence it can be considered as a bargain between concurrency
and maintaining the ACID properties.
16. When a deadlock and starvation problem occur? Explain how these
problems can be resolved.
Starvation in DBMS
Reasons of Starvation –
Resource leak.
Increasing Priority –
Deadlock Detection
In this case for Deadlock detection we can run an algorithm to check for
cycle in the Resource Allocation Graph. Presence of cycle in the graph is
the sufficient condition for deadlock.
deadlock
Deadlock Recovery
Recovery method
Killing the process: killing all the process involved in the deadlock.
Killing process one by one. After killing each process check for deadlock
again keep repeating the process till system recover from deadlock.
21. Given below are two sets of FDs for a relation R (A, B, C, D, E). Are
they equivalent?
24. Discuss the time – stamp ordering protocol for concurrency control.
The main idea for this protocol is to order the transactions based on their
Timestamps. A schedule in which the transactions participate is then
serializable and the only equivalent serial schedule permitted has the
transactions in the order of their Timestamp Values. Stating simply, the
schedule is equivalent to the particular Serial Order corresponding to the
order of the Transaction timestamps. Algorithm must ensure that, for each
items accessed by Conflicting Operations in the schedule, the order in
which the item is accessed does not violate the ordering. To ensure this, use
two Timestamp Values relating to each database item X.
If R_TS(X) > TS(T) or if W_TS(X) > TS(T), then abort and rollback T
and reject the operation. else,
If W_TS(X) > TS(T), then abort and reject T and reject the operation,
else
But the schedule may not be cascade free, and may not even be
recoverable.
Syntax: COMMIT;
Following is an example which would delete those records from the table
which have age = 20 and then COMMIT the changes in the database.
COMMIT;
Output:
Thus, two rows from the table would be deleted and the SELECT
statement would look like,
ROLLBACK: If any error occurs with any of the SQL grouped statements,
all changes need to be aborted. The process of reversing changes is called
rollback. This command can only be used to undo transactions since the
last COMMIT or ROLLBACK command was issued.
Syntax: ROLLBACK;
Example:
Delete those records from the table which have age = 20 and then
ROLLBACK the changes in the database.
ROLLBACK;
Output:
SAVEPOINT SAVEPOINT_NAME;
This command is used only in the creation of SAVEPOINT among all the
transactions.
ROLLBACK TO SAVEPOINT_NAME;
Example:
Delete those records from the table which have age = 20 and then
ROLLBACK the changes in the database by keeping Savepoints.
Queries:
SAVEPOINT SP1;
//Savepoint created.
//deleted
SAVEPOINT SP2;
//Savepoint created.
Here SP1 is first SAVEPOINT created before deletion.In this example one
deletion have taken place.
Output:
Deletion have been taken place, let us assume that you have changed your
mind and decided to ROLLBACK to the SAVEPOINT that you identified
as SP1 which is before deletion.
ROLLBACK TO SP1;
//Rollback completed.
Notice that first deletion took place even though you rolled back to SP1
which is first SAVEPOINT.
Once a SAVEPOINT has been released, you can no longer use the
ROLLBACK command to undo transactions performed since the last
SAVEPOINT.