Category: Database Management System

Conflict Serializability | Practice Problems

Conflict Serializability-

 

Before you go through this article, make sure that you have gone through the previous article on Conflict Serializability.

 

We have discussed-

  • The concept of serializability helps to identify the correct non-serial schedules that will maintain the consistency of the database.
  • There are two types of serializability-

 

 

In this article, we will discuss practice problems based on conflict serializability.

 

PRACTICE PROBLEMS BASED ON CONFLICT SERIALIZABILITY-

 

Problem-01:

 

Check whether the given schedule S is conflict serializable or not-

S : R1(A) , R2(A) , R1(B) , R2(B) , R3(B) , W1(A) , W2(B)

 

Solution-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R2(A) , W1(A)              (T2 → T1)
  • R1(B) , W2(B)              (T1 → T2)
  • R3(B) , W2(B)              (T3 → T2)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists a cycle in the precedence graph.
  • Therefore, the given schedule S is not conflict serializable.

 

Problem-02:

 

Check whether the given schedule S is conflict serializable and recoverable or not-

 

 

Solution-

 

Checking Whether S is Conflict Serializable Or Not-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R2(X) , W3(X)              (T2 → T3)
  • R2(X) , W1(X)              (T2 → T1)
  • W3(X) , W1(X)             (T3 → T1)
  • W3(X) , R4(X)              (T3 → T4)
  • W1(X) , R4(X)              (T1 → T4)
  • W2(Y) , R4(Y)              (T2 → T4)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists no cycle in the precedence graph.
  • Therefore, the given schedule S is conflict serializable.

 

Checking Whether S is Recoverable Or Not-

 

  • Conflict serializable schedules are always recoverable.
  • Therefore, the given schedule S is recoverable.

 

Alternatively,

  • There exists no dirty read operation.
  • This is because all the transactions which update the values commits immediately.
  • Therefore, the given schedule S is recoverable.
  • Also, S is a Cascadeless Schedule.

 

Problem-03:

 

Check whether the given schedule S is conflict serializable or not. If yes, then determine all the possible serialized schedules-

 

 

Solution-

 

Checking Whether S is Conflict Serializable Or Not-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R4(A) , W2(A)              (T4 → T2)
  • R3(A) , W2(A)              (T3 → T2)
  • W1(B) , R3(B)              (T1 → T3)
  • W1(B) , W2(B)             (T1 → T2)
  • R3(B) , W2(B)              (T3 → T2)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists no cycle in the precedence graph.
  • Therefore, the given schedule S is conflict serializable.

 

Finding the Serialized Schedules-

 

  • All the possible topological orderings of the above precedence graph will be the possible serialized schedules.
  • The topological orderings can be found by performing the Topological Sort of the above precedence graph.

 

After performing the topological sort, the possible serialized schedules are-

  1. T1 → T3 → T4 → T2
  2. T1 → T4 → T3 → T2
  3. T4 → T1 → T3 → T2

 

Problem-04:

 

Determine all the possible serialized schedules for the given schedule-

 

 

Solution-

 

The given schedule S can be rewritten as-

 

 

This is because we are only concerned about the read and write operations taking place on the database.

 

Checking Whether S is Conflict Serializable Or Not-

 

Step-01:

 

List all the conflicting operations and determine the dependency between the transactions-

  • R1(A) , W2(A)              (T1 → T2)
  • R2(A) , W1(A)              (T2 → T1)
  • W2(A) , W1(A)             (T2 → T1)
  • R2(B) , W1(B)              (T2 → T1)
  • R1(B) , W2(B)              (T1 → T2)
  • W1(B) , W2(B)             (T1 → T2)

 

Step-02:

 

Draw the precedence graph-

 

 

  • Clearly, there exists a cycle in the precedence graph.
  • Therefore, the given schedule S is not conflict serializable.
  • Thus, Number of possible serialized schedules = 0.

 

Next Article- View Serializability in DBMS

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Serializability in DBMS | Conflict Serializability

Schedules in DBMS-

 

Before you go through this article, make sure that you have gone through the previous article on Schedules in DBMS.

 

We have discussed-

  • A schedule is the order in which the operations of multiple transactions appear for execution.
  • Serial schedules are always consistent.
  • Non-serial schedules are not always consistent.

 

