170 likes | 288 Views
Installment Number 11 Expression Transformation ( part 2 of 2 ). 690530004 碩一葛煥元. Index. Other Types of Expression Conjunctive Normal Form Expression Semantic Transformations Optimization Inhibitors Duplicate rows 3 VL Dynamically deferred constraints. Other Types of Expression.
E N D
Installment Number 11Expression Transformation ( part 2 of 2 ) 690530004 碩一葛煥元 Expression Transformation ( 2 / 2 )
Index • Other Types of Expression • Conjunctive Normal Form Expression • Semantic Transformations • Optimization Inhibitors • Duplicate rows • 3VL • Dynamically deferred constraints Expression Transformation ( 2 / 2 )
Other Types of Expression • A * B + A * Ctransform A *( B + C ) • true-valued expressionA > B AND B > 3transformA > B AND B > 3 AND A > 3(‘>’ is transitive) Expression Transformation ( 2 / 2 )
Conjunctive Normal Form Expression • A > B OR (C = D AND E < F)transform(A > B OR C = D ) AND ( A > B OR E < F) • C1ANDC2AND … ANDCnis true only if every conjunct is trueis false if any conjunct is false • evaluate all of the conjuncts in parallel Expression Transformation ( 2 / 2 )
Semantic Transformations ex.1 • foreign-to-primary-key join Expression Transformation ( 2 / 2 )
Semantic Transformations ex2 (1/3) • constraints:All red parts must be stored in London • Find suppliers who supply only red parts and are located in the same city as at least one of the parts the supply Expression Transformation ( 2 / 2 )
Semantic Transformations ex2 (2/3) • Find suppliers who supply only red parts and are located in the same city as at least one of the parts the supply • CREATE VIEW SC ASSELECT S# , CITYFROM SP WHERE NOT IN (SELECT S# FROM SP WHERE P#<>’red’)ORDER BY CITY; • SELECT S# FROM SC WHERE city=‘???? ’; Expression Transformation ( 2 / 2 )
Semantic Transformations ex2 (3/3) • transformFind London suppliers who supply only red parts. • SELECT S# FROM SP WHERE NOT IN (SELECT S# FROM SP WHERE P#<>’red’)AND city=‘London’ ; Expression Transformation ( 2 / 2 )
Optimization Inhibitors • Duplicate rows • 3-Valued logic • Dynamically deferred constraints Expression Transformation ( 2 / 2 )
Duplicate rows (1/2) • List part numbers for parts that either are screws or are supplied by supplier S1 ,or both. Expression Transformation ( 2 / 2 )
Duplicate rows (2/2) Expression Transformation ( 2 / 2 )
3VL (3-Valued logic) • p OR NOT p • 3VL Expression Transformation ( 2 / 2 )
Dynamically deferred constraints • DEPT (Dept#, DeptName, Emp#,…)EMP (Emp#, EmpName,…) • SELECT * FORM DEPT,EMP; • SELECT * FORM DEPT,EMPWHERE DEPT.Emp#=EMP.Emp#AND … ; (if each employee is only belong to one department) Expression Transformation ( 2 / 2 )
Puzzle • SELECT E#FROM DEPT,EMPWHERE NOT ( DEPT.D# = EMP.D# AND EMP.D# = ‘D1’ ); • (DEPT , EMP satisfy the primary-to-foreign key) • real-world • delivered by the query as stated • apply predicate transitive closure Expression Transformation ( 2 / 2 )
Answer a NOT (DEPT.D# = EMP.D# AND EMP.D# = ‘D1’); Answer:E1 Expression Transformation ( 2 / 2 )
Answer b • 3VL NOT (DEPT.D# = EMP.D# AND EMP.D# = ‘D1’); NOT (DEPT.D# = unknown) OR NOT (EMP.D#=‘D1’) Answer:Empty Expression Transformation ( 2 / 2 )
Answer c NOT (DEPT.D# = EMP.D# AND EMP.D# = ‘D1’); NOT DEPT.D# = ‘D1’ OR NOT EMP.P# =‘D1’ Answer:E1 Expression Transformation ( 2 / 2 )