浙江大学数据库系统概念PPT第十五章.ppt
《浙江大学数据库系统概念PPT第十五章.ppt》由会员分享,可在线阅读,更多相关《浙江大学数据库系统概念PPT第十五章.ppt(31页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Silberschatz,Korth and Sudarshan,Bo Zhou15.1Database System ConceptsChapter 15:TransactionsnTransaction ConceptnConcurrent ExecutionsnSerializabilitynTesting for SerializabilitynRecoverabilitynTransaction Definition in SQLSilberschatz,Korth and Sudarshan,Bo Zhou15.2Database System ConceptsTransactio
2、n ConceptnE.g.Transaction to transfer$50 from account A to account B:1.read(A)4.read(B)2.A:=A 505.B:=B+503.write(A)6.write(BnA transaction is a unit of program execution that accesses and possibly updates various data items.A transaction must see a consistent database.During transaction execution th
3、e database may be inconsistent.When the transaction is committed,the database must be consistent.nTwo main issues to deal with:Failures of various kinds,such as hardware failures and system crashesConcurrent execution of multiple transactionsSilberschatz,Korth and Sudarshan,Bo Zhou15.3Database Syste
4、m ConceptsACID PropertiesnAtomicity.Either all operations of the transaction are properly reflected in the database or none are.Commit a transactionRollback a transactionnConsistency.Execution of a transaction in isolation preserves the consistency of the database.nIsolation.Although multiple transa
5、ctions may execute concurrently,each transaction must be unaware of other concurrently executing transactions.Intermediate transaction results must be hidden from other concurrently executed transactions.nDurability.After a transaction completes successfully,the changes it has made to the database p
6、ersist,even if there are system failures.To preserve integrity of data,the database system must ensure:Silberschatz,Korth and Sudarshan,Bo Zhou15.4Database System ConceptsExample of Fund TransfernTransaction to transfer$50 from account A to account B:1.read(A)2.A:=A 503.write(A)4.read(B)5.B:=B+506.w
7、rite(B)nConsistency requirement the sum of A and B is unchanged by the execution of the transaction.nAtomicity requirement if the transaction fails after step 3 and before step 6,the system should ensure that its updates are not reflected in the database,else an inconsistency will result.Failure cou
8、ld be due to software or hardwareSilberschatz,Korth and Sudarshan,Bo Zhou15.5Database System ConceptsExample of Fund Transfer(Cont.)nDurability requirement once the user has been notified that the transaction has completed(i.e.,the transfer of the$50 has taken place),the updates to the database by t
9、he transaction must persist despite failures.nIsolation requirement if between steps 3 and 6,another transaction is allowed to access the partially updated database,it will see an inconsistent database(the sum A+B will be less than it should be).Can be ensured trivially by running transactions seria
10、lly,that is one after the other.However,executing multiple transactions concurrently has significant benefits,as we will see.Silberschatz,Korth and Sudarshan,Bo Zhou15.6Database System ConceptsConcurrent ExecutionsnMultiple transactions are allowed to run concurrently in the system.Advantages are:in
11、creased processor and disk utilization,leading to better transaction throughput:one transaction can be using the CPU while another is reading from or writing to the diskreduced average response time for transactions:short transactions need not wait behind long ones.nConcurrency control schemes mecha
12、nisms to achieve isolation,i.e.,to control the interaction among the concurrent transactions in order to prevent them from destroying the consistency of the databaseSilberschatz,Korth and Sudarshan,Bo Zhou15.7Database System ConceptsConsistency problems of concurrent Consistency problems of concurre
13、nt Execution without controlExecution without controlnLost modification:nDirty Read:T1T21Read(x)2Read(x)3X=x+14Write(x)X=x*25Write(x)T1T21Write(T)2Read(T)3rollbackSilberschatz,Korth and Sudarshan,Bo Zhou15.8Database System ConceptsConsistency problems(Cont.)nNon repeatable readT1T21Read(x)2Write(x)3
14、Read(x)X?Silberschatz,Korth and Sudarshan,Bo Zhou15.9Database System ConceptsSchedulesnSchedules sequences that indicate the chronological order in which instructions of concurrent transactions are executeda schedule for a set of transactions must consist of all instructions of those transactionsmus
15、t preserve the order in which the instructions appear in each individual transaction.nSome notions:Serial ScheduleEquivalent scheduleSerializable ScheduleSilberschatz,Korth and Sudarshan,Bo Zhou15.10Database System ConceptsExample SchedulesnLet T1 transfer$50 from A to B,and T2 transfer 10%of the ba
16、lance from A to B.The following is a serial schedule(Schedule 1 in the text),in which T1 is followed by T2.Silberschatz,Korth and Sudarshan,Bo Zhou15.11Database System ConceptsExample Schedule(Cont.)nLet T1 and T2 be the transactions defined previously.The following schedule(Schedule 3 in the text)i
17、s not a serial schedule,but it is equivalent to Schedule 1.In both Schedule 1 and 3,the sum A+B is preserved.Silberschatz,Korth and Sudarshan,Bo Zhou15.12Database System ConceptsExample Schedules(Cont.)nThe following concurrent schedule(Schedule 4 in the text)does not preserve the value of the the s
18、um A+B.Silberschatz,Korth and Sudarshan,Bo Zhou15.13Database System ConceptsSerializabilitynBasic Assumption Each transaction preserves database consistency.We ignore operations other than read and write instructions,and we assume that transactions may perform arbitrary computations on data in local
19、 buffers in between reads and writes.Our simplified schedules consist of only read and write instructions.nThus serial execution of a set of transactions preserves database consistency.nA(possibly concurrent)schedule is serializable if it is equivalent to a serial schedule.nHow to determine a schedu
20、le is equivalent to a serial schedule?Different forms of schedule equivalence give rise to the notions of:1.conflict serializability2.view serializabilitySilberschatz,Korth and Sudarshan,Bo Zhou15.14Database System ConceptsConflict SerializabilitynInstructions li and lj of transactions Ti and Tj res
21、pectively,conflict if and only if there exists some item Q accessed by both li and lj,and at least one of these instructions wrote Q.1.li=read(Q),lj=read(Q).li and lj dont conflict.2.li=read(Q),lj=write(Q).They conflict.3.li=write(Q),lj=read(Q).They conflict4.li=write(Q),lj=write(Q).They conflictnIn
22、tuitively,a conflict between li and lj forces a(logical)temporal order between them.If li and lj are consecutive in a schedule and they do not conflict,their results would remain the same even if they had been interchanged in the schedule.Silberschatz,Korth and Sudarshan,Bo Zhou15.15Database System
23、ConceptsConflict Serializability(Cont.)nIf a schedule S can be transformed into a schedule S by a series of swaps of non-conflicting instructions,we say that S and S are conflict equivalent.nWe say that a schedule S is conflict serializable if it is conflict equivalent to a serial schedulenExample o
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 浙江大学 数据库 系统 概念 PPT 第十五
限制150内