In DBMS, schedules may be classified as-

 

 

In this article, we will discuss about Serializability in DBMS.

 

Serializability in DBMS-

 

  • Some non-serial schedules may lead to inconsistency of the database.
  • Serializability is a concept that helps to identify which non-serial schedules are correct and will maintain the consistency of the database.

 

Serializable Schedules-

 

If a given non-serial schedule of ‘n’ transactions is equivalent to some serial schedule of ‘n’ transactions, then it is called as a serializable schedule.

 

Characteristics-

 

Serializable schedules behave exactly same as serial schedules.

Thus, serializable schedules are always-

 

Serial Schedules Vs Serializable Schedules-

 

Serial Schedules Serializable Schedules
No concurrency is allowed.

Thus, all the transactions necessarily execute serially one after the other.

Concurrency is allowed.

Thus, multiple transactions can execute concurrently.

Serial schedules lead to less resource utilization and CPU throughput. Serializable schedules improve both resource utilization and CPU throughput.
Serial Schedules are less efficient as compared to serializable schedules.

(due to above reason)

Serializable Schedules are always better than serial schedules.

(due to above reason)

 

Types of Serializability-

 

Serializability is mainly of two types-

 

 

  1. Conflict Serializability
  2. View Serializability

 

In this article, we will discuss about Conflict Serializability.

Learn about View Serializability.

 

Conflict Serializability-

 

If a given non-serial schedule can be converted into a serial schedule by swapping its non-conflicting operations, then it is called as a conflict serializable schedule.

 

Conflicting Operations-

 

Two operations are called as conflicting operations if all the following conditions hold true for them-

  • Both the operations belong to different transactions
  • Both the operations are on the same data item
  • At least one of the two operations is a write operation

 

Example-

 

Consider the following schedule-

 

 

In this schedule,

  • W1 (A) and R2 (A) are called as conflicting operations.
  • This is because all the above conditions hold true for them.

 

Checking Whether a Schedule is Conflict Serializable Or Not-

 

Follow the following steps to check whether a given non-serial schedule is conflict serializable or not-

 

Step-01:

 

Find and list all the conflicting operations.

 

Step-02:

 

Start creating a precedence graph by drawing one node for each transaction.

 

Step-03:

 

  • Draw an edge for each conflict pair such that if Xi (V) and Yj (V) forms a conflict pair then draw an edge from Ti to Tj.
  • This ensures that Ti gets executed before Tj.

 

Step-04:

 

  • Check if there is any cycle formed in the graph.
  • If there is no cycle found, then the schedule is conflict serializable otherwise not.

 

NOTE-

 

 

Next Article- Practice Problems On Conflict Serializability

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Participation Constraints | DBMS

Participation Constraints-

 

Before you go through this article, make sure that you have gone through the previous article on Introduction to ER Diagrams.

 

Participation constraints define the least number of relationship instances in which an entity must compulsorily participate.

 

Types of Participation Constraints-

 

There are two types of participation constraints-

 

 

  1. Total participation
  2. Partial participation

 

1. Total Participation-

 

  • It specifies that each entity in the entity set must compulsorily participate in at least one relationship instance in that relationship set.
  • That is why, it is also called as mandatory participation.
  • Total participation is represented using a double line between the entity set and relationship set.

 

 

Example-

 

 

Here,

  • Double line between the entity set “Student” and relationship set “Enrolled in” signifies total participation.
  • It specifies that each student must be enrolled in at least one course.

 

Also read- Relationship Sets in DBMS and Entity Sets in DBMS

 

2. Partial Participation-

 

  • It specifies that each entity in the entity set may or may not participate in the relationship instance in that relationship set.
  • That is why, it is also called as optional participation.
  • Partial participation is represented using a single line between the entity set and relationship set.

 

 

Example-

 

 

Here,

  • Single line between the entity set “Course” and relationship set “Enrolled in” signifies partial participation.
  • It specifies that there might exist some courses for which no enrollments are made.

 

Relationship between Cardinality and Participation Constraints-

 

Minimum cardinality tells whether the participation is partial or total.

  • If minimum cardinality = 0, then it signifies partial participation.
  • If minimum cardinality = 1, then it signifies total participation.

