DBMS in 5 Hours
DBMS in 5 Hours
DBMS in 5 Hours
• Chapter-1 (Basics): Data & information, Database System vs File System, Views of Data Base, Data Independence,
Instances & Schema, OLAP Vs OLTP, Types of Data Base, DBA, Architecture.
• Chapter-2 (ER Diagram): Entity, Attributes, Relationship, Degree of a Relationship, Mapping, Weak Entity set,
Conversion from ER Diagram to Relational Model, Generalization, Specification, Aggregation.
• Chapter-3 (RDBMS & Functional Dependency): Basics & Properties, Update Anomalies, Purpose of Normalization,
Functional Dependency, Closure Set of Attributes, Armstrong’s axioms, Equivalence of two FD, Canonical cover, Keys.
• Chapter-4 (Normalization): 1NF, 2NF, 3NF, BCNF, Multivalued Dependency, 4NF, Lossy-Lossless Decomposition, 5NF,
Dependency Preserving Decomposition.
• Chapter-5 (Indexing): Overview of indexing, Primary indexing, Clustered indexing and Secondary Indexing, B-Tree.
• Chapter-6 (Relational Algebra) : Query Language, Select, Project, Union, Set Difference, Cross Product, Rename
Operator, Additional or Derived Operators.
• Chapter-7(SQL) : Introduction to SQL, Classification, DDL Commands, Select, Where, Set Operations, Cartesian
Product, Natural Join, Outer Join, Rename, Aggregate Functions, Ordering, String, Group, having, Trigger, embedded,
dynamic SQL.
• Chapter-8 (Relational Calculus) : Overview, Tuple Relation Calculus, Domain Relation Calculus.
• Chapter-9 (Transaction) : What is Transaction, ACID Properties, Transaction Sates, Schedule, Conflict Serializability,
View Serializability, Recoverability, Cascade lessness, Strict Schedule.
• Chapter-10 (Recovery & Concurrency Control) : Log Based Recovery, Shadow Paging, Data Fragmentation, TIME
STAMP ORDERING PROTOCOL, THOMAS WRITE RULE, 2 phase locking, Basic 2pl, Conservative 2pl, Rigorous 2pl, Strict
2pl, Validation based protocol Multiple Granularity.
Knowledge Gate Website
Syllabus
• UNIT-1 : INTRODUCTION Overview, Database System vs File System, Database System Concept and Architecture, Data
Model Schema and Instances, Data Independence and Database Language and Interfaces, Data Definitions Language,
DML, Overall Database Structure. Data Modeling Using the Entity Relationship Model: ER Model Concepts, Notation
for ER Diagram, Mapping Constraints, Keys, Concepts of Super Key, Candidate Key, Primary Key, Generalization,
Aggregation, Reduction of an ER Diagrams to Tables, Extended ER Model, Relationship of Higher Degree.
• UNIT-2 : RELATIONAL DATA MODEL Relational Data Model Concepts, Integrity Constraints, Entity Integrity, Referential
Integrity, Keys Constraints, Domain Constraints, Relational Algebra, Relational Calculus, Tuple and Domain Calculus.
Introduction on SQL: Characteristics of SQL, Advantage of SQL. SQl Data Type and Literals. Types of SQL Commands.
SQL Operators and Their Procedure. Tables, Views and Indexes. Queries and Sub Queries. Aggregate Functions. Insert,
Update and Delete Operations, Joins, Unions, Intersection, Minus, Cursors, Triggers, Procedures in SQL/PL SQL.
• UNIT-3 : DATA BASE DESIGN & NORMALIZATION Functional dependencies, normal forms, first, second, 3 third normal
forms, BCNF, inclusion dependence, loss less join decompositions, normalization using FD, MVD, and JDs, alternative
approaches to database design.
• UNIT-4 : TRANSACTION PROCESSING CONCEPT Transaction System, Testing of Serializability, Serializability of
Schedules, Conflict & View Serializable Schedule, Recoverability, Recovery from Transaction Failures, Log Based
Recovery, Checkpoints, Deadlock Handling. Distributed Database: Distributed Data Storage, Concurrency Control,
Directory System.
• UNIT-5 : CONCURRENCY CONTROL TECHNIQUES Concurrency Control, Locking Techniques for Concurrency Control,
Time Stamping Protocols for Concurrency Control, Validation Based Protocol, Multiple Granularity, Multi Version
Schemes, Recovery with Concurrent Transaction, Case Study of Oracle.
Knowledge Gate Website
What is Data ?
• Data are characteristics or attributes, often numerical, collected through observation and can
be qualitative(descriptive) or quantitative(numerical). Any facts and figures about an entity is
called as Data.
• Data serves a crucial role in various sectors by facilitating analysis, supporting decision-making
processes, and being fundamental to research activities.
Slower data retrieval due to unstructured Structured querying capabilities allow for
Data Access
querying capabilities. quicker data access.
• View Level
• Database Schema:
• The database schema refers to the overall design of the database, illustrating the logical
structure and organization of data. It defines how data is organized and how relationships
between data are handled, essentially serving as the blueprint for how the database is
constructed.
• Multimedia Database: Stores data types such as images, audio, and video files,
facilitating the management and retrieval of multimedia content. A digital asset
management system like Adobe Experience Manager that facilitates the storage
and retrieval of multimedia content.
1. Internal Level: Concerns the physical storage of data in databases, overseeing data storage
on hardware devices, and managing low-level aspects like data compression and indexing.
2. Conceptual Level: Represents the logical layout of the database, detailing the schema with
tables and attributes and their interrelations. It's independent of specific DBMS
implementations, focusing on organizing and connecting data elements.
3. External Level: Embodies the user interface of the database, facilitating data access and
interaction through user-friendly views and interfaces tailored to various user groups.
• An entity may be concrete, such as a person or a book, or it may be abstract, such as a course,
a course offering, or a flight reservation.
• Tangible - Entities which physically exist in real world. E.g. - Car, Pen, locker
• Attributes are the descriptive properties possessed by each member of an entity set.
for each attribute there is a set of permitted values called domain.
• Multivalued - Attributes which can have more than one value for an entity at same time. E.g.
- Phone no, email, address.
• A multivalued attribute is represented by a double ellipse in an ER diagram and by an
independent table in a relational model.
• Separate table for each multivalued attribute, by taking mva and pk of main table as fk in
new table
जुगाड़ technology
Customer
• Composite - Attributes which can be further divided into sub parts, as simple
attributes. A composite attribute is represented by an ellipse connected to an
ellipse and in a relational model by a separate column.
• Derived -The value of these types of attributes can be derived from values of other
Attributes. E.g. - Age attribute can be derived from date_of_birth and Date attribute.
• An attribute takes a null value when an entity does not have a value for it. The null
value may indicate “not applicable”— that is, that the value does not exist for the
entity.
• Name
• Degree
• An E-R enterprise schema may define certain constraints to which the contents
of a database must conform.
• Express the number of entities to which another entity can be associated via a
relationship set. Four possible categories are-
• One to One (1:1) Relationship.
• One to Many (1: M) Relationship.
• Many to One (M: 1) Relationship.
• Many to Many (M: N) Relationship.
E.g.- The directed line from relationship set advisor to both entities set indicates that ‘an instructor
may advise at most one student, and a student may have at most one advisor’.
E.g.- This indicates that an instructor may advise many students, but a student may
have at most one advisor.
E.g.- This indicates that student may have many instructors but an instructor can
advise at most one student.
E.g.- This indicates a student may have many advisors and an instructor may advise
many students.
• Partial participation
• Total Participation
• Modification Anomalies
• Deletion Anomalies
Br_code Br_hod_name
A) A → b A B C
1 2 3
B) BC → A
4 2 3
C) B → C 5 3 3
D) AC → B
Knowledge Gate Website
• Trivial Functional dependency - If β is a subset of α, then the functional
dependency α → β will always hold.
X Y Z
जजसका होना न होना बराबर हो 1 4 2
1 4 3
2 6 3
3 2 2
• Augmentation: If X → Y, then XZ → YZ
F1+ = F2+
Or
AC → D
E → AH
E → AD
E→H
• There may be any following type of redundancy in the set of functional dependencies: -
• Complete production may be Redundant.
• One or more than one attributes may be redundant on right hand side of a production.
• One or more than one attributes may be redundant on Left hand side of a production.
A→B
C→B
D → ABC
AC → D
• Candidate key which are not chosen as primary key is alternate key.
Non-Prime attribute: - A attribute is said to be non-prime if it is not part of any of the candidate
key
Eg R(ABCD)
AB→CD
Here candidate key is AB so, A and B are prime attribute, C and D are non-prime attributes.
Full DEPENDENCY- When a non – prime attribute is dependent on the entire candidate key then
it is called Full dependency.
e.g. R(ABCD)
AB→D
A→C
• A Relation schema R consist of only prime attributes then R is always in 3NF, but
may or may not be in BCNF.
• Denoted by, A →→ B, Means, for every value of A, there may exist more than
one value of B.
• E.g. S_name → → Club_name
S_Name Club_name
Kamesh Dance
Kamesh Guitar
S_name → → Club_name
S_name → → Club_name
S_name → → P_no
NOTE: The above Student schema is in BCNF as no functional dependency holds on EMP, but
still redundancy due to MVD.
• Decomposition is lossy if R ⊃ R1 ⋈ R2
• Common attribute must be a key for at least one relation (R1 or R2)
• Att(R1) ∩ Att(R2) → (R1) or Att(R1) ∩ Att(R2) → (R2)
• Let relation R be decomposed into Relations R1, R2, R3…………. RN with their respective
functional Dependencies set as F1, F2, F3…………. FN, then the Decomposition is Dependency
Preserving iff
• {F1 ∪ F2 ∪ F3 ∪ F4………. ∪ FN }+ = F+
Index
Single
Multilevel
level
• In single-level indexing, an index file is created for the main file, marking the end
of the indexing process.
• Multiple-level indexing, on the other hand, involves creating an index for the
index file and continually repeating this procedure until only a single block
remains.
Knowledge Gate Website
PRIMARY INDEXING
• Main file is always sorted according to primary key.
• Indexing is done on Primary Key, therefore called as primary indexing
• Index file have two columns, first primary key and second anchor pointer (base
address of block)
• It is an example of Sparse Indexing.
• Here first record (anchor record) of every block gets an entry in the index file
• No. of entries in the index file = No of blocks acquired by the main file.
• Sparse Index-If an index entry is created only for some records of the main file, then it
is called sparse index. No. of index entries in the index file < No. of records in the main
file. Note: - dense and sparse are not complementary to each other, sometimes it is
possible that a record is both dense and sparse.
• A B-tree starts with a single root node (which is also a leaf node) at level 0 (zero). Once the root node is full with
m – 1 search key values and we attempt to insert another entry in the tree, the root node splits into two nodes at
level 1.
• Only the middle value is kept in the root node, and the rest of the values are split evenly between the other two
nodes. When a non-roof node is full and a new entry is inserted into it, that node is split into two nodes at the
same level, and the middle entry is moved to the parent node along with two pointers to the new split nodes.
• If the parent node is full, it is also split. Splitting can propagate all the way to the root node, creating a new level if
the root is split.
• Means user provides both what data to be retrieved and how data to be retrieved. e.g.
Relational Algebra.
• What data to be retrieved e.g. Relational Calculus. Tuple relational calculus, Domain relational
calculus are declarative query languages based on mathematical logic
3+4
A⊕B
Name Symbol
Select
(σ)
Project
(∏)
Union
(∪)
Set difference
(−)
Cross product
(Χ)
Rename
(ρ)
Knowledge Gate Website
DERIVED OPERATORS
• Union, Cartesian product and set difference operate on pairs of relations and
are, therefore, called binary operations.
• Πcolumn_name (table_name)
Q Write a RELATIONAL ALGEBRA query to find all the details of bank branches?
• It is a unary operator.
• σ condition (table_name)
Q Write a RELATIONAL ALGEBRA query to find branch name which is situated in Delhi and having
assets less than 1,00,000?
• Using the connectives and (∧), or (∨), and not (¬), we can combine several predicates into a
larger predicate.
• Minimum number of tuples selected can be 0, Maximum selected tuples can be all.
• The relations r and s must be of the same arity. That is, they must have the same number
of attributes.
• The domains of the ith attribute of r and the ith attribute of s must be the same, for all i.
Q Write a RELATIONAL ALGEBRA query to find all the customer name who have a loan but do not
have an account?
Q Write a RELATIONAL ALGEBRA query to find all the customer name who have a loan but do not
have an account?
Πcustomer_name(borrower)) - (Πcustomer_name(depositor)))
• If R1 has m tuples and R2 has n tuples the result will be having = m*n tuples.
• Same attribute name may appear in both R1 and R2, we need to devise a naming
schema to distinguish between these attributes.
• ρLearner(Student)
• r ∩ s = r − (r − s)
• Set intersection is not a fundamental operation and does not add any
power to the relational algebra.
• r ∩ s = {t | t ∈ r and t ∈ s}
Πcustomer_name(depositor)) U Πcustomer_name(borrower))
R1 R2
A B B C R1 ⋈ R2
1 P Q X A B C
2 Q R Y 2 Q X
3 R S Z 3 R Y
• Although we refer to the SQL language as a “query language,” it can do much more than just
query a database. It can define the structure of the data base, modify data in the database,
specify security constraints and number of other tasks.
• Originally based upon relational algebra(procedural) and tuple relational calculus (Non-
procedural) mathematical model.
2. The Sequel language has evolved since then, and its name has changed to SQL (Structured Query
Language) (some other company has trademark on the word sequel). SQL has clearly established itself
as the standard relational database language.
3. In 1986, the American National Standards Institute (ANSI) and the International Organization for
Standardization (ISO) published an SQL standard, called SQL-86.
4. The next version of the standard was SQL-89, SQL-92, SQL:1999, SQL:2003, SQL:2006, SQL:2008,
SQL:2011, SQL: 2016, SQL: 2019and most recently SQL:2023.
• The basic structure of an SQL query consists of three clauses: select, from, and where. The
query takes it’s input the relations listed in the from clause, operates on them as specified in
the where and select clauses, and then produces a relation as the result without any name
unless specified.
1. It is to be noted only select and from are mandatory clauses, and if not required then it is not essential to write
where. If the where clause is omitted, the predicate P is true.
2. SQL in general is not case sensitive i.e. it doesn’t matter whether we write query in upper or lower case.
3. In practice, duplicate elimination is time-consuming. Therefore, SQL allows duplicates in relations as well as in
the results of SQL expressions. In those cases where we want to force the elimination of duplicates, we insert
the keyword distinct after select, will discuss in detail later. SQL allows us to use the keyword all to specify
explicitly that duplicates are not removed, Since duplicate retention is the default, we shall not use all in our
examples.
Q Write a SQL query to find each loan number along with loan amount?
Q Write a SQL query to find the name of all customer without duplication having bank account?
Q Write a SQL query to find all account_no and balance with 6% yearly interest added to it?
Q find the name of all customer without duplication having bank account?
Select distinct customer_name
from depositor
Q find all account_no and balance with 6% yearly interest added to it?
Select account_number, balance*1.06
from account
Q Write a SQL query to find branch name which is situated in Delhi and having assets less than 1,00,000?
Q Write a SQL query to find branch name and account_no which has balance greater than equal to 1,000 but less
than equal to 10,000?
Q Write a SQL query to find branch name which is situated in Delhi and having assets less than 1,00,000?
Select branch_name
from branch
Where branch_city = ‘delhi’ and assets < 1,00,000
Q Write a SQL query to find branch name and account_no which has balance greater than equal to 1,000 but less
than equal to 10,000?
Select branch_name, account_number
from account
Where balance between 1000 and 10000
2. The union operation automatically eliminates duplicates, unlike the select clause, If we want to
retain all duplicates, we must write union all in place of union.
3. The intersect operation automatically eliminates duplicates. If we want to retain all duplicates,
we must write intersect all in place of intersect.
R1 R2
A B B C R1 ⋈ R2
1 P Q X A B C
2 Q R Y 2 Q X
3 R S Z 3 R Y
Knowledge Gate Website
Q Write a SQL query to find the name of all the customers along with account
balance, who have an account in the bank?
R1 ⟕ R2 R1 ⟖R2 R1 ⟗ R2
A B C A B C A B C
1 P null 2 Q X 1 P null
2 Q X
2 Q X 3 R Y
3 R Y
3 R Y null S Z null S Z
Q find the average balance of every account in the banks from south_delhi branch?
Select avg(balance)
from account
Where branch_name = ‘south_delhi’
Select sum(balance)/count(balance)
from account
Q find all the branch_name which are situated in Delhi in alphabetic order?
Select distinct branch_name
from branch
where branch_city = 'Delhi’
Order by branch_name aesc;
• SQL also permits a variety of functions on character strings, such as concatenating, extracting
substrings, finding the length of strings, converting strings to uppercase and lowercase,
removing spaces at the end of the string and so on. There are variations on the exact set of
string functions supported by different database systems.
Q find all the customer name who have ‘kumar’ in their name ?
Q find all the customer name who have ‘kumar’ in their name ?
Select customer_name
from customer
where customer_name like ‘%kumar%’
• like ’ab\%cd%’ escape ’\’ matches all strings beginning with “ab%cd”.
• like ’ab\\cd%’ escape ’\’ matches all strings beginning with “ab\cd”.
2. The attribute or attributes given in the group by clause are used to form groups. Tuples with
the same value on all attributes in the group by clause are placed in one group.
• Usage of Triggers
• Triggers help maintain database integrity by automatically enforcing conditions or
modifying data during database operations. They are crucial for applying business rules,
auditing database alterations, and supporting data replication, ensuring compliance before
any data insertions, updates, or deletions.
Relational
Calculus
Tuple Domain
relational relational
calculus calculus
• For every relational-algebra expression using only the basic operations, there is an
equivalent expression in the tuple relational calculus, and for every tuple-relational-
calculus expression, there is an equivalent relational algebra expression.
• Domain relational calculus also does not have any equivalent of the aggregate operation, but
it can be extended to support aggregation, and extending it to handle arithmetic expressions
is straightforward.
• READ (X) - Accessing the database item x from disk (where database stored data)
to memory variable also name as X.
• WRITE (X) - Writing the data item from memory variable X to disk.
T1
Read(A)
A = A-100
Write(A)
Read(B)
B = B+100
Write(B)
T1
Read(A)
A = A-100
Write(A)
Read(B)
B = B+100
Write(B)
• But interleaving of instructions between transactions may also lead to many problems
that can lead to inconsistent database.
• Sometimes it is possible that even though individual transaction are satisfying the acid
properties even though the final statues of the system will be inconsistent.
• So if somehow we proof that a non-serial schedule will also have same effects as of
a serial schedule than we can proof that, this particular non-serial schedule will
also be consistent.
Conflict
serializable
View
serializable
T1 T2 T1 T2 T1 T2 T1 T2
R(A) W(B) R(A) W(A)
W(B) R(A) W(A) R(A)
T1 T2 T1 T2 T1 T2 T1 T2
R(A) R(A) W(A) W(A)
R(A) R(A) W(A) W(A)
T1 T2 T1 T2
R(A) R(B)
A=A-50 B=B+50
R(B) R(A)
B=B+50 A=A-50
R(B) R(B)
B=B+50 B=B+50
R(A) R(A)
A=A+10 A=A+10
Knowledge Gate Website
SERIALIZABILITY
• Conflicting instructions - Let I and J be two consecutive instructions belonging to two different
transactions Ti and Tj in a schedule S, the possible I and J instruction can be as-
• I= READ(Q), J=READ(Q) ->Non-conflicting
• I= READ(Q), J=WRITE(Q) ->Conflicting
• I= WRITE(Q), J=READ(Q) ->Conflicting
• I= WRITE(Q), J=WRITE(Q) ->Conflicting
• So, the instructions I and J are said to be conflicting, if they are operations by different
transactions on the same data item, and at least one of these instructions is a write operation.
• If an edge Ti → Tj exists in the precedence graph, then in any serial schedule S’ equivalent to S,
Ti must appear before Tj.
• If the precedence graph for S has no cycle, then schedule S is conflict serializable, else it is
not.
• If a schedule is conflict serializable then it will also be view serializable, so we must check view
serializability only if a schedule is not conflict serializable.
• For each data item Q, if the transaction Ti reads the initial value of Q in schedule S , then then the
transaction Ti must, in schedule S’ ,also read the initial value of Q.
• If a transaction Ti in schedule S reads any data item Q, which is updated by transaction Tj, then a
transaction Ti must in schedule S’ also read data item Q updated by transaction Tj in schedule S’.
• For each data item Q, the transaction (if any) that performs the final write(Q) operation in schedule
S, then the same transaction must also perform final write(Q) in schedule S’.
Conflict
Recoverable
serializable
View
Cascadeless
serializable
Strict
S S
T1 T2 T1 T2
R(X) R(X)
W(X) W(X)
R(X) R(X)
C C
C C
Knowledge Gate Website
CASCADING ROLLBACK Vs CASCADELESS SCHEDULE
• It is a phenomenon, in which even if the schedule is recoverable, the a single transaction failure leads
to a series of transaction rollbacks, is called cascading rollback. Cascading rollback is undesirable, since
it leads to undoing of a significant amount of work. Uncommitted reads are not allowed in cascade less
schedule.
• A schedule in which for each pair of transactions Ti and Tj, such that if Tj reads a data item previously
written by Ti then the commit or abort of Ti must appear before read operation of Tj. Such a schedule
is called cascade less schedule.
S S
T1 T2 T3 T1 T2 T3
R(X) R(X)
W(X) W(X)
R(X) C
W(X) R(X)
R(X) W(X)
C C
C R(X)
C C
Knowledge Gate Website
Strict Schedule
• A schedule in which for each pair of transactions Ti and Tj, such that if Tj reads a data item
previously written by Ti then the commit or abort of Ti must appear before read and write
operation of Tj.
S1 S2 S3
T1 T2 T1 T2 T1 T2
R(a) R(a) R(a)
W(a) W(a) R(b)
W(a) C W(a)
C W(a) W(b)
R(a) R(a) C
C C R(a)
C
• Before any write operation modifies the database, a log record of that operation needs to be
created. This is to ensure that in case of a failure, the system can restore the database to a
consistent state using the log records.
Knowledge Gate Website
Aspect Deferred Database Modification Immediate Database Modification
Write Operation Timing Only at the commit point. As soon as changes occur.
In the shadow paging recovery technique, the database maintains two page tables during a
transaction: the current page table (reflecting the state before the transaction began) and the
shadow page table (which tracks changes made during the transaction). Here's how it operates:
• Initialization: When a transaction begins, the database creates a shadow copy of the page
table. The database pages themselves are not duplicated; only the page table entries are
duplicated.
• Modifications: As the transaction progresses, any changes are reflected in the current page
table, while the shadow page table retains the original state. If a page is modified, a new copy
of the page is created, and the current page table is updated to point to this new version,
thereby ensuring that the shadow page table still points to the original unmodified page.
• Recovery: In case of a system failure before the transaction commits, the database can easily
recover by discarding the current page table and reverting back to the shadow page table,
thereby restoring the database to its state before the transaction began.
• Data Replication
• Advantages: Increased Availability, Improved Performance, Enhanced Reliability
• Disadvantages: Storage Costs, Maintenance Complexity, Write Complexity.
• Data Fragmentation
• Advantages: Efficient Data Access, Distributed Processing, Localized Management.
• Disadvantages: Complexity, Dependency on Network, Reconstruction Issues.
• Lock based method: - where we ask a transaction to first lock a data item before using it. So
that no different transaction can use a data at the same time, removing any possibility of
conflict.
• 2 phase locking
1. Basic 2pl
2. Conservative 2pl
3. Rigorous 2pl
4. Strict 2pl
• Graph based protocol
• Validation based protocol – Majority of transactions are read only transactions, the rate of
conflicts among the transaction may be low, thus many of transaction, if executed without the
supervision of a concurrency control scheme, would nerveless leave the system in a consistent
state. Knowledge Gate Website
TIME STAMP ORDERING PROTOCOL
• Basic idea of time stamping is to decide the order between the transaction
before they enter in the system using a stamp (time stamp), in case of any
conflict during the execution order can be decided using the time stamp.
• Let’s understand how this protocol works, here we have two idea of
timestamping, one for the transaction, and other for the data item.
• With each transaction ti, in the system, we associate a unique fixed timestamp, denoted by
TS(ti).
• If a transaction has been assigned a timestamp TS(ti) and a new transaction tj , enters into
the system with a timestamp TS(tj), then always TS(ti) <TS(tj).
2. Second it is unique means no two transaction can have the same timestamp.
• These timestamps are updated whenever a new read(Q) or write(Q) instruction is executed.
1. If TS(Ti ) < W-timestamp(Q), then Ti needs to read a value of Q that was already
overwritten. Hence, the read operation is rejected, and Ti is rolled back.
2. If TS(Ti ) < W-timestamp(Q), then Ti is attempting to write an obsolete value of Q. Hence, this
write operation is rejected, and Ti is rolled back.
3. If TS(Ti ) ≥ R-timestamp(Q), then the write operation is executed, and W-timestamp(Q) is set to
max(W-timestamp(Q), TS(Ti )).
4. If TS(Ti ) ≥ W-timestamp(Q), then the write operation is executed, and W-timestamp(Q) is set to
max(W-timestamp(Q), TS(Ti )).
• The protocol rules for read operations remain unchanged. while for write operation, there is
slightly change in Thomas write rule than timestamp ordering protocol.
• Thomas' Write Rule allows greater potential concurrency. Allows some view-serializable
schedules that are not conflict serializable.
• Lock based protocols ensure this requirement. Idea is first obtain a lock on the
desired data item then if lock is granted then perform the operation and then
unlock it.
• Shared mode
• If transaction Ti has obtained a shared-mode lock (denoted by S) on any data item
Q, then Ti can read, but cannot write Q, any other transaction can also acquire a
shared mode lock on the same data item(this is the reason we called this shared
mode).
• Exclusive mode
• If transaction Ti has obtained an exclusive-mode lock (denoted by X) on any data
item Q, then Ti can both read and write Q, any other transaction cannot acquire
either a shared or exclusive mode lock on the same data item. (this is the reason we
called this exclusive mode)
• We shall require that each transaction in the system follow a set of rules, called a locking
protocol, indicating when a transaction may lock and unlock each of the data items for e.g. 2pl
or graph based locking.
• Growing phase- A transaction may obtain locks, but not release any locks.
• Shrinking phase- A transaction may release locks, but may not obtain any new locks.
T1 T2
LOCK-X(A)
READ(A)
WRITE(A)
LOCK-S(B)
READ(B)
LOCK-X(B)
READ(B)
WRITE(B)
LOCK-S(A)
READ(A)
UNLOCK(B)
UNLOCK(A)
UNLOCK(B)
Knowledge Gate Website
UNLOCK(A)
Conflict View Recoverability Cascadelessness Deadlock
Serializability Serializability Freedom
Rigorous 2PL
Strict 2PL
• If a schedule is allowed in 2PL protocol then definitely it is always conflict serializable. But it is
not necessary that if a schedule is conflict serializable then it will be generated by 2pl.
Equivalent serial schedule is based on the order of lock points.
• Shrinking phase will work as usual, and transaction can unlock any data item
anytime.
• This protocol requires that locking be two phase and also all the locks taken be
held by transaction until that transaction commit.
• This protocol requires that locking be two phase and also that exclusive –mode locks taken by
transaction be held until that transaction commits.
IS IX S X
IS
IX
S
X
IS IX S X
IS true true true false
IX true true false false
S true false true false
X false false false false
• A difficulty in reducing the overhead is that we do not know in advance which transactions
will be involved in a conflict. To gain that knowledge, we need a scheme for monitoring the
system.
• The validation protocol requires that each transaction Ti executes in two or three different
phases in its lifetime, depending on whether it is a read-only or an update transaction. The
phases are, in order:
Knowledge Gate Website
• Read phase. During this phase, the system executes transaction Ti. It reads the values of the
various data items and stores them in variables local to Ti. It performs all write operations on
temporary local variables, without updates of the actual database.
• Validation phase. The validation test (described below) is applied to trans- action Ti. This
determines whether Ti is allowed to proceed to the write phase without causing a violation of
serializability. If a transaction fails the validation test, the system aborts the transaction.
• Write phase. If the validation test succeeds for transaction Ti, the temporary local variables
that hold the results of any write operations performed by Ti are copied to the database.
Read-only transactions omit this phase.