400 likes | 527 Views
INSTALL NUMBER 12 Answers to Puzzle Corner Problems (Installment Number 7-11). 中正大學資管所 碩一 690530023 郭 溥 淵. Introduction. Reading review(Installment 7-11) The DEE and DUM problem The empty argument problem The general unification theorem Expression transformation problem
E N D
INSTALL NUMBER 12Answers to Puzzle Corner Problems(Installment Number 7-11) 中正大學資管所 碩一 690530023 郭 溥 淵
Introduction • Reading review(Installment 7-11) • The DEE and DUM problem • The empty argument problem • The general unification theorem • Expression transformation problem • Technical correspondence • Conclusion • Q&A
Reading review(Installment 7-11) • Installment 7: Table with no columns • Installment 8: Empty bag and identity crises • Installment 9: The power of the keys • Installment 10: Expression transformation • Installment 11: Expression transformation
The DEE and DUM problem • Source:”Tables with No Columns” (Installment 7) • Problem statement: What are the effects of DEE and DUM on the relational algebra operation union,intersection, difference, restrict, project, division, extend, and summarize?
Union DEE DUM DEE DEE DEE DUM DEE DUM The DEE and DUM problem • Solution:
The DEE and DUM problem • Solution:
The DEE and DUM problem • Solution:
The DEE and DUM problem • Solution of restrict and project: • Any restriction of DEE yields DEE if the restriction condition is true, DUM if it is false. • Any restriction of DUM yields DUM. • Projection of any_table over no columns yields DUM if the original table is empty, DEE otherwise. In particular, projection of DEE or DUM, necessarily over no columns at all, return its input.
The DEE and DUM problem • Solution of division: • Any table T divided by DEE yields T. • Any table T divided by DUM yields an empty table with the same heading as T. • DEE divided by any table T yields T. • DUM divided by any tale T yields an empty table with the same heading as T. • Any nonempty table divided by itself yields DEE. An empty table divided by itself yields DUM.
The DEE and DUM problem • Solution of extend and summarize: • Extending DEE or DUM to add a new column yields a relation of one column and the same number of rows as its input. • Summarizing DEE or DUM(necessarily over no columns at all) yields a relation of one column and the same number of rows as input.
The empty argument problem • Source:”Empty Bags and Identity crises” (Installment 8) • Problem statement: Give the correct “empty argument” treatment for each of the following functions. Note: In Case 1-4 the argument is intended to be a bag of number; in Case 5-6 it is a bag of tables all having the same(specified) heading.
The empty argument problem 1. Sum of the squares Solution: 0 2.Standard deviation Solution: Undefined
The empty argument problem 3. Median Solution: Undefined 4.Geometric mean Solution: 1
The empty argument problem • Source:”Empty Bags and Identity crises” (Installment 8) • Problem statement: Give the correct “empty argument” treatment for each of the following functions. Note: In Case 1-4 the argument is intended to be a bag of number; in Case 5-6 it is a bag of tables all having the same(specified) heading.
The empty argument problem 5. Union Solution: An empty table with the specified heading. 6.Intersection Solution: A table with the specified heading and with body equal to the Cartesian product to all underlying domains.
The empty argument problem • SELECT CURRENT_TIME WHERE 1=0 ; • EXTEND DUM ADD CURRENT_TIME AS X • Those two query are equivalent.
The general unification theorem • Source:”The power of keys” (Installment 9) • Problem statement: Darwen’s work on FD and key inheritance makes use of the following theorem. Let A, B, C, and D be subsets of the set of columns of relation R such that AB and CD. Then A∪(C-B)B∪D . Prove this theorem.
The general unification theorem • Solution: • Self-determination: AA • Joint dependence: AB&AC≡AB∪C • Transitivity: AB&BC ==> AC • Composition: AB&CD ==>A∪CB∪D
The general unification theorem • Solution: 1. AB (given) 2.CD (given) 3.AB∩C (by joint dependence and 1) 4.C-BC-B (self-determination) 5.A∪(C-B)(B∩C)∪(C-B) (by composition, 3, 4) 6.A∪(C-B)C (simplifying 5) 7.A∪(C-B)D (by transitivity, 6, 2) 8. A∪(C-B)B∪D (by composition, 1, 7)
The general unification theorem • Solution: 1. AB (given) 2.CD (given) 3.AB∩C (by joint dependence and 1) why? 因為AB,又B∩C屬於B的一部份, 故AB∩C。
The general unification theorem • Solution: 4.C-BC-B (self-determination) 5.A∪(C-B)(B∩C)∪(C-B) (by composition, 3, 4) why? Composition: AB&CD ==>A∪CB∪D AB∩C ---3 C-BC-B ---4 故A∪(C-B)(B∩C)∪(C-B)
The general unification theorem • Solution: 6.A∪(C-B)C (simplifying 5) why? (B∩C)∪(C-B)就是C 所以A∪(C-B)C 7.A∪(C-B)D (by transitivity, 6, 2) why? 因為A∪(C-B)C,又CD 所以A∪(C-B)D
The general unification theorem • Solution: 8. A∪(C-B)B∪D (by composition,1,7) why? Composition: AB&CD ==>A∪CB∪D AB ---1 A∪(C-B)D ---2 所以A∪(C-B)B∪D • 完成證明
Expression transformation problem • Source:”Expression Transformation” (Installment 10 & 11) • Problem statement:Prove the following statements • A sequence of restrictions against a given relation can be transformed into a single restriction. • A sequence of projections against a given relation can be transformed into a single projection. • A restriction of a projection can be transformed into a restriction.
Expression transformation problem • Solution: (a) • ( R WHERE C1 ) WHERE C2 • R WHERE C1 AND C2 If C1 and C2 are both restriction condition for relation R, then above two expressions are obviously equivalent.
Expression transformation problem • Solution: (b) • ( R [ L1 ] ) [L2] • R [ L2 ] If L1 is a subset of the heading of relation R and L2 is a subset of L1,then the above two expressions are obviously equivalent.
Expression transformation problem • Solution: (c) • R [ L ] WHERE C • ( R WHERE C ) [ L ] If L and C are, respectively, a subset of heading of relation R and restriction condition for relation R that involves only columns mentioned in L, then the above two expressions are obviously equivalent.
Expression transformation problem • SELECT E# FROM DEPT, EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’) ; • Show the answer DEPT EMP
Expression transformation problem (a) Show the correct real-world answer to this query. DEPT EMP
Expression transformation problem • SELECT E# FROM DEPT, EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’) ; • Show the answer DEPT EMP The answer is E1.
Expression transformation problem (b) Show the answer delivered by the query as stated. DEPT EMP
Expression transformation problem • SELECT E# FROM DEPT, EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’) ; • Show the answer DEPT EMP The answer is empty.
Expression transformation problem • SELECT E# FROM DEPT, EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’) ; • Show the answer DEPT EMP
Expression transformation problem (c) Show the answer delivered if the optimizer applies “predicate transitive closure”. DEPT EMP
Expression transformation problem Optimizer will transform the expression to : SELECT E# FROM DEPT,EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = D1 AND DEPT.D# = D1 ) ; The answer is E1.
Technical correspondence • Problem: • SUMMARIZE EMP BY ( D# ) ADD AVG ( SAL ) AS AVGSAL
Technical correspondence • Solution: • IF exp1 THEN exp2 ELSE exp3 • SUMMARIZE EMP BY ( D# ) ADD ( IF IS_EMPTY ( EMP ) THEN 0 ELSE AVG ( SAL ) ) AS AVGSAL