Maximum cardinality tells the maximum number of entities that participates in a relationship set.

 

Next Article- Types of Attributes in DBMS

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Relationship Sets | DBMS

Relationship in DBMS-

 

Before you go through this article, make sure that you have gone through the previous article on Introduction to ER Diagrams.

 

A relationship is defined as an association among several entities.

 

Example-

 

‘Enrolled in’ is a relationship that exists between entities Student and Course.

 

 

Also read- Entity Sets in DBMS

 

Relationship Set-

 

A relationship set is a set of relationships of same type.

 

Example-

 

Set representation of above ER diagram is-

 

 

Degree of a Relationship Set-

 

The number of entity sets that participate in a relationship set is termed as the degree of that relationship set. Thus,

 

Degree of a relationship set = Number of entity sets participating in a relationship set

 

Types of Relationship Sets-

 

On the basis of degree of a relationship set, a relationship set can be classified into the following types-

 

 

  1. Unary relationship set
  2. Binary relationship set
  3. Ternary relationship set
  4. N-ary relationship set

 

1. Unary Relationship Set-

 

Unary relationship set is a relationship set where only one entity set participates in a relationship set.

 

Example-

One person is married to only one person

 

 

2. Binary Relationship Set-

 

Binary relationship set is a relationship set where two entity sets participate in a relationship set.

 

Example-

Student is enrolled in a Course

 

 

3. Ternary Relationship Set-

 

Ternary relationship set is a relationship set where three entity sets participate in a relationship set.

 

Example-

 

 

4. N-ary Relationship Set-

 

N-ary relationship set is a relationship set where ‘n’ entity sets participate in a relationship set.

 

Next Article- Cardinality in ER Diagram

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.

Cardinality in ER Diagram | DBMS

Cardinality Constraint-

 

Before you go through this article, make sure that you have gone through the previous article on Introduction to ER Diagrams.

 

Cardinality constraint defines the maximum number of relationship instances in which an entity can participate.

 

Types of Cardinality Ratios-

 

There are 4 types of cardinality ratios-

 

 

  1. Many-to-Many cardinality (m:n)
  2. Many-to-One cardinality (m:1)
  3. One-to-Many cardinality (1:n)
  4. One-to-One cardinality (1:1 )

 

Also read- Relationship Sets in DBMS and Entity Sets in DBMS

 

1. Many-to-Many Cardinality-

 

By this cardinality constraint,

  • An entity in set A can be associated with any number (zero or more) of entities in set B.
  • An entity in set B can be associated with any number (zero or more) of entities in set A.

 

Symbol Used-

 

 

Example-

 

Consider the following ER diagram-

 

 

Here,

  • One student can enroll in any number (zero or more) of courses.
  • One course can be enrolled by any number (zero or more) of students.

 

2. Many-to-One Cardinality-

 

By this cardinality constraint,

  • An entity in set A can be associated with at most one entity in set B.
  • An entity in set B can be associated with any number (zero or more) of entities in set A.

 

Symbol Used-

 

 

Example-

 

Consider the following ER diagram-

 

 

Here,

  • One student can enroll in at most one course.
  • One course can be enrolled by any number (zero or more) of students.

 

3. One-to-Many Cardinality-

 

By this cardinality constraint,

  • An entity in set A can be associated with any number (zero or more) of entities in set B.
  • An entity in set B can be associated with at most one entity in set A.

 

Symbol Used-

 

 

Example-

 

Consider the following ER diagram-

 

 

Here,

  • One student can enroll in any number (zero or more) of courses.
  • One course can be enrolled by at most one student.

 

4. One-to-One Cardinality-

 

By this cardinality constraint,

  • An entity in set A can be associated with at most one entity in set B.
  • An entity in set B can be associated with at most one entity in set A.

 

Symbol Used-

 

 

Example-

 

Consider the following ER diagram-

 

 

Here,

  • One student can enroll in at most one course.
  • One course can be enrolled by at most one student.

 

Next Article- Participation Constraints

 

Get more notes and other study material of Database Management System (DBMS).

Watch video lectures by visiting our YouTube channel LearnVidFun.