安徽工业大学数据库第十一章习题解答

合集下载

2022年安徽工业大学数据科学与大数据技术专业《数据库系统原理》科目期末试卷A(有答案)

2022年安徽工业大学数据科学与大数据技术专业《数据库系统原理》科目期末试卷A(有答案)

2022年安徽工业大学数据科学与大数据技术专业《数据库系统原理》科目期末试卷A(有答案)一、填空题1、关系代数运算中,基本的运算是______________、______________、______________、______________和______________。

2、在SQL Server 2000中,某数据库用户User在此数据库中具有对T 表数据的查询和更改权限。

现要收回User对T表的数据更改权,下述是实现该功能的语句,请补全语句。

_____UPDATE ON T FROM User;3、关系系统的查询优化既是关系数据库管理系统实现的关键技术,又是关系系统的优点。

因为,用户只要提出______,不必指出 ______。

4、在SQL Server 2000中,数据页的大小是8KB。

某数据库表有1000行数据,每行需要5000字节空间,则此数据库表需要占用的数据页数为_____页。

5、SQL语言的数据定义功能包括______、______、______和______。

6、如果多个事务依次执行,则称事务是执行______;如果利用分时的方法,同时处理多个事务,则称事务是执行______。

7、数据仓库是______、______、______、______的数据集合,支持管理的决策过程。

8、设有关系模式R(A,B,C)和S(E,A,F),若R.A是R的主码,S.A是S的外码,则S.A的值或者等于R中某个元组的主码值,或者______取空值,这是规则,它是通过______和______约束来实现的。

9、视图是一个虚表,它是从______导出的表。

在数据库中,只存放视图的______,不存放视图对应的______。

10、数据库系统是利用存储在外存上其他地方的______来重建被破坏的数据库。

方法主要有两种:______和______。

二、判断题11、一个数据表只能有一个唯一索引。

()12、在数据表中,空值表示不确定。

国开学习网电大数据库应用技术第11章测验答案

国开学习网电大数据库应用技术第11章测验答案

国开学习网电大数据库应用技术第11章测验答案以下是对国开研究网电大数据库应用技术第11章测验的答案:1. 数据库事务具有ACID特性,即原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability)。

3. 数据库的并发控制机制包括两阶段封锁(Two-Phase Locking)、时间戳(Timestamp)和多版本并发控制(MVCC)。

4. 数据库索引是一种用于加快数据访问速度的数据结构。

常见的索引类型有B树索引、哈希索引和位图索引。

5. 在数据库设计中,关系模型用于描述数据之间的关联关系。

关系模型包括实体(Entity)、属性(Attribute)和关系(Relationship)。

6. SQL(Structured Query Language)是一种用于管理关系型数据库的编程语言。

SQL可以用于创建、查询和操作数据库中的数据。

7. 数据库触发器(Trigger)是一种在特定事件发生时自动执行的程序。

触发器可以用于实现数据的自动更新和完整性约束。

8. 数据库备份是一种用于保护数据免受数据丢失的措施。

常见的数据库备份方式包括完全备份、增量备份和差异备份。

9. 数据库性能优化是一种通过优化数据库结构和查询语句,提高数据库查询性能和响应速度的方法。

常见的优化手段包括索引优化和查询优化。

10. 数据库安全性是指保护数据库免受非法访问和数据泄露的一种措施。

常见的数据库安全措施包括访问控制、加密和审计。

以上就是对国开研究网电大数据库应用技术第11章测验的答案。

如有其他问题,请随时咨询。

历年安徽工业大学数据库原理样卷及答案

历年安徽工业大学数据库原理样卷及答案

安徽工业大学数据库原理样卷总分:100分考试时间:90分钟注意事项:➢考试过程中如遇问题请及时向监考老师反馈。

➢部分学科有选作题,注意按题目要求进行作答,如有选项框,请使用2B铅笔将选定题目对应的选项框涂满涂黑,不得多涂或漏涂。

➢考试结束信号发出后,要立即停笔并起立。

一、单项选择题(每小题2 分,共 40分)1、在3级模式之间引入两级映射,其主要功能之一就是( )。

A、使数据与程序具有较高的独立性B、使系统具有较高的通道能力C、保持数据与程序的一致性D、提高存储空间的利用率【答案】A2、以下()内存区不属于SGA。

A、PGAB、日志缓冲区C、数据缓冲区D、共享池【答案】A3、下面叙述中正确的是( )。

A、网状模型和关系模型都是格式化的数据模型B、"授权"是数据库系统中采用的完整性措施之一C、数据的的完整性是指保护数据以防止不合法的使用D、用对关系的运算来表示表达查询的语言称为代数式语言,简称关系代数【答案】D4、实现将现实世界抽象为信息世界的是( )A、物理模型B、概念模型C、关系模型D、逻辑模型【答案】B5、消除了非主属性对候选键的部分函数依赖的关系模式,就是A、1NFB、2NFC、3NFD、BCNF【答案】B6、有关三个世界中数据的描述术语,“实体”是()。

A、对现实世界数据信息的描述B、对信息世界数据信息的描述C、对计算机世界数据信息的描述D、对三个世界间相互联系的描述【答案】B7、关于层次模型及网状模型正确的说法是( )A、层次结构中数据结构用有向树表示,可以直观的描述任何层次与非层次的系统B、网状结构不能表达实体间多对多的联系点C、在层次结构和网状结构的数据库模式设计中包含了物理存储细节,因而降低了数的独立性D、网状模型、层次模型和关系模型是目前仍在使用的DBMS的三种数据模型【答案】D8、在SELECT语句中使用MAX(列名)时,列名应该( )A、必须是数值型B、必须是字符型C、必须是数值型或字符型D、不限制数据类型【答案】D9、MySQL 支持的用户自定义完整性约束不包括A、非空约束B、CHECK 约束C、触发器D、视图【答案】D10、当程序中执行了 SELECT... FOR UPDATE ,以下描述正确的是()。

习题答案 自编教材 52+12 讲义 大纲模式

习题答案 自编教材 52+12 讲义 大纲模式

数据库系统概论习题参考答案An Introduction to Database System安徽工业大学授课教师:周兵选用教材:《数据库系统及应用》,戴小平,中国科技大学出版社,2010.8.参考书目:1、《Date C J, An Introduction to Database System》(Ed.7), Addison-Wesley,20002、《数据库系统原理教程》,王珊,陈红:清华大学出版社,20003、《数据库系统概论》(第四版),萨师煊,王珊, 高等教育出版社,2006 中国人民大学说明:斜体部分是可选讲授内容, 带星号的习题为可选。

第 1 章数据库基础1.1习题P22A.1 1.2试述数据库、数据库系统、数据库管理系统这几个概念。

答案:B.1数据库数据库是关于企业或组织的全部数据的集合。

数据库包含两部分:一是对数据结构的所有描述,存储于数据字典之中,二是数据数据本身,它是数据库的主体。

B.2数据库系统数据库系统是指在计算机系统中引入数据库后的系统构成,由数据库、数据库管理系统、运行环境、数据库管理员和用户构成。

B.3数据库管理系统数据库管理系统是位于用户与操作系统之间的一层数据管理软件,负责数据库管理和维护的软件系统。

A.2 1.3试述数据管理技术的三个阶段,及其特点。

答案:B.1手工管理阶段数据的组织和管理完全靠程序员手工完成,因此称为手工管理阶段。

这个阶段数据的管理效率很低。

C.1特点:D.1数据不保存。

D.2应用程序管理数据。

D.3数据不共享。

D.4数据不具有独立性。

B.2文件系统阶段在文件系统中,按一定的规则将数据组织成为一个文件,应用程序通过文件系统对文件中的数据进行存取和加工。

C.1特点:D.1数据可以长期保留。

D.2数据不属于某个特定的应用程序。

D.3文件组织形式的多样化。

D.4数据冗余度大。

D.5数据不一致性。

D.6数据联系弱。

B.3数据库系统阶段数据库技术克服了以前所有管理方式的缺点,试图提供一种完善的、更高级的数据管理方式。

数据库系统概论习题及答案-其它题

数据库系统概论习题及答案-其它题

数据库系统概论习题及答案-其它题(共13页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--数据库系统概论复习资料:第一章假设教学管理规定:①一个学生可选修多门课,一门课有若干学生选修;②一个教师可讲授多门课,一门课只有一个教师讲授;③一个学生选修一门课,仅有一个成绩。

学生的属性有学号、学生姓名;教师的属性有教师编号,教师姓名;课程的属性有课程号、课程名。

要求:根据上述语义画出ER图,要求在图中画出实体的属性并注明联系的类型;第2章关系数据库1、设有如下所示的关系S(S#,SNAME,AGE,SEX)、C(C#,CNAME,TEACHER)和SC(S#,C#,GRADE),试用关系代数表达式表示下列查询语句:(1)检索“程军”老师所授课程的课程号(C#)和课程名(CNAME)。

(2)检索年龄大于21的男学生学号(S#)和姓名(SNAME)。

(3)检索至少选修“程军”老师所授全部课程的学生姓名(SNAME)。

(4)检索”李强”同学不学课程的课程号(C#)。

(5)检索至少选修两门课程的学生学号(S#)。

(6)检索全部学生都选修的课程的课程号(C#)和课程名(CNAME)。

(7)检索选修课程包含“程军”老师所授课程之一的学生学号(S#)。

(8)检索选修课程号为k1和k5的学生学号(S#)。

(9)检索选修全部课程的学生姓名(SNAME)。

(10)检索选修课程包含学号为2的学生所修课程的学生学号(S#)。

(11)检索选修课程名为“C语言”的学生学号(S#)和姓名(SNAME)。

解:本题各个查询语句对应的关系代数表达式表示如下:(1). ∏C#,CNAME(σTEACHER=‘程军’(C))(2). ∏S#,SNAME(σAGE>21∧SEX=”男”(C)) (3). ∏SNAME{s[∏S#,C#(sc )÷∏C#(σTEACHER=‘程军’(C))]}(4). ∏C#(C)- ∏C#(σSNAME=‘李强’(S) SC)(5). ∏S#(σ[1]=[4]∧[2]≠[5] (SC × SC))(6). ∏C#,CNAME(C (∏S#,C#(sc)÷∏S#(S)))(7). ∏S#(SC∏C#(σTEACHER=‘程军’(C)))(8). ∏S#,C#(sc )÷∏C#(σC#=’k1’∨ C#=’k5’(C)) (9). ∏SNAME{s[∏S#,C#(sc )÷∏C#(C)]}(10). ∏S#,C#(sc )÷∏C#(σS#=’2’(SC))(11). ∏S#,SNAME{s[∏S#(SCσCNAME=‘C 语言’(C))]}2、关系R 和S 如下图所示,试计算R ÷S 。

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第11章

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第11章

2Chapter11Indexing and Hashingb.c.11.4Answer:•With structure11.3.a:Insert9:10:InsertExercises3Delete23:Delete19:•With structure11.3.b:Insert9:Insert4Chapter 11Indexing and HashingDelete23:Delete 19:•With structure 11.3.c:Insert9:Insert10:Insert8:Delete 23:Delete 19:Exercises511.5Answer:If there are K search-key values and m −1siblings are involvedin the redistribution,the expected height of the tree is:log ⌊(m −1)n /m ⌋(K )11.6Answer:Extendable hash structure000 001010 011 100101 110 11111.7Answer:a.Delete 11:From the answer to Exercise 11.6,change the third bucketto:At this stage,it is possible to coalesce the second and third buckets.Then it is enough if the bucket address table has just four entriesinstead of eight.For the purpose of this answer,we do not do the coalescing.b.Delete 31:From the answer to 11.6,change the last bucket to:6Chapter11Indexing and Hashingc.Insert1:From the answer to11.6,change thefirst bucket to:d.Insert15:From the answer to11.6,change the last bucket to:11.8Answer:The pseudocode is shown in Figure11.1.11.9Answer:Let i denote the number of bits of the hash value used in thehash table.Let bsize denote the maximum capacity of each bucket.Thepseudocode is shown in Figure11.2.Note that we can only merge two buckets at a time.The common hashprefix of the resultant bucket will have length one less than the two bucketsmerged.Hence we look at the buddy bucket of bucket j differing from itonly at the last bit.If the common hash prefix of this bucket is not i j,thenthis implies that the buddy bucket has been further split and merge is notpossible.When merge is successful,further merging may be possible,which is handled by a recursive call to coalesce at the end of the function.11.10Answer:If the hash table is currently using i bits of the hash value,thenmaintain a count of buckets for which the length of common hash prefixis exactly i.Consider a bucket j with length of common hash prefix i j.If the bucketis being split,and i j is equal to i,then reset the count to1.If the bucketis being split and i j is one less that i,then increase the count by1.It thebucket if being coalesced,and i j is equal to i then decrease the count by1.If the count becomes0,then the bucket address table can be reduced insize at that point.However,note that if the bucket address table is not reduced at that point,then the count has no significance afterwards.If we want to postpone thereduction,we have to keep an array of counts,i.e.a count for each value ofExercises7 functionfindIterator(value V){/*Returns an iterator for the search on the value V*/Iterator iter();Set iter.v alue=V;Set C=root nodewhile(C is not a leaf node)beginLet i=samllest number such that V<=C.K iif there is no such number i then beginLet P m=last non-null pointer in the nodeSet C=C.P m;endelse Set C=C.P i;end/*C is a leaf node*/Let i be the least value such that K i=Vif there is such a value i then beginSet iter.index=i;Set iter.page=C;Set iter.acti v e=T RUE;endelse if(V is the greater than the largest value in the leaf)then beginif(C.P n.K1=V)then beginSet iter.page=C.P n;Set iter.index=1;Set iter.acti v e=T RUE;endelse Set iter.acti v e=F AL SE;endelse Set iter.acti v e=F AL SE;return(iter)}Class Iterator{variables:value V/*The value on which the index is searched*/boolean active/*Stores the current state of the iterator(TRUE or FALSE)*/int index/*Index of the next matching entry(if active is TRUE)*/PageID page/*Page Number of the next matching entry(if active is TRUE)*/ function next(){if(active)then beginSet ret Page=page;Set retI ndex=index;if(index+1=page.size)then beginpage=page.P nindex=0endelse index=index+1;if(page.K index=V)then acti v e=F AL SE;return(ret Page,retI ndex)endelse return null;}}Figure11.1Pseudocode forfindIterator and the Iterator class8Chapter11Indexing and Hashingdelete(value K l)beginj=first i high-order bits of h(K l);delete value K l from bucket j;coalesce(bucket j);endcoalesce(bucket j)begini j=bits used in bucket j;k=any bucket withfirst(i j−1)bits same as thatof bucket j while the bit i j is reversed;i k=bits used in bucket k;if(i j=i k)return;/*buckets cannot be merged*/if(entries in j+entries in k>bsize)return;/*buckets cannot be merged*/move entries of bucket k into bucket j;decrease the value of i j by1;make all the bucket-address-table entries,which pointed to bucket k,point to j;coalesce(bucket j);endFigure11.2Pseudocode for deletioncommon hash prefix.The array has to be updated in a similar fashion.Thebucket address table can be reduced if the i th entry of the array is0,wherei is the number of bits the table is using.Since bucket table reduction isan expensive operation,it is not always advisable to reduce the table.Itshould be reduced only when sufficient number of entries at the end ofcount array become0.11.11Answer:We reproduce the instructor relation below.Exercises9 ID dept salary10101Comp.Sci.Wu9000015151MusicEinstein9500032343HistoryGold8700045565Comp.Sci.Califieri6200076543FinanceCrick7200083821Comp.Sci.Kim80000a.Bitmap for salary,with S1,S2,S3and S4representing the given inter-vals in the same orderS1000000000000S3010*********b.The question is a bit trivial if there is no bitmap on the deptname attribute is:Comp.Sci010********* Music000101000000 History000000000100 Elec.Eng.010********* Finance010*********10Chapter11Indexing and HashingScan on these records with salary80000or more gives Wu and Singhas the instructors who satisfy the given query.11.12Answer:If the index entries are inserted in ascending order,the newentries get directed to the last leaf node.When this leaf node getsfilled,it is split into two.Of the two nodes generated by the split,the left nodeis left untouched and the insertions takes place on the right node.Thismakes the occupancy of the leaf nodes to about50percent,except the lastleaf.If keys that are inserted are sorted in descending order,the above situationwould still occur,but symmetrically,with the right node of a split nevergetting touched again,and occupancy would again be50percent for allnodes other than thefirst leaf.11.13Answer:a.The cost to locate the page number of the required leaf page foran insertion is negligible since the non-leaf nodes are in memory.On the leaf level it takes one random disk access to read and onerandom disk access to update it along with the cost to write onepage.Insertions which lead to splitting of leaf nodes require anadditional page write.Hence to build a B+-tree with n r entries ittakes a maximum of2∗n r random disk accesses and n r+2∗(n r/f)page writes.The second part of the cost comes from the fact that inthe worst case each leaf is halffilled,so the number of splits thatoccur is twice n r/f.The above formula ignores the cost of writing non-leaf nodes,sincewe assume they are in memory,but in reality they would also bewritten eventually.This cost is closely approximated by2∗(n r/f)/f,which is the number of internal nodes just above the leaf;we canadd further terms to account for higher levels of nodes,but these aremuch smaller than the number of leaves and can be ignored.b.Substituting the values in the above formula and neglecting the costfor page writes,it takes about10,000,000∗20milliseconds,or56hours,since each insertion costs20milliseconds.Exercises11c.function insert leaf(value K,pointer P)if(tree is empty)create an empty leaf node L,which is also the rootelse Find the last leaf node in the leaf nodes chain Lif(L has less than n−1key values)then insert(K,P)at thefirst available location in Lelse beginCreate leaf node L1Set L.P n=L1;Set K1=last value from page Linsert parent(1,L,K1,L1)insert(K,P)at thefirst location in L1endfunction insert parent(level l,pointer P,value K,pointer P1)if(level l is empty)then beginCreate an empty non-leaf node N,which is also the rootinsert(P,K,P1)at the starting of the node Nreturnelse beginFind the right most node N at level lif(N has less than n pointers)then insert(K,P1)at thefirst available location in Nelse beginCreate a new non-leaf page N1insert(P1)at the starting of the node Ninsert parent(l+1,pointer N,value K,pointer N1)endendThe insert leaf function is called for each of the value,pointerpairs in ascending order.Similar function can also be build for de-scending order.The search for the last leaf or non-leaf node at anylevel can be avoided by storing the current last page details in anarray.The last node in each level might be less than halffilled.To makethis index structure meet the requirements of a B+-tree,we can re-distribute the keys of the last two pages at each level.Since the lastbut one node is always full,redistribution makes sure that both ofthen are at least halffilled.11.14Answer:In a B+-tree index orfile organization,leaf nodes that areadjacent to each other in the tree may be located at different places ondisk.When afile organization is newly created on a set of records,it ispossible to allocate blocks that are mostly contiguous on disk to leafsnodes that are contiguous in the tree.As insertions and deletions occur12Chapter11Indexing and Hashingon the tree,sequentiality is increasingly lost,and sequential access has towait for disk seeks increasingly often.a.One way to solve this problem is to rebuild the index to restoresequentiality.b.i.In the worst case each n-block unit and each node of the B+-treeis halffilled.This gives the worst case occupancy as25percent.ii.No.While splitting the n-block unit thefirst n/2leaf pages areplaced in one n-block unit,and the remaining in the second n-block unit.That is,every n-block split maintains the order.Hence,the nodes in the n-block units are consecutive.iii.In the regular B+-tree construction,the leaf pages might not besequential and hence in the worst case,it takes one seek per leafing the block at a time method,for each n-node block,we will have at least n/2leaf nodes in it.Each n-node block canbe read using one seek.Hence the worst case seeks comes downby a factor of n/2.iv.Allowing redistribution among the nodes of the same block,doesnot require additional seeks,where as,in regular B+-tree werequire as many seeks as the number of leaf pages involvedin the redistribution.This makes redistribution for leaf blocksefficient with this scheme.Also the worst case occupancy comesback to nearly50percent.(Splitting of leaf nodes is preferredwhen the participating leaf nodes are nearly full.Hence nearly50percent instead of exact50percent)。

安徽工业大学数据库第十一章习题解答

安徽工业大学数据库第十一章习题解答
T1 :A:= A + 2 ;
T2 :A:= A* 2 ;
T3 :A:= A* *2 ( A←A 2 )
设 A 得初值为 0。
⑴ 若这三个事务允许并发执行,则有多少种可能得正确结果,请一一列举出
来;
⑵ 请给出一个可串行化得调度,并给出执行结果;
⑶ 请给出一个非串行化得调度,并给出执行结果;
⑷ 若这三个事务都遵守两段锁协议,请给出一个不产生死锁得可串行化调
最后结 果 A 为 0, 为非 串行化 得调度 。

T1
Slock A Y=A=0 Xlock A A=Y+2 写回 A(=2) Unlock A
Unlock A
T2
Slock A 等待
等待 Y=A=2 Xlock A 等待 A=Y*2 写回 A(=4) Unlock A
Unlock A

T1
Slock A Y=A=0
第十一章 并发控制
1、 并发操作可能会产生哪几类数据不一致性?用什么方法能避免各种不一致
性得情况。
答 : 数据库得并发操作所带来得数据不一致性有三类 : 丢失更新问题、不一致性分析问题 与读“脏”数据问题。对于并发操作带来得问题 , 通常采用并发控制得方法调度并发操作 , 避 免造成数据得不一致性 , 使一个用户事务得执行不受其她事务得干扰。
2 、 为什么 D M L 锁只能提供解除 S 封锁得操作,而不提供解除 X 封锁得操作。
答 : 为防止由事务得 ROLLBAC操K 作引起得丢失更新操作 ,X 封锁必须保留到事务终点。即 X 封锁不就是用 UNLOCK操作解除得 , 而就是在事务结束得语义中包含了对 X 封锁得解除 , 因 此,DML不提供解除 X 封锁得操作。而为增加事务并发操作得程度 , 未到事务终点时 , 用户可以 使用 DML提供得专门解除 S 封锁得操作 , 随时解除事务得 S 封锁 , 这就是因为被 S 封锁得数据 不可能就是未提交得修改。

2022年安徽工业大学数据科学与大数据技术专业《操作系统》科目期末试卷A(有答案)

2022年安徽工业大学数据科学与大数据技术专业《操作系统》科目期末试卷A(有答案)

2022年安徽工业大学数据科学与大数据技术专业《操作系统》科目期末试卷A(有答案)一、选择题1、假定下列指令已装入指令寄存器,则执行时不可能导致CPU从用户态变为内核态(系统态)的是()。

A.DIV R0,R1;(R0)/(R1)→ROB.INT n;产生软中断C.NOT RO;寄存器R0的内容取非D.MOV RO,addr;把地址 addr处的内存数据放入寄存器RO中2、一个多道批处理系统中仅有P1,和P2两个作业,P2比P1晚5ms到达。

它们的计算和I/O操作顺序如下:P1:计算60ms,I/O 80ms,计算20msP2:计算120ms,I/O 40ms,计算40ms。

若不考虑调度和切换时间,则完成两个作业需要的时间最少是()。

A.240msB.260msC.340msD.360ms3、某计算机系统中有8台打印机,有K个进程竞争使用,每个进,程最多需要3台打印机,该系统可能会发生死锁的K的最小值是()A.2B.3C.4D.54、若系统中有5台绘图仪,有多个进程需要使用两台,规定每个进程一次仪允许申请一台,则最多允许()个进程参与竞争,而不会发生死锁。

A.5B.2C.3D.45、设有n个进程共用一个相同的程序段,若每次最多允许m个进程(mSn)同时进入,临界区,则信号量的初值为()。

A.nB.mC.m-nD.-m6、某计算机按字节编址,其动态分区内存管理采用最佳适应算法每次分配和回收内存后都对空闲分区链重新排序。

当前空闲分区信息见表3-12。

回收起始地址为60K、大小为140KB的分区后,系统中空闲分区的数量、空闲分区链第一个分区的起始地址和大小分别是()。

A.3,20K,380KBB.3,500K,80KBC.4,20K,180KBD.4,500K,80KB7、提高单机资源利用率的关键技术是()。

A.SPOOLing技术B.虚拟技术C.交换技术D.多道程序设计技术8、通常对文件系统来说,文件名及属性可以集中在()中以使查询。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第十一章并发控制
1.并发操作可能会产生哪几类数据不一致性?用什么方法能避免各种不一致
性的情况。

答:数据库的并发操作所带来的数据不一致性有三类:丢失更新问题、不一致性分析问题和读“脏”数据问题。

对于并发操作带来的问题,通常采用并发控制的方法调度并发操作,避免造成数据的不一致性,使一个用户事务的执行不受其他事务的干扰。

2.为什么D M L锁只能提供解除S封锁的操作,而不提供解除X封锁的操作。

答:为防止由事务的ROLLBACK操作引起的丢失更新操作,X封锁必须保留到事务终点。

即X封锁不是用UNLOCK操作解除的,而是在事务结束的语义中包含了对X封锁的解除,因此,DML不提供解除X封锁的操作。

而为增加事务并发操作的程度,未到事务终点时,用户可以使用DML提供的专门解除S封锁的操作,随时解除事务的S封锁,这是因为被S封锁的数据不可能是未提交的修改。

3.为什么有些封锁需保留到事务终点,而有些封锁可随时解除。

答:为防止由事务的ROLLBACK操作引起的丢失更新操作,X封锁必须保留到事务终点。

而被S封锁的数据不可能是未提交的修改,因此可以随时解除事务的S封锁,达到增加事务并发操作的程度。

4.设T1、T2、T3是如下的三个事务:
T1:A:=A+2;
T2:A:=A*2;
T3:A:=A**2(A←A2)
设A的初值为0。

⑴若这三个事务允许并发执行,则有多少种可能的正确结果,请一一列举
出来;
⑵请给出一个可串行化的调度,并给出执行结果;
⑶请给出一个非串行化的调度,并给出执行结果;
⑷若这三个事务都遵守两段锁协议,请给出一个不产生死锁的可串行化调
度;
⑸若这三个事务都遵守两段锁协议,请给出一个产生死锁的调度。

解:
⑴A的最终结果可能有2、4、8、16。

因为串行执行次序有T1→T2→T3、T1→T3→T2、T2→T1→T3、T2→T3→T1、
T3→T1→T2、T3→T2→T1,对应的执行结果是16、8、4、2、4、2。

⑵T1T2T3
Slock A
Y=A=0
Unlock A
Xlock A
Slock A
A=Y+2 等待
写回A(=2)等待
Unlock A 等待
Y=A=2
Unlock A
Xlock A
Slock A
A=Y*2 等待
写回A(=4)等待
Unlock A 等待
Y=A=4
Unlock A
Xlock A
A=Y**2
写回A(=16)
Unlock A
最后结果A为16,是可串行化的调度。

⑶T1T2T3
Slock A
Y=A=0
Unlock A
Slock A
Y=A=0
Xlock A
等待Unlock A
A=Y+2
写回A(=2)Slock A
Unlock A 等待
Y=A=2
Unlock A
Xlock A
Xlock A
等待A=Y**2
等待写回A(=16)
等待Unlock A
A=Y*2
写回A(=0)
Unlock A
最后结果A为0,为非串行化的调度。

⑷T1T2T3
Slock A
Y=A=0
Xlock A
A=Y+2 Slock A
写回A(=2)等待
Unlock A 等待
Y=A=2
Xlock A
Unlock A 等待Slock A
A=Y*2 等待
写回A(=4)等待
Unlock A 等待
Y=A=4
Unlock A
Xlock A
A=Y**2
写回A(=16)
Unlock A
Unlock A
⑸T1T2T3
Slock A
Y=A=0
Slock A
Y=A=0
Xlock A
等待
Xlock A
等待
Slock A
Y=A=0
Xlock A
等待。

相关文档
最新文档