数据库优先图_优先图| 数据库管理系统

优先图(Precedence graph)是数据库并发控制中的概念,用于测试计划的冲突可序列化性。它是一个有向图,包含表示事务的节点和表示冲突的边。如果优先图中无环,则计划是可序列化的。本文介绍了冲突可序列化性的测试算法,并通过例子展示了如何构建和分析优先图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

数据库优先图

优先图 (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.

边缘:边缘是一组两个不同的事务TqTr之间的受调节连通性,它以Tq –> Tr的格式显示,其中Tq是边缘的起点,而Tr是结束。

计划的冲突可序列化性测试算法 (The Algorithm for testing Conflict Serializability of a schedule)

  1. Create a node T, for each transaction participating in schedule S in the precedence graph.

    优先级图中参与计划S的每个事务创建一个节点T。

  2. 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)。 这是读写冲突。

  3. 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)。 这是一个读写冲突。

  4. 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)。 这是一个写-写冲突。

  5. 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是否可序列化冲突?

precedence graph in DBMS

Solution:

解:

Let's make a precedence graph,

让我们做一个优先级图,

precedence graph in DBMS

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是否可序列化冲突?

precedence graph in DBMS

Solution:

解:

Let's make a precedence graph,

让我们做一个优先级图,

precedence graph in DBMS

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是可序列化的冲突

翻译自: https://www.includehelp.com/dbms/precedence-graph.aspx

数据库优先图

Vite + Vue 3 + TypeScript 的项目中,你可以使用 Vue Router 来处理路由调用接口。 首先,确保你已经安装了 Vue Router 和 axios(或其他用于发送 HTTP 请求的库)。你可以使用以下命令进行安装: ``` npm install vue-router axios ``` 接下来,在你的项目中创建一个 `router` 文件夹,在其中创建一个 `index.ts` 文件。在该文件中,你可以配置你的路由。以下是一个示例: ```typescript import { createRouter, createWebHistory, RouteRecordRaw } from &#39;vue-router&#39;; import Home from &#39;@/views/Home.vue&#39;; import About from &#39;@/views/About.vue&#39;; const routes: Array<RouteRecordRaw> = [ { path: &#39;/&#39;, name: &#39;Home&#39;, component: Home, }, { path: &#39;/about&#39;, name: &#39;About&#39;, component: About, }, ]; const router = createRouter({ history: createWebHistory(), routes, }); export default router; ``` 在上面的示例中,我们定义了两个路由:`Home` 和 `About`。你可以根据你的需求进行修改和扩展。 然后,在你的入口文件(如 `main.ts`)中,引入使用你的路由: ```typescript import { createApp } from &#39;vue&#39;; import App from &#39;./App.vue&#39;; import router from &#39;./router&#39;; const app = createApp(App); app.use(router); app.mount(&#39;#app&#39;); ``` 现在,你可以在你的组件中使用 `vue-router` 进行路由导航和调用接口。例如,在 `Home.vue` 组件中,你可以这样使用: ```vue <template> <div> <h1>Home</h1> <button @click="fetchData">Fetch Data</button> </div> </template> <script> import axios from &#39;axios&#39;; export default { methods: { fetchData() { axios.get(&#39;/api/data&#39;).then((response) => { console.log(response.data); }).catch((error) => { console.error(error); }); }, }, }; </script> ``` 在上面的示例中,我们使用了 axios 发送 GET 请求来获取数据。你可以根据你的需求调整和扩展这个例子。 希望这能帮助到你!如果你有任何其他问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值