Download presentation
Presentation is loading. Please wait.
Published byGriffin Bridges Modified over 9 years ago
1
INSTALL NUMBER 12 Answers to Puzzle Corner Problems (Installment Number 7-11) 中正大學資管所 碩一 690530023 郭 溥 淵
2
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
3
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
4
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?
5
The DEE and DUM problem Solution: Unio n DEEDUM DEE DUMDEEDUM OR10 111 010
6
The DEE and DUM problem Solution: Intersection DEEDUM DEE DUM AND10 110 000
7
The DEE and DUM problem Solution: Difference DEEDUM DEEDUMDEE DUM AND NOT 10 101 000
8
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.
9
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.
10
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.
11
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.
12
The empty argument problem 1. Sum of the squares Solution: 0 2.Standard deviation Solution: Undefined
13
The empty argument problem 3. Median Solution: Undefined 4.Geometric mean Solution: 1
14
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.
15
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.
16
The empty argument problem SELECT CURRENT_TIME WHERE 1=0 ; EXTEND DUM ADD CURRENT_TIME AS X Those two query are equivalent.
17
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 A B and C D. Then A ∪ (C- B) B ∪ D. Prove this theorem.
18
The general unification theorem Solution: Self-determination: A A Joint dependence: A B&A C ≡ A B ∪ C Transitivity: A B&B C ==> A C Composition: A B&C D ==>A ∪ C B ∪ D
19
The general unification theorem Solution: 1. A B (given) 2.C D (given) 3.A B∩C (by joint dependence and 1) 4.C-B C-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)
20
The general unification theorem Solution: 1. A B (given) 2.C D (given) 3.A B∩C (by joint dependence and 1) why? 因為 A B, 又 B∩C 屬於 B 的一部份, 故 A B∩C 。
21
The general unification theorem Solution: 4.C-B C-B (self-determination) 5.A ∪ (C-B) (B∩C) ∪ (C-B) (by composition, 3, 4) why? Composition: A B&C D ==>A ∪ C B ∪ D A B∩C ---3 C-B C-B ---4 故 A ∪ (C-B) (B∩C) ∪ (C-B)
22
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 ,又 C D 所以 A ∪ (C-B) D
23
The general unification theorem Solution: 8. A ∪ (C-B) B ∪ D (by composition,1,7) why? Composition: A B&C D ==>A ∪ C B ∪ D A B --- 1 A ∪ (C-B) D ---2 所以 A ∪ (C-B) B ∪ D 完成證明
24
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.
25
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.
26
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.
27
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.
28
Expression transformation problem SELECT E# FROM DEPT, EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’) ; Show the answer DEPT EMP D# D2 E#D# E1--
29
Expression transformation problem (a) Show the correct real-world answer to this query. DEPT EMP D# D2 E#D# E1--
30
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. D# D2 E#D# E1--
31
Expression transformation problem (b) Show the answer delivered by the query as stated. DEPT EMP D# D2 E#D# E1--
32
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. D# D2 E#D# E1--
33
Expression transformation problem SELECT E# FROM DEPT, EMP WHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’) ; Show the answer DEPT EMP D# D2 E#D# E1--
34
Expression transformation problem (c) Show the answer delivered if the optimizer applies “predicate transitive closure”. DEPT EMP D# D2 E#D# E1--
35
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.
36
Technical correspondence Problem: SUMMARIZE EMP BY ( D# ) ADD AVG ( SAL ) AS AVGSAL
37
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
38
Conclusion
39
Q&A
40
Thanks for your listening.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.