数据库优先图
优先图 (Precedence graph)
A precedence graph, also known as serialization graph or conflict graph, is used for testing Conflict Serializability of a schedule in the condition that forms the setting of concurrency control in databases.
优先级图 (也称为序列化图或冲突图 )用于在形成数据库中并发控制设置的条件下测试计划的冲突可序列化性。
It is also known as a directed Graph G = (V, E), which consists of a pair of a set of nodes V = {V1, V2, V3, ..., Vn} and a set of directed edges E = {E1, E2, E3, ..., Em}. Where the set of nodes V are testing to retrieve identical data attribute through the transactions of a schedule and the set of edges E is regulated connectivity between a set of two nodes.
也称为有向图G =(V,E) ,它由一对节点集合V = {V1,V2,V3,...,Vn}和一组有向边E = { E1,E2,E3,...,Em} 。 其中,节点集V正在通过调度的事务进行测试以检索相同的数据属性,而边缘E的集是两个节点集之间受监管的连接性。
Nodes: In the graph, for each transaction Tp the graph contains a single node. So, In a schedule of a precedence graph, The total number of transactions will be similar to the total number of nodes.
节点:在图中,对于每个事务Tp ,图中都包含一个节点。 因此,在优先级图的调度中,事务的总数将类似于节点的总数。
Edges: An edge is regulated connectivity between a set of two distinct transactions Tq and Tr and it shows in the format Tq –>Tr, where Tq is the beginning of the edge and Tr is the ending.
边缘:边缘是一组两个不同的事务Tq和Tr之间的受调节连通性,它以Tq –> Tr的格式显示,其中Tq是边缘的起点,而Tr是结束。
计划的冲突可序列化性测试算法 (The Algorithm for testing Conflict Serializability of a schedule)
Create a node T, for each transaction participating in schedule S in the precedence graph.
为优先级图中参与计划S的每个事务创建一个节点T。
For every condition in schedule S create an edge Tp → Tq in the precedence graph if a Transaction Tq implements a read_item (Z) after Tp implements a write_item (Z). It's a Read-Write conflict.
在时间表中的每条件S在优先图创建的边缘TP→Tq的如果事务Tq的器具TP工具后read_item(Z)一write_item(Z)。 这是读写冲突。
For every condition in schedule S create an edge Tp → Tq in the precedence graph if a Transaction Tq implements a write_item (Z) after Ti implements a read_item (Z). It's a Write-Read conflict.
在时间表中的每条件S在优先图创建的边缘TP→Tq的如果事务Tq的器具的Ti器具后write_item(Z)一read_item(Z)。 这是一个读写冲突。
For every condition in schedule S create an edge Tp → Tq in the precedence graph If a Transaction Tq implements a write_item (Z) after Tp implements a write_item (Z). It's a Write-Write conflict.
在时间表中的每条件S在优先图创建的边缘TP→Tq的如果事务Tq的器具TP工具后write_item(Z)一write_item(Z)。 这是一个写-写冲突。
If and only if there is no cycle in the precedence graph, then the schedule S is Serializable.
当且仅当优先级图中没有周期时,调度程序S才是可序列化的。
Example:
例:
Q1) Find the following Schedule S is conflict Serializable or not?
Q1)查找以下附表S是否可序列化冲突?

Solution:
解:
Let's make a precedence graph,
让我们做一个优先级图,

In the above precedence graph, by following accordingly to the Algorithm, Transaction Tp implements reads A before Transaction Tq implements writes A, therefore the first arrow directed from Transaction Tp towards Transaction Tq and Transaction Tq reads B before Transaction Tp writes B, therefore the second arrow directed from Transaction Tq towards Transaction Tp.
另外,在上述优先图 ,通过相应地跟随该算法,事务TP工具读取A之前事务Tq的器具写入A,因此第一个箭头从交易TP指向事务Tq的和事务Tq的读取B之前事务TP写入B,因此,第二从事务Tq指向事务Tp的箭头。
Since from the above precedence graph it's clearly visible that the graph is cyclic, therefore the schedule S is not conflicted Serializable.
由于从上面的优先级图中可以清楚地看到该图是循环的,因此计划S不会与Serializable冲突。
Q2) Find the following Schedule S is conflict Serializable or not?
Q2)查找以下附表S是否可序列化冲突?

Solution:
解:
Let's make a precedence graph,
让我们做一个优先级图,

In the above precedence graph, by following accordingly to the Algorithm, Transaction Tp implements reads A before Transaction Tq implements writes A, therefore the first arrow directed.
另外,在上述优先图 ,通过相应地跟随该算法,事务TP工具读取A之前事务Tq的器具写入A,因此第一个箭头导向。
from Transaction Tp towards Transaction Tq and Transaction Tq reads B before Transaction Tr writes B, therefore the second arrow directed from Transaction Tq towards Transaction Tr and then the Transaction Tp reads C before Transaction Tr writes C, therefore the third arrow directed from Transaction Tp towards Tr.
从朝向交易Tq的和事务Tq的事务TP读取B之前事务Tr的写入B,因此,第二箭头从朝向交易Tr的事务Tq的定向,然后将事务TP读取在C之前事务Tr的写入C,因此从交易TP向定向的第三箭头Tr
Since from the above precedence graph it's clearly visible that the graph is acyclic, therefore the schedule S is conflict Serializable.
由于从上面的优先级图中可以清楚地看到该图是非循环的, 因此调度S是可序列化的冲突 。
数据库优先图