Upload
gloria
View
43
Download
0
Embed Size (px)
DESCRIPTION
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 - PowerPoint PPT Presentation
Citation preview
INSTALL NUMBER 12Answers to Puzzle Corner Problems(Installment Number 7-11)
中正大學資管所碩一 690530023
郭 溥 淵
IntroductionIntroduction
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?
The DEE and DUM problem Solution:
Union
DEE DUM
DEE DEE DEE
DUM DEE DUM
OR 1 0
1 1 1
0 1 0
The DEE and DUM problem Solution:
Intersection DEE DUM
DEE DEE DUM
DUM DUM DUM
AND 1 0
1 1 0
0 0 0
The DEE and DUM problem Solution:
Difference DEE DUM
DEE DUM DEE
DUM DUM DUM
AND NOT
1 0
1 0 1
0 0 0
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. UnionSolution:
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)C7.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 ---1A∪(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 D#
D2
E# D#
E1 --
Expression transformation problem
(a) Show the correct real-world answer to this query.
DEPT EMP D#
D2
E# D#
E1 --
Expression transformation problem
SELECT E#FROM DEPT, EMPWHERE NOT ( DEPT.D# = EMP.D#
AND EMP.D# = ‘D1’) ; Show the answer
DEPT EMP
The answer is E1.
D#
D2
E# D#
E1 --
Expression transformation problem
(b) Show the answer delivered by the query as stated.
DEPT EMP D#
D2
E# D#
E1 --
Expression transformation problem
SELECT E#FROM DEPT, EMPWHERE NOT ( DEPT.D# = EMP.D#
AND EMP.D# = ‘D1’) ; Show the answer
DEPT EMP
The answer is empty.
D#
D2
E# D#
E1 --
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 --
Expression transformation problem
(c) Show the answer delivered if the optimizer applies “predicate transitive closure”.
DEPT EMP D#
D2
E# D#
E1 --
Expression transformation problem
Optimizer will transform the expression to :SELECT E#FROM DEPT,EMPWHERE NOT ( DEPT.D# = EMP.D#
AND EMP.D# = D1AND 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
Conclusion
Q&A
Thanks for your listening.