Dirty Read Problem
Dirty Read Problem
Dirty Read Problem
problem
This type of problem occurs when one transaction T1 updates a data item of the database,
and then that transaction fails due to some reason, but its updates are accessed by some
other transaction.
Example: Let’s take the value of A is 100
t1 Read(A)
t2 A=A+20
t3 Write(A)
t4 Read(A)
t5 A=A+30
t6 Write(A)
t7 Write(B)
Here,
At t1 time, T1 transaction reads the value of A i.e., 100.
At t2 time, T1 transaction adds the value of A by 20.
At t3 time, T1transaction writes the value of A (120) in the database.
At t4 time, T2 transactions read the value of A data item i.e., 120.
At t5 time, T2 transaction adds the value of A data item by 30.
At t6 time, T2transaction writes the value of A (150) in the database.
At t7 time, a T1 transaction fails due to power failure then it is rollback according to
atomicity property of transaction (either all or none).
So, transaction T2 at t4 time contains a value which has not been committed in the
database. The value read by the transaction T2 is known as a dirty read.
Unrepeatable read (R-W Conflict) or the inconsistency
analysis problem
t1 Read(A)
t2 Read(A)
t3 A=A+30
t4 Write(A)
t5 Read(A)
Here,
At t1 time, T1 transaction reads the value of A i.e., 100.
At t2 time, T2transaction reads the value of A i.e., 100.
At t3 time, T2 transaction adds the value of A data item by 30.
At t4 time, T2 transaction writes the value of A (130) in the database.
Transaction T2 updates the value of A. Thus, when another read statement is
performed by transaction T1, it accesses the new value of A, which was updated by T2.
Such type of conflict is known as R-W conflict.
Lock-Based Protocol
In this type of protocol, any transaction cannot read or write data until it acquires an
appropriate lock on it. There are two types of lock:
1. Shared lock:
o It is also known as a Read-only lock. In a shared lock, the data item can only read by the
transaction.
o It can be shared between the transactions because when the transaction holds a lock,
then it can't update the data on the data item.
2. Exclusive lock:
o In the exclusive lock, the data item can be both reads as well as written by the
transaction.
o This lock is exclusive, and in this lock, multiple transactions do not modify the same data
simultaneously.
o Pre-claiming Lock Protocols evaluate the transaction to list all the data items on which
they need locks.
o Before initiating an execution of the transaction, it requests DBMS for all the lock on all
those data items.
o If all the locks are granted then this protocol allows the transaction to begin. When the
transaction is completed then it releases all the lock.
o If all the locks are not granted then this protocol allows the transaction to rolls back and
waits until all the locks are granted.
o The two-phase locking protocol divides the execution phase of the transaction into three
parts.
o In the first part, when the execution of the transaction starts, it seeks permission for the
lock it requires.
o In the second part, the transaction acquires all the locks. The third phase is started as
soon as the transaction releases its first lock.
o In the third phase, the transaction cannot demand any new locks. It only releases the
acquired locks.
There are two phases of 2PL:
Growing phase: In the growing phase, a new lock on the data item may be acquired by
the transaction, but none can be released.
Shrinking phase: In the shrinking phase, existing lock held by the transaction may be
released, but no new locks can be acquired.
In the below example, if lock conversion is allowed then the following phase can
happen:
Example:
The following way shows how unlocking and locking work with 2-PL.
Transaction T1:
Transaction T2:
o The first phase of Strict-2PL is similar to 2PL. In the first phase, after acquiring all the
locks, the transaction continues to execute normally.
o The only difference between 2PL and strict 2PL is that Strict-2PL does not release a lock
after using it.
o Strict-2PL waits until the whole transaction to commit, and then it releases all the locks at
a time.
o Strict-2PL protocol does not have shrinking phase of lock release.
Starvation
Data independence
1. Logical Data Independence
o Logical data independence refers characteristic of being able to change the conceptual
schema without having to change the external schema.
o Logical data independence is used to separate the external level from the conceptual
view.
o If we do any changes in the conceptual view of the data, then the user view of the data
would not be affected.
o Logical data independence occurs at the user interface level.
Logical Data Independence is mainly Mainly concerned with the storage of the
concerned with the structure or changing data.
the data definition.
You need to make changes in the A change in the physical level usually
Application program if new fields are does not need change at the Application
added or deleted from the database. program level.
1. Query Processor :
It interprets the requests (queries) received from end user via an application
program into instructions. It also executes the user request which is received
from the DML compiler.
Query Processor contains the following components –
DML Compiler –
It processes the DML statements into low level instruction (machine
language), so that they can be executed.
DDL Interpreter –
It processes the DDL statements into a set of table containing meta data
(data about data).
Embedded DML Pre-compiler –
It processes DML statements embedded in an application program into
procedural calls.
Query Optimizer –
It executes the instruction generated by DML Compiler.
2. Storage Manager :
Storage Manager is a program that provides an interface between the data
stored in the database and the queries received. It is also known as Database
Control System. It maintains the consistency and integrity of the database by
applying the constraints and executes the DCL statements. It is responsible for
updating, storing, deleting, and retrieving data in the database.
It contains the following components –
Authorization Manager –
It ensures role-based access control, i.e,. checks whether the particular
person is privileged to perform the requested operation or not.
Integrity Manager –
It checks the integrity constraints when the database is modified.
Transaction Manager –
It controls concurrent access by performing the operations in a scheduled
way that it receives the transaction. Thus, it ensures that the database
remains in the consistent state before and after the execution of a
transaction.
File Manager –
It manages the file space and the data structure used to represent
information in the database.
Buffer Manager –
It is responsible for cache memory and the transfer of data between the
secondary storage and main memory.
3. Disk Storage :
It contains the following components –
Data Files –
It stores the data.
Data Dictionary –
It contains the information about the structure of any database object. It is
the repository of information that governs the metadata.
Indices –
It provides faster retrieval of data item.
SQL | Views
Views in SQL are kind of virtual tables. A view also has rows and columns as they are in
a real table in the database. We can create a view by selecting fields from one or more
tables present in the database. A View can either have all the rows of a table or specific
rows based on certain condition.
In this article we will learn about creating , deleting and updating Views.
We can create View using CREATE VIEW statement. A View can be created
from a single table or multiple tables.