简体   繁体   English

DBMS事务和可序列化

[英]DBMS Transaction and Serializable

We know: 我们知道:

A schedule in which transactions are aligned in such a way that one transaction is executed first. 一种调度,其中的事务以首先执行一个事务的方式进行排列。 When the first transaction completes its cycle then next transaction is executed. 当第一个事务完成其周期时,将执行下一个事务。 Transactions are ordered one after other. 事务被依次订购。 This type of schedule is called serial schedule as transactions are executed in a serial manner. 这种类型的日程表称为串行日程表,因为事务是以串行方式执行的。

and

This execution does no harm if two transactions are mutually independent and working on different segment of data but in case these two transactions are working on same data, results may vary . 如果两个事务相互独立并且在不同的数据段上工作,则此执行不会造成任何损害,但是如果这两个事务在相同的数据上工作,则结果可能会有所不同

so what is the benefit of finding that two transaction is Serialize Schedule? 那么,发现两个事务是序列化计划有什么好处 if the result is vary, what is the benefit ? 如果结果不同,则有什么好处?

When transactions access the same variables but are executed serially (ie not executed simultaneously) there is a sense in which "results may vary" from when there is only one transaction ever executing (possibly repeatedly). 当事务访问相同的变量但被串行执行(即不同时执行)时,从某种意义上说,与仅执行一个事务(可能重复执行)的情况相比,“结果可能会有所不同”。 With serial transactions we don't know what order the (non-overlapping) transactions are executed in. All we know at the start of the execution of a repeating transaction is that other transactions may have changed variables since the end of the last execution of the repeating transaction. 对于串行事务,我们不知道执行(非重叠)事务的顺序。在执行重复事务时,我们所知道的是,自上次执行事务结束以来,其他事务可能已更改了变量。重复交易。 (Although we generally know something about how they have been left.) (尽管我们通常对它们的保留方式有所了解。)

There is nothing wrong with such "varying results" because they just reflect that the transactions were requested at varying times. 这种“变化的结果”没有什么错,因为它们只是反映了交易是在不同时间请求的。

When transactions access the same variables and are executed simultaneously (ie not serially) then then for each transaction "results may vary" (in another sense) from how we normally understand the code. 当事务访问相同的变量并同时(即,不是串行地)执行时,则对于每个事务,“结果可能会有所不同”(换句话说),这与我们通常理解代码的方式不同。 That normal understanding relies on only one transaction executing at a time. 通常的理解是一次只执行一个事务。 Eg normally if code reads a variable twice without writing to it then we expect to get the same value. 例如,如果代码两次读取变量而不写入变量,那么我们期望得到相同的值。 But that's not guaranteed if another transaction writes to it in between reads. 但是,如果在两次读取之间有另一个事务写入该数据,则不能保证。 Eg normally if code reads a variable then we expect to get the value that the variable actually had. 例如,如果代码读取一个变量,那么通常我们希望得到该变量实际具有的值。 But that's not guaranteed if we get some of its bytes and then another transaction writes to it and then we get the rest of the bytes from that new value. 但是,如果我们得到它的一些字节,然后又有另一个事务写入它,然后再从该新值中获得其余字节,则不能保证。

But if transactions are serializable then they can be executed non-serially (with overlap) but with the same result as if they were executed serially (with no overlap). 但是,如果事务是可序列化的,那么它们可以非串行地执行(有重叠),但结果却与串行地执行(无重叠)相同。 Then code means what it normally means when there is only one transaction executing. 然后代码表示只有一个事务正在执行时的通常含义。

So we have to make sure that the system acts as if transactions are serial or else we have no idea what our program does . 因此,我们必须确保系统的行为就像事务是串行的,否则我们不知道程序会做什么

A serializable schedule is an interleaving of operations from multiple transactions that gives the same result as some serial(ized) schedule. 可序列化的时间表是对来自多个事务的操作的交织,其结果与某些序列化的时间表相同。 The benefit of executing a serializable schedule that is different from just doing all of one transaction's operations after another's is improved throughput from doing multiple operations from multiple transactions at the same time. 执行一个可序列化的计划的好处与从另一个事务中一次执行所有事务的操作不同,这可以提高吞吐量,因为它可以同时执行多个事务中的多个操作。

PS PS

Your quotes appear on a web page that is a mess. 您的报价出现在一个混乱的网页上 It doesn't even define "serializable schedule". 它甚至没有定义 “可序列化时间表”。 The text between your quotations is 引号之间的文字是

In a multi-transaction environment, serial schedules are considered as benchmark. 在多事务环境中,串行计划被视为基准。 The execution sequence of instruction in a transaction cannot be changed but two transactions can have their instruction executed in random fashion. 事务中指令的执行顺序不能更改,但是两个事务可以以随机方式执行其指令。

But the second sentence should start But in a non-serial schedule... . 但是第二句话应该以But开头, 但要以非连续的时间表...。 Because in a serial schedule "Transactions are ordered one after other." 因为在串行时间表中,“事务是一个接一个地排序的”。 So the "results may vary" in the quotation is in a non-serial schedule . 因此,报价中的“结果可能有所不同”是在非序列表中

But you did not respond to my comment: 但是您没有回应我的评论:

Does "This execution" refer to a serial execution of transactions or to a non-serial execution of transactions? “此执行”是指事务的串行执行还是事务的非串行执行? (What came before your second quote?) (在第二次报价前出现了什么?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM