📜  冲突和视图可序列化之间的区别

📅  最后修改于: 2021-09-28 11:04:28             🧑  作者: Mango

先决条件 – DBMS 中的计划类型

可序列化的时间表:
如果事务调度的结果等于其连续执行的事务的结果,即在时间上没有重叠,则事务调度是可串行化的。可序列化的调度始终使数据库处于一致状态。串行调度始终是可序列化的调度,因为新事务仅在旧事务完成执行后才开始。

例子 –
让我们考虑以下时间表,看看它是否可序列化。

T1 T2
  R(X)
R(X)  
  R(Y)
  W(Y)
R(Y)  
W(X)  

现在,让我们弄清楚上述计划是否可序列化。

  1. 交换 T1 的 R(X) 和 T2 的 R(Y)。
  2. 交换 T1 的 R(X) 和 T2 的 W(Y)。
T1 T2
  R(X)
  R(Y)
  W(Y)
R(X)  
R(Y)  
W(X)  

因此,在更改初始调度中的冲突操作后,我们得到了一个串行调度。因此,这个调度是可序列化的。

可序列化计划的类型:

  1. 结果等效时间表
  2. 冲突等价调度或冲突可串行化
  3. 查看等效计划或查看可序列化性

Conflict 和 View Serializability 的区别:

S.No. Conflict Serializability View Serializability
1. Two schedules are said to be conflict equivalent if all the conflicting operations in both the schedule get executed in the same order. If a schedule is a conflict equivalent to its serial schedule then it is called Conflict Serializable Schedule. Two schedules are said to be view equivalent if the order of initial read, final write and update operations is the same in both the schedules. If a schedule is view equivalent to its serial schedule then it is called View Serializable Schedule.
2. If a schedule is view serializable then it may or may not be conflict serializable. If a schedule is conflict serializable then it is also view serializable schedule.
3. Conflict equivalence can be easily achieved by reordering the operations of two transactions therefore, Conflict Serializability is easy to achieve. Viewequivalence is rather difficult to achieve as both transactions should perform similar actions in a similar manner. Thus, View Serializability is difficult to achieve.
4. For a transaction T1 writing a value A that no one else reads but later some other transactions say T2 write its own value of A, W(A) cannot be placed under positions where it is never read. If a transaction T1 writes a value A that no other transaction reads (because later some other transactions say T2 writes its own value of A) W(A) can be placed in positions of the schedule where it is never read.

冲突可串行化示例 –
让我们考虑以下事务调度并测试它的 Conflict Serializable

T1 T2 T3
  R(X)  
    R(X)
W(Y)    
  W(X)  
    R(Y)
  W(Y)  

现在,我们将列出所有冲突的操作。此外,我们将使用 Precedence Graph 确定调度是否是冲突可序列化的。

如果两个操作属于不同的事务,对相同的数据进行操作,并且其中至少一个是写操作,则称这两个操作是冲突的。

  1. R3(X) 和 W2(X) [ T3 -> T2 ]
  2. W1(Y) 和 R3(Y) [ T1 -> T3 ]
  3. W1(Y) 和 W2(Y) [ T1 -> T2 ]
  4. R3(Y) 和 W2(Y) [ T3 -> T2 ]

构建优先图,我们看到图中没有环。因此,调度是冲突可序列化的。

可序列化的时间表是,

T1 -> T3 -> T2 

视图可序列化示例 –
让我们考虑以下事务调度并测试它的 View Serializability。

T1 T2 T3
R(A)    
  W(A)  
    R(A)
W(A)    
    W(A)

我们知道,如果调度是冲突可序列化的,那么它也是视图可序列化的。所以首先让我们检查 Conflict Serializability。

此时间表的冲突操作是 –

  1. R1(A) 和 W2(A) [ T1 -> T2 ]
  2. R1(A) 和 W2(A) [ T1 -> T3 ]
  3. W2(A) 和 R3(A) [ T2 -> T3 ]
  4. W2(A) 和 W1(A) [ T2 -> T1 ]
  5. W2(A) 和 W3(A) [ T2 -> T3 ]
  6. R3(A) 和 W1(A) [ T3 -> T1 ]
  7. W3(A) 和 W1(A) [ T1 -> T3 ]

为调度中的冲突操作构建优先级图。

我们可以看到优先级图中有一个循环,这意味着给定的时间表不是 Conflict Serializable。现在,在检查盲写时,我们发现在给定的调度中存在盲写 W2(A)。因此,时间表可能是也可能不是视图可序列化的。

为了检查视图的可序列化性,我们将绘制时间表的依赖关系图。从给定的时间表中,我们收集了以下几点:

  1. T1 在 T2 更新 A 之前读取 A,因此,T1 必须在 T2 之前执行。
  2. T3 对 A 进行最终更新,因此它必须在最后执行。

构建依赖图。

由于图中不存在环,我们可以说给定的时间表是 View Serializable。
可序列化的时间表是 T1 -> T2 -> T3。