Possible problems in RDBMS
-
Upload
sonu-mamman -
Category
Data & Analytics
-
view
47 -
download
1
description
Transcript of Possible problems in RDBMS
Submitted To: Submitted By: Sarbjeet Singh
MCA-2nd
Roll No: 5(DBU)
Phantom Reads are also known as Phantom Record or Dirty Reads.
A dirty read occurs when a transaction is allowed to read data from a row that has been modified by another running transaction and not yet committed.
Continue…………
• In our example, Transaction 2 changes a row, but does not commit the changes. Transaction 1 then reads the uncommitted data. Now if Transaction 2 rolls back its changes (already read by Transaction 1) or updates different changes to the database, then the view of the data may be wrong in the records of Transaction 1.
• Transaction 1/* Query 1 */
SELECT age FROM users WHERE id = 1;/* will read 20 */
• Transaction 2/* Query 2 */
UPDATE users SET age = 21 WHERE id = 1;/* No commit here */
• Transaction 1/* Query 1 */
SELECT age FROM users WHERE id = 1;/* will read 21 */
ROLLBACK; /* lock-based DIRTY READ */
• But in this case no row exists that has an id of 1 and an age of 21.
Locking is a facility provided by an RDBMS to ensure that a transaction does not interfere with any other transaction.
This prevents data from being corrupted or invalidated when multiple users try to read while others write to the database.
Binary Locking
Shared/Exclusive (or Read/Write) Locking
Two Phase Locking
A binary lock has two states zero or one (0 or 1)
L(X)=1 means the database object X is locked
L(X)=0 means the database object X is unlocked
Statements:
Lock(x)-Lock on object x
Unlock(x)-Unlock on object x
If a transaction is only reading data from a database, it gets a shared lock on that part of the database. Other transactions can also get a shared lock on that part of the database to read data. However, they cannot change the data.
If a transaction is updating data in a database, it gets an exclusive lock on that part of the database. No other transaction can read or change this data.
The rules to be followed in 2PL are
If Transaction wants to read an object, first obtains an Shared locks.
If Transaction wants to modify an object, first obtains a Exclusive locks.
If Transaction releases any lock, it can acquire no new locks.
It deals with the cost of implementing locks depending upon the space and time. Here, space refers to data structure in DBMS for each lock and time refers to handling of lock request and release.
Continue…
The cost of implementing locks depends on the size of data items. There are two types of lock granularity:
Fine granularity :
-refers for small item sizes
Coarse granularity :
-refers for large item Sizes.
Here, Sizes decides on the basis:
• a database record
• a field value of a database record
• a disk block
• a whole file
• the whole database
Deadlock situation occurs when two or more process attempt to access a resource, which is locked by another process and therefore can’t be shared.
Due to locking of resource, each process has to wait for resource that is locked by another process and as a result non of transaction can finish.
Time stamp
A timestamp is the current time of an data item that is recorded in a database.
Timestamps are also routinely used to provide information about files, including when they were created and last accessed or modified.
. This information is included in the inode, which is a data structure on a file-system on a Unix-like operating system that stores all the information about a file except its name and its actual data.