




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Chapter 7: Relational Database DesignChapter 7: Relational Database DesignFeatures of Good Relational DesignAtomic Domains and First Normal FormDecomposition Using Functional DependenciesFunctional Dependency TheoryAlgorithms for Functional DependenciesDecomposition Using Multivalued Dependencies Mo
2、re Normal FormDatabase-Design ProcessModeling Temporal DataThe Banking Schema P264branch = (branch_name, branch_city, assets)customer = (customer_id, customer_name, customer_street, customer_city)loan = (loan_number, amount)account = (account_number, balance)employee = (employee_id. employee_name, t
3、elephone_number, start_date)dependent_name = (employee_id, dname)account_branch = (account_number, branch_name)loan_branch = (loan_number, branch_name)borrower = (customer_id, loan_number)depositor = (customer_id, account_number)cust_banker = (customer_id, employee_id, type)works_for = (worker_emplo
4、yee_id, manager_employee_id)payment = (loan_number, payment_number, payment_date, payment_amount)savings_account = (account_number, interest_rate)checking_account = (account_number, overdraft_amount)Design Alternative: Larger SchemasSuppose we combine borrow and loan to get bor_loan = (customer_id,
5、loan_number, amount )Result is possible repetition of information (L-100 in example below) Cause redundancy and inconsistency.A Combined Schema Without RepetitionConsider combining loan_branch and loanloan_amt_br = (loan_number, amount, branch_name)No repetition (as suggested by example below)Design
6、 Alternative: Smaller SchemasSuppose we had started with bor_loan. How would we know to split up (decompose) 分解 it into borrower and loan?Write a rule “if there were a schema (loan_number, amount), then loan_number would be a candidate key”Denote as a functional dependency: 函数依赖loan_number amountIn
7、bor_loan, because loan_number is not a candidate key, the amount of a loan may have to be repeated. This indicates the need to decompose bor_loan.Not all decompositions are good. Suppose we decompose employee intoemployee1 = (employee_id, employee_name)employee2 = (employee_name, telephone_number, s
8、tart_date)The next slide shows how we lose information - we cannot reconstruct the original employee relation - and so, this is a lossy decomposition.A Lossy Decomposition 有损分解First Normal Form 第一范式Domain is atomic if its elements are considered to be indivisible unitsExamples of non-atomic domains:
9、Set of names, composite attributesIdentification numbers like CS101 that can be broken up into partsA relational schema R is in first normal form if the domains of all attributes of R are atomicNon-atomic values complicate storage and encourage redundant (repeated) storage of dataExample: Set of acc
10、ounts stored with each customer, and set of owners stored with each account. customer / account is a many to many relationship.We assume all relations are in first normal form (and revisit this in Chapter 9)First Normal Form (Contd)Atomicity is actually a property of how the elements of the domain a
11、re used.Example: Strings would normally be considered indivisible Suppose that students are given roll numbers which are strings of the form CS0012 or EE1127If the first two characters are extracted to find the department, the domain of roll numbers is not atomic.Doing so is a bad idea: leads to enc
12、oding of information in application program rather than in the database.Goal Devise a Theory for the FollowingDecide whether a particular relation R is in “good” form.In the case that a relation R is not in “good” form, decompose it into a set of relations R1, R2, ., Rn such that each relation is in
13、 good form the decomposition is a lossless-join decompositionOur theory is based on:functional dependenciesmultivalued dependenciesFunctional DependenciesConstraints on the set of legal relations.Require that the value for a certain set of attributes determines uniquely the value for another set of
14、attributes.A functional dependency is a generalization of the notion of a key.Functional Dependencies (Cont.)Let R be a relation schema R and RThe functional dependency holds on R if and only if for any legal relations r(R), whenever any two tuples t1 and t2 of r agree on the attributes , they also
15、agree on the attributes . That is, t1 = t2 t1 = t2 Example: Consider r(A,B ) with the following instance of r.On this instance, A B does NOT hold, but B A does hold. 41 537Functional Dependencies (Cont.)K is a superkey for relation schema R if and only if K RK is a candidate key for R if and only if
16、 K R, and 函数性for no K, R 最小性Functional dependencies allow us to express constraints that cannot be expressed using superkeys. Consider the schema:bor_loan = (customer_id, loan_number, amount ).We expect this functional dependency to hold:loan_number amountbut would not expect the following to hold:
17、amount customer_nameUse of Functional DependenciesWe use functional dependencies to:test relations to see if they are legal under a given set of functional dependencies. If a relation r is legal under a set F of functional dependencies, we say that r satisfies F.specify constraints on the set of leg
18、al relationsWe say that F holds on R if all legal relations on R satisfy the set of functional dependencies F.Note: A specific instance of a relation schema may satisfy a functional dependency even if the functional dependency does not hold on all legal instances. 只对个别实例成立的, 不是函数依赖.For example, a sp
19、ecific instance of loan may, by chance, satisfy amount customer_name.Functional Dependencies (Cont.)A functional dependency is trivial 平凡的 if it is satisfied by all instances of a relationExample: customer_name, loan_number customer_name customer_name customer_nameIn general, is trivial if Closure o
20、f a Set of Functional DependenciesGiven a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F.For example: If A B and B C, then we can infer that A CThe set of all functional dependencies logically implied by F is the closure of F. We
21、 denote the closure of F by F+.F+ is a superset of F. 注意: 函数依赖具有传递性, closure of F , 其实就是个传递闭包.Boyce-Codd Normal Form is trivial (i.e., ) is a superkey for RA relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form where R a
22、nd R, at least one of the following holds:Example schema not in BCNF:bor_loan = ( customer_id, loan_number, amount )because loan_number amount holds on bor_loan but loan_number is not a superkeyDecomposing a Schema into BCNFSuppose we have a schema R and a non-trivial dependency causes a violation o
23、f BCNF.We decompose R into:(U )( R - ( - ) )In our example, = loan_number = amountand bor_loan is replaced by (U ) = ( loan_number, amount )( R - ( - ) ) = ( customer_id, loan_number )BCNF and Dependency PreservationConstraints, including functional dependencies, are costly to check in practice unle
24、ss they pertain to only one relationIf it is sufficient to test only those dependencies on each individual relation of a decomposition, in order to ensure that all functional dependencies hold, then that decomposition is dependency preserving.Because it is not always possible to achieve both BCNF an
25、d dependency preservation, see P275 , we consider a weaker normal form, known as third normal form.Third Normal FormA relation schema R is in third normal form (3NF) if for all: in F+at least one of the following holds: is trivial (i.e., ) is a superkey for REach attribute A in is contained in a can
26、didate key for R. (NOTE: each attribute may be in a different candidate key)If a relation is in BCNF, then it is in 3NF.Third condition is a minimal relaxation of BCNF to ensure dependency preservation (will see why later).Goals of NormalizationLet R be a relation scheme with a set F of functional d
27、ependencies.Decide whether a relation scheme R is in “good” form.In the case that a relation scheme R is not in “good” form, decompose it into a set of relation scheme R1, R2, ., Rn such that each relation scheme is in good form the decomposition is a lossless-join decompositionPreferably, the decom
28、position should be dependency preserving.How good is BCNF?There are database schemas in BCNF that do not seem to be sufficiently normalized Consider a database classes (course, teacher, book ) such that (c, t, b) classes means that t is qualified to teach c, and b is a required textbook for cThe dat
29、abase is supposed to list for each course the set of teachers any one of which can be the courses instructor, and the set of books, all of which are required for the course (no matter who teaches it).There are no non-trivial functional dependencies and therefore the relation is in BCNF Insertion ano
30、malies i.e., if Marilyn is a new teacher that can teach database, two tuples need to be inserted(database, Marilyn, DB Concepts)(database, Marilyn, Ullman)courseteacherbookdatabasedatabasedatabasedatabasedatabasedatabaseoperating systemsoperating systemsoperating systemsoperating systemsAviAviHankHa
31、nkSudarshanSudarshanAviAvi PetePeteDB ConceptsUllmanDB ConceptsUllmanDB ConceptsUllmanOS ConceptsStallingsOS ConceptsStallingsclassesHow good is BCNF? (Cont.)Therefore, it is better to decompose classes into:courseteacherdatabasedatabasedatabaseoperating systemsoperating systemsAviHankSudarshanAvi J
32、imteachescoursebookdatabasedatabaseoperating systemsoperating systemsDB ConceptsUllmanOS ConceptsShawtextThis suggests the need for higher normal forms, such as Fourth Normal Form (4NF), which we shall see later.How good is BCNF? (Cont.)Functional-Dependency TheoryWe now consider the formal theory t
33、hat tells us which functional dependencies are implied logically by a given set of functional dependencies.We then develop algorithms to generate lossless decompositions into BCNF and 3NFWe then develop algorithms to test if a decomposition is dependency-preservingClosure of a Set of Functional Depe
34、ndenciesGiven a set F set of functional dependencies, there are certain other functional dependencies that are logically implied by F.For example: If A B and B C, then we can infer that A CThe set of all functional dependencies logically implied by F is the closure of F.We denote the closure of F by
35、 F+.We can find all of F+ by applying Armstrongs Axioms:if , then (reflexivity) 自反if , then (augmentation) 扩充if , and , then (transitivity) 传递These rules are sound (generate only functional dependencies that actually hold) and complete (generate all functional dependencies that hold).ExampleR = (A,
36、B, C, G, H, I)F = A B A CCG HCG I B Hsome members of F+A H by transitivity from A B and B HAG I by augmenting A C with G, to get AG CG and then transitivity with CG I CG HI by augmenting CG I to infer CG CGI, and augmenting of CG H to infer CGI HI, and then transitivityProcedure for Computing F+To c
37、ompute the closure of a set of functional dependencies F: F + = Frepeatfor each functional dependency f in F+ apply reflexivity and augmentation rules on f add the resulting functional dependencies to F +for each pair of functional dependencies f1and f2 in F + if f1 and f2 can be combined using tran
38、sitivity then add the resulting functional dependency to F +until F + does not change any furtherNOTE: We shall see an alternative procedure for this task laterClosure of Functional Dependencies (Cont.)We can further simplify manual computation of F+ by using the following additional rules.If holds
39、and holds, then holds (union)If holds, then holds and holds (decomposition)If holds and holds, then holds (pseudotransitivity)The above rules can be inferred from Armstrongs axioms.Closure of Attribute SetsGiven a set of attributes a, define the closure of a under F (denoted by a+) as the set of att
40、ributes that are functionally determined by a under F Algorithm to compute a+, the closure of a under F result := a;while (changes to result) dofor each in F dobeginif result then result := result endExample of Attribute Set ClosureR = (A, B, C, G, H, I)F = A BA C CG HCG IB H(AG)+1.result = AG2.resu
41、lt = ABCG(A C and A B)3.result = ABCGH(CG H and CG AGBC)4.result = ABCGHI(CG I and CG AGBCH)Is AG a candidate key? Is AG a super key?Does AG R? = Is (AG)+ RIs any subset of AG a superkey?Does A R? = Is (A)+ RDoes G R? = Is (G)+ RUses of Attribute ClosureThere are several uses of the attribute closur
42、e algorithm:Testing for superkey: if is a superkey, then + contains all attributes of R.Testing functional dependencies if holds (or, in other words, is in F+), then +. Is a simple and cheap test, and very usefulComputing closure of FFor each R, we find the closure +, and for each S +, we output a f
43、unctional dependency S.Canonical Cover 正则覆盖Sets of functional dependencies may have redundant dependencies that can be inferred from the othersFor example: A C is redundant in: A B, B CParts of a functional dependency may be redundantE.g.: on RHS: A B, B C, A CD can be simplified to A B, B C, A D E.
44、g.: on LHS: A B, B C, AC D can be simplified to A B, B C, A D Intuitively, a canonical cover of F is a “minimal” set of functional dependencies equivalent to F, having no redundant dependencies or redundant parts of dependencies Extraneous AttributesConsider a set F of functional dependencies and th
45、e functional dependency in F.Attribute A is extraneous in if A and F logically implies (F ) ( A) .Attribute A is extraneous in if A and the set of functional dependencies (F ) ( A) logically implies F.Note: implication in the opposite direction is trivial in each of the cases above, since a “stronge
46、r” functional dependency always implies a weaker oneExample: Given F = A C, AB C B is extraneous in AB C because A C, AB C logically implies A C (I.e. the result of dropping B from AB C).Example: Given F = A C, AB CDC is extraneous in AB CD since AB C can be inferred even after deleting CTesting if
47、an Attribute is ExtraneousConsider a set F of functional dependencies and the functional dependency in F.To test if attribute A is extraneous in compute ( A)+ using the dependencies in F check that ( A)+ contains A; if it does, A is extraneousTo test if attribute A is extraneous in compute + using o
48、nly the dependencies in F = (F ) ( A), check that + contains A; if it does, A is extraneousCanonical Cover 正则覆盖A canonical cover for F is a set of dependencies Fc such that F logically implies all dependencies in Fc, and Fc logically implies all dependencies in F, andNo functional dependency in Fc c
49、ontains an extraneous attribute, andEach left side of functional dependency in Fc is unique.To compute a canonical cover for F:repeatUse the union rule to replace any dependencies in F 1 1 and 1 2 with 1 1 2 Find a functional dependency with an extraneous attribute either in or in If an extraneous a
50、ttribute is found, delete it from until F does not changeNote: Union rule may become applicable after some extraneous attributes have been deleted, so it has to be re-appliedComputing a Canonical CoverR = (A, B, C)F = A BC B C A BAB CCombine A BC and A B into A BCSet is now A BC, B C, AB CA is extra
51、neous in AB CCheck if the result of deleting A from AB C is implied by the other dependenciesYes: in fact, B C is already present!Set is now A BC, B CC is extraneous in A BC Check if A C is logically implied by A B and the other dependenciesYes: using transitivity on A B and B C. Can use attribute c
52、losure of A in more complex casesThe canonical cover is: A BB CLossless-join DecompositionFor the case of R = (R1, R2), we require that for all possible relations r on schema Rr = R1 (r ) R2 (r ) A decomposition of R into R1 and R2 is lossless join if and only if at least one of the following depend
53、encies is in F+:R1 R2 R1R1 R2 R2ExampleR = (A, B, C)F = A B, B C)Can be decomposed in two different waysR1 = (A, B), R2 = (B, C)Lossless-join decomposition: R1 R2 = B and B BCDependency preserving : R1 A B, R2 B C)R1 = (A, B), R2 = (A, C)Lossless-join decomposition: R1 R2 = A and A ABNot dependency
54、preserving (cannot check B C without computing R1 R2)Dependency PreservationR is a relation with functional dependency set F . R is decomposed to R1 R2 R3 . Rn. Ri has functional dependency set Fi . definition: A decomposition is dependency preserving, if (F1 F2 Fn )+ = F +If it is not, then checkin
55、g updates for violation of functional dependencies may require computing joins, which is expensive.Testing for Dependency PreservationTo check if a dependency is preserved in a decomposition of R into R1, R2, , Rn we apply the following test (with attribute closure done with respect to F)result = wh
56、ile (changes to result) dofor each Ri in the decompositiont = (result Ri)+ Riresult = result tIf result contains all attributes in , then the functional dependency is preserved.We apply the test on all dependencies in F to check if a decomposition is dependency preservingThis procedure takes polynom
57、ial time, instead of the exponential time required to compute F+ and (F1 F2 Fn)+ ExampleR = (A, B, C )F = A B B CKey = AR is not in BCNFDecomposition R1 = (A, B), R2 = (B, C)R1 and R2 in BCNFLossless-join decompositionDependency preservingTesting for BCNFTo check if a non-trivial dependency causes a
58、 violation of BCNF1. compute + (the attribute closure of ), and 2. verify that it includes all attributes of R, that is, it is a superkey of R.Simplified test: To check if a relation schema R is in BCNF, it suffices to check only the dependencies in the given set F for violation of BCNF, rather than
59、 checking all dependencies in F+.If none of the dependencies in F causes a violation of BCNF, then none of the dependencies in F+ will cause a violation of BCNF either.However, using only F is incorrect when testing a relation in a decomposition of RConsider R = (A, B, C, D, E), with F = A B, BC DDe
60、compose R into R1 = (A,B) and R2 = (A,C,D, E) Neither of the dependencies in F contain only attributes from (A,C,D,E) so we might be mislead into thinking R2 satisfies BCNF. In fact, dependency AC D in F+ shows R2 is not in BCNF. Testing Decomposition for BCNFTo check if a relation Ri in a decomposi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 冠心病患者非心脏手术麻醉管理专家共识
- 甘肃省白银市育才中学2024届中考二模数学试题含解析
- 广东东莞中堂六校2024年中考数学全真模拟试卷含解析
- 25年公司员工安全培训考试试题【满分必刷】
- 2024-2025企业员工岗前安全培训考试试题及答案【易错题】
- 2025公司管理人员安全培训考试试题附完整答案(各地真题)
- 2025年工厂安全培训考试试题及答案【全优】
- 2025厂级安全培训考试试题(审定)
- 2025年新员工岗前安全培训考试试题(往年题考)
- 2025年中国瓷砖粘合剂行业市场占有率及投资前景预测分析报告
- 《精子战争》作者罗宾·贝克
- 收费站特情处理培训
- 《防癌抗癌专题》课件
- 【MOOC】考古发现与中国文化-浙江大学 中国大学慕课MOOC答案
- (PPAP)生产件批准作业指导书
- 常用动脉穿刺术小讲课护理课件
- 2024年高考真题-化学(天津卷) 含解析
- 房屋过户协议书范文五份
- 陶瓷工艺技术研究试题考核试卷
- 铲车维护保养管理制度
- 公共卫生工作人员绩效考核评价细则
评论
0/150
提交评论