Copyright © C. J. Date 2005page 97 S#Y S1DURINGS3DURING [d04:d10][d08:d10] S2DURINGS4DURING [d02:d04][d04:d10] [d08:d10] WITH ( EXTEND T2 ADD ( COLLAPSE.

Slides:



Advertisements
Similar presentations
Copyright © C. J. Date 2005page 1 AGENDA : 1. A few preliminaries 2. Laying the foundations 3.Building on the foundations.
Advertisements

Copyright © C. J. Date 2005page 49 SAMPLE QUERIES : l Query A:Get S#-FROM-TO triples for suppliers who have been able to supply at least one part during.
CPSC 504: Data Management Discussion on Chandra&Merlin 1977 Laks V.S. Lakshmanan Dept. of CS UBC.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Domain Restriction on Relation domain restriction operator,, restricts a relation to only those members whose domain is in a specified set. domain restriction.
Joining Relations in SQL Objectives of the Lecture : To consider the Natural & Generalised Joins using the SQL1 standard; To consider the Natural & Generalised.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
Algebraic and Logical Query Languages Spring 2011 Instructor: Hassan Khosravi.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Chapter 14 Getting to First Base: Introduction to Database Concepts.
Database Principles Relational Algebra. Database Principles What is Relational Algebra? It is a language in which we can ask questions (query) of a database.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
1 SQL: Structured Query Language Chapter 5. 2 SQL and Relational Calculus relationalcalculusAlthough relational algebra is useful in the analysis of query.
Copyright © Cengage Learning. All rights reserved.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra.
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
Chapter 6 Relations. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Topics in this Chapter Tuples Relation Types Relation Values Relation.
Chapter 6 Relations. Topics in this Chapter Tuples Relation Types Relation Values Relation Variables SQL Facilities.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
SQL. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A typical SQL query has the form: select.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Relational Algebra II. Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Further Normalization II: Higher Normal Forms Prof. Yin-Fu Huang CSIE, NYUST Chapter 13.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Chapter 8 Relational Calculus. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.8-2 Topics in this Chapter Tuple Calculus Calculus vs. Algebra.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
NULLs & Outer Joins Objectives of the Lecture : To consider the use of NULLs in SQL. To consider Outer Join Operations, and their implementation in SQL.
Relational Algebra  Souhad M. Daraghma. Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational.
Built-in Data Structures in Python An Introduction.
Chapter 7 Relational Algebra. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.7-2 Topics in this Chapter Closure Revisited The Original Algebra:
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Relational Algebra.
Set Operations Objectives of the Lecture : To consider the Set Operations Union, Difference and Intersect; To consider how to use the Set Operations in.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Advanced Relational Algebra & SQL (Part1 )
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Extra slides for Chapter 3: Propositional Calculus & Normal Forms Based on Prof. Lila Kari’s slides For CS2209A, 2009 By Dr. Charles Ling;
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
1 Algebra of Queries Classical Relational Algebra It is a collection of operations on relations. Each operation takes one or two relations as its operand(s)
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Relational Algebra Prof. Yin-Fu Huang CSIE, NYUST Chapter 7.
Chapter 10 Views. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.10-2 Topics in this Chapter What are Views For? View Retrievals View Updates.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
1 SQL: The Query Language. 2 Example Instances R1 S1 S2 v We will use these instances of the Sailors and Reserves relations in our examples. v If the.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
1 CS122A: Introduction to Data Management Lecture 9 SQL II: Nested Queries, Aggregation, Grouping Instructor: Chen Li.
Chapter 8 Relational Calculus.
STRUCTURE OF PRESENTATION :
More SQL: Complex Queries,
Chapter 10 Views.
Relational Algebra - Part 1
STRUCTURE OF PRESENTATION :
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
STRUCTURE OF PRESENTATION :
Presentation transcript:

Copyright © C. J. Date 2005page 97 S#Y S1DURINGS3DURING [d04:d10][d08:d10] S2DURINGS4DURING [d02:d04][d04:d10] [d08:d10] WITH ( EXTEND T2 ADD ( COLLAPSE ( X ) AS Y ) ) { ALL BUT X } AS T3 : T3

Copyright © C. J. Date 2005page 98 S#DURING S1[d04:d10]Packed form S2[d02:d04]of T1 on DURING S2 [d08:d10] S3 [d08:d10] S4 [d04:d10] WITH SP_DURING { S#, DURING } AS T1, (T1 GROUP { DURING } AS X ) AS T2, ( EXTEND T2 ADD ( COLLAPSE ( X ) AS Y ) ) { ALL BUT X } AS T3 : T3 UNGROUP Y

Copyright © C. J. Date 2005page 99 THE PACK OPERATOR (shorthand!) : PACK R ON A  WITH ( R GROUP { A } AS X ) AS R1, ( EXTEND R1 ADD ( COLLAPSE ( X ) AS Y ) ) { ALL BUT X } AS R2 : R2 UNGROUP Y Note: Packing R on A involves grouping R by all attributes of R apart from A  Query A: PACK SP_DURING { S#, DURING } ON DURING /* "temporal projection"—see later!*/ /* (original query involved regular projection)*/

Copyright © C. J. Date 2005page 100 NOW FOR QUERY B : l Get S#-FROM-TO triples for suppliers who have been unable to supply any parts at all during at least one interval of time, where FROM and TO together designate a maximal interval during which supplier S# was in fact unable to supply any part at all Revised version: l Get S#-DURING pairs for suppliers who have been unable to supply any parts at all during at least one interval of time, where DURING designates a maximal interval during which supplier S# was in fact unable to supply any part at all

Copyright © C. J. Date 2005page 101 Original version of Query B involved relational difference Revised version is going to involve "temporal difference" (involves both unpack and pack) Intuitively, we want S#-DURING pairs that appear in or are implied by S_DURING and do not appear in and are not implied by SP_DURING—where "implied by" means "appearing in the unpacked form" Suggests (correctly!)1. two unpacks 2. take difference 3. pack result

Copyright © C. J. Date 2005page 102 THE UNPACK OPERATOR (shorthand!) : UNPACK R ON A  WITH ( R GROUP { A } AS X ) AS R1, ( EXTEND R1 ADD ( EXPAND ( X ) AS Y ) ) { ALL BUT X } AS R2 : R2 UNGROUP Y Left operand for difference op: S#-DURING pairs that appear in or are implied by S_DURING: UNPACK S_DURING { S#, DURING } ON DURING /* shorthand for: */ WITH S_DURING { S#, DURING } AS T1, (T1 GROUP { DURING } AS X ) AS T2, ( EXTEND T2 ADD ( EXPAND ( X ) AS Y ) ) { ALL BUT X } AS T3 : T3 UNGROUP Y

Copyright © C. J. Date 2005page 103 LEFT OPERAND LOOKS LIKE THIS : S#DURING S1[d04:d04] S1[d05:d05]S4[d04:d04] S1[d06:d06]S4[d05:d05] S1[d07:d07]S4[d06:d06] S1[d08:d08]S4[d07:d07] S1[d09:d09]S4[d08:d08] S1[d10:d10]S4[d09:d09] S2[d02:d02]S4[d10:d10] S2[d03:d03]S5[d02:d02] S2[d04:d04]S5[d03:d03] S2[d07:d07]S5[d04:d04] S2[d08:d08]S5[d05:d05] S2[d09:d09]S5[d06:d06] S2[d10:d10]S5[d07:d07] S3[d03:d03]S5[d08:d08] S3[d04:d04]S5[d09:d09] S3[d05:d05]S5[d10:d10] S3[d06:d06] S3[d07:d07] U1

Copyright © C. J. Date 2005page 104 RIGHT OPERAND : S#-DURING pairs that appear in or are implied by SP_DURING: UNPACK SP_DURING { S#, DURING } ON DURING S#DURING S1[d04:d04] S1[d05:d05]S3[d08:d08] S1[d06:d06]S3[d09:d09] S1[d07:d07]S3[d10:d10] S1[d08:d08]S4[d04:d04] S1[d09:d09]S4[d05:d05] S1[d10:d10]S4[d06:d06] S2[d02:d02]S4[d07:d07] S2[d03:d03]S4[d08:d08] S2[d04:d04]S4[d09:d09] S2[d08:d08]S4[d10:d10] S2[d09:d09] S2[d10:d10] U2

Copyright © C. J. Date 2005page 105 U1 MINUS U2 : S#DURING S2[d07:d07] S3[d03:d03]S5[d04:d04] S3[d04:d04]S5[d05:d05] S3[d05:d05]S5[d06:d06] S3[d06:d06]S5[d07:d07] S3[d07:d07]S5[d08:d08] S5[d02:d02]S5[d09:d09] S5[d03:d03]S5[d10:d10] U3

Copyright © C. J. Date 2005page 106 PACK U3 ON DURING S#DURING S2[d07:d07] S3[d03:d07] S5[d02:d10] Query B: PACK (( UNPACK S_DURING { S#, DURING } ON DURING ) MINUS ( UNPACK SP_DURING { S#, DURING } ON DURING ) ) ON DURING /* "temporal difference"—see later! */

Copyright © C. J. Date 2005page 107 BY THE WAY : PACK and UNPACK are not inverses of each other! In fact: PACK ( UNPACK r ON A ) ON A  PACK r ON A UNPACK ( PACK r ON A ) ON A  UNPACK r ON A Hence, can ignore first operation in a PACK/UNPACK or (more important) UNPACK/PACK sequence Also: PACK ( PACK r ON A ) ON A  PACK r ON A UNPACK ( UNPACK r ON A ) ON A  UNPACK r ON A

Copyright © C. J. Date 2005page 108 MORE EXAMPLES : NHW { NAME, HEIGHT, WEIGHT }/* not temporal!*/ For each weight in NHW, get every range of heights such that for each height in that range there is at least one person in NHW of that height and weight: PACK ( ( EXTEND NHW { HEIGHT, WEIGHT } ADD ( INTERVAL_HEIGHT ( [ HEIGHT : HEIGHT ] ) AS HR ) ) { WEIGHT, HR } ) ON HR Predicate:For all heights h in HR (but not for h = BEGIN(HR)-1 or h = END(HR)+1), there exists at least one person p such that p has weight WEIGHT and height h

Copyright © C. J. Date 2005page 109 At any given time, if there are any shipments at all at that time, then there is some part number pmax such that no supplier is able to supply any part at that time with a part number greater than pmax For each part number that has ever been such a pmax value, get that part number together with the interval(s) during which it actually was that pmax value WITH( UNPACK SP_DURING ON DURING ) AS SP_UNPACKED, ( SUMMARIZE SP_UNPACKED BY { DURING } ADD ( MAX ( P# ) AS PMAX ) ) AS SUMMARY : PACK SUMMARY ON DURING

Copyright © C. J. Date 2005page 110 S_PARTS_DURING { S#, PARTS, DURING } S#PARTSDURING S2[P3:P4][d07:d08] S3[P2:P4][d01:d04] S3[P3:P5][d01:d04] S3[P2:P4][d05:d06] S3[P2:P4][d06:d09] S4[P3:P4][d05:d08] For each part that has ever been capable of being supplied by S3, get P# and applicable time intervals

Copyright © C. J. Date 2005page 111 WITH ( S_PARTS_DURING WHERE S# = S# ('S3') ) AS T1, T1 { PARTS, DURING } AS T2, ( UNPACK T2 ON PARTS ) AS T3, ( EXTEND T3 ADD ( POINT FROM PARTS AS P# ) ) AS T4, T4 { P#, DURING } AS T5 : PACK T5 ON DURING P#DURING P2[d01:d09] P3[d01:d09] P4[d01:d09] P5[d01:d04]

Copyright © C. J. Date 2005page 112 PACKING AND UNPACKING ON NO ATTRIBUTES : Can generalize PACK and UNPACK r to operate in terms of any subset of interval attributes of r Consider empty set of attributes first (important!) Define both PACK r ON () and UNPACK r ON () to return r Justification: PACK r ON ()  WITH( r GROUP { } AS X ) AS R1, ( EXTEND R1 ADD ( COLLAPSE ( X ) AS Y ) ) { ALL BUT X } AS R2 : R2 UNGROUP Y /* as usual except for "GROUP { }" */

Copyright © C. J. Date 2005page 113 PACKING AND UNPACKING ON NO ATTRIBUTES (cont.) : l Effectively: R1 = EXTEND r ADD ( TABLE_DEE AS X ) l Effectively: R2 = R1 RENAME ( X AS Y ) l Effectively: Result = R2 without attribute Y = r  Similarly for UNPACK r ON ()

Copyright © C. J. Date 2005page 114 UNPACKING ON SEVERAL ATTRIBUTES : Let r be as follows: A1A2 Consider expression [P1:P1][d08:d09] UNPACK [P1:P2][d08:d08] ( UNPACK r ON A1 ) [P3:P4][d07:d08] ON A2 UNPACK r ON A1 r’UNPACK r’ ON A2 A1A2A1A2 [P1:P1][d08:d09][P1:P1][d08:d08] [P1:P1][d08:d08][P1:P1][d09:d09] [P2:P2][d08:d08][P2:P2][d08:d08] [P3:P3][d07:d08][P3:P3][d07:d07] [P4:P4][d07:d08][P3:P3][d08:d08] [P4:P4][d07:d07] [P4:P4][d08:d08]

Copyright © C. J. Date 2005page 115 UNPACK r ON A2 r’UNPACK r’ ON A1 A1A2A1A2 [P1:P1][d08:d08][P1:P1][d08:d08] [P1:P1][d09:d09][P1:P1][d09:d09] [P1:P2][d08:d08][P2:P2][d08:d08] [P3:P4][d07:d07][P3:P3][d07:d07] [P4:P4][d08:d08][P4:P4][d07:d07] [P3:P3][d08:d08] [P4:P4][d08:d08] Final result is same as before!

Copyright © C. J. Date 2005page 116 SO : UNPACK ( UNPACK r ON A1 ) ON A2  UNPACK ( UNPACK r ON A2 ) ON A1 Generalization: UNPACK ON ( ) /* parens can be omitted if just one */

Copyright © C. J. Date 2005page 117 PACKING ON SEVERAL ATTRIBUTES : Let r be as follows:A1A2 Define PACK r ON (A1,A2)[P2:P4][d01:d04] to involve preliminary[P3:P5][d01:d04] UNPACK r ON (A1,A2) ;[P2:P4][d05:d06] then... [P2:P4][d06:d09] PACK r ON (A1,A2) PACK r ON (A2,A1) A1A2A1A2 [P2:P5][d01:d04][P2:P4][d01:d09] [P2:P4][d05:d09][P5:P5][d01:d04]

Copyright © C. J. Date 2005page 118 SO : PACK ( PACK r ON A1 ) ON A2  PACK ( PACK r ON A2 ) ON A1 Generalization: PACK ON ( ) /* parens can be omitted if just one */

Copyright © C. J. Date 2005page 119 FURTHER CONSEQUENCES AND RAMIFICATIONS : PACK r ON ( A1, … An )  PACK ( … PACK ( PACK r ON A1 ) … ) ON An rA1A2PACK r ON (A2,A1)  no redundancy /* see earlier */ [P2:P4][d01:d04] [P3:P5][d01:d04]PACK (PACK r ON A2) ON A1 [P2:P4][d05:d06]  redundancy [P2:P4][d06:d09]/* [P3:P5] instead of [P5:P5] */ (That’s why we define PACK the way we do)

Copyright © C. J. Date 2005page 120 EQUIVALENCE OF RELATIONS : PACK r ON (A1,A2)PACK r ON (A2,A1) A1A2A1A2 [P2:P5][d01:d04][P2:P4][d01:d09] [P2:P4][d05:d09][P5:P5][d01:d04] l Convey same information! (obviously, since they have the same unpacked form) … In other words, equivalent (wrt A1 and A2) r1 and r2 are equivalent (wrt A1, …, An) if and only if UNPACK r1 ON (A1, …, An) = UNPACK r2 ON (A1,…,An) l But diff "points of view"—left = ranges of parts for given time intervals, right = time intervals for given ranges of parts

Copyright © C. J. Date 2005page 121 EQUIVALENCE OF RELATIONS (cont.) : l To convert left into right: PACK left ON ( A2, A1 )  l left has at most one tuple for any given day, right has at most one tuple for any given part—fluke! Counterexample

Copyright © C. J. Date 2005page 122 ELIMINATING REDUNDANCY : r A1A2 [P3:P8][d01:d04] Two distinct tuples [P5:P9][d03:d08]for part P3 [P1:P7][d07:d10](ditto part P4) PACK r ON (A1,A2)PACK r ON (A2,A1) A1A2A1A2 [P3:P8][d01:d02][P3:P4][d01:d04] [P3:P9][d03:d04][P1:P4] [d07:d10] [P5:P9][d05:d06][P5:P7][d01:d10] [P1:P9][d07:d08][P8:P8][d01:d08] [P1:P7][d09:d10][P9:P9][d03:d08]

Copyright © C. J. Date 2005page 123 ELIMINATING REDUNDANCY (cont.) : l Two packed forms are distinct again l But not as "compact" as original relation! l Both redundancy-free l Let r have interval attributes A1, …, An. Let u be result of UNPACK r ON (A1,…,An). Then r is redundancy-free if and only if every tuple in u derives from exactly one tuple in r. l Any "fully packed" form of any relation is guaranteed to be redundancy-free

Copyright © C. J. Date 2005page 124 ELIMINATING REDUNDANCY (cont.) : r A1A2 [P1:P2][d01:d02] [P1:P4][d03:d04] [P3:P4][d05:d06] PACK r ON (A1,A2)PACK r ON (A2,A1) A1A2A1A2 [P1:P2][d01:d02][P1:P2][d01:d04] [P1:P4][d03:d04][P3:P4] [d03:d06] [P3:P4][d05:d06] l Two packed forms are of same cardinality -- fluke!

Copyright © C. J. Date 2005page 125 ELIMINATING REDUNDANCY (cont.) : Given foregoing examples: Minimum-cardinality fully packed form of r not unique (in general)—i.e., no canonical form that is "more canonical" than all the rest  Exercise: Give all "fully packed" forms of A1A2A3 [S1:S2][P2:P3][d03:d04] [S2:S3][P3:P4][d04:d05]

Copyright © C. J. Date 2005page LAYING THE FOUNDATIONS :  Time and the DB  What’s the problem?  Intervals  Interval operators  The EXPAND and COLLAPSE operators  The PACK and UNPACK operators  Relational operators

Copyright © C. J. Date 2005page 127 RECALL QUERY B : Get S#-DURING pairs for suppliers who have been unable to supply any parts at all during at least one interval of time, where DURING designates a maximal interval during which supplier S# was in fact unable to supply any part at all PACK ( ( UNPACK S_DURING { S#, DURING } ON DURING ) MINUS ( UNPACK SP_DURING { S#, DURING } ON DURING ) ) ON DURING This kind of expression is needed very frequently … So define a shorthand!

Copyright © C. J. Date 2005page 128 "U_MINUS" : USING ( ACL )  R1 MINUS R2  l R1 and R2 must be of same relation type l ACL is a commalist of attribute names in which every attribute mentioned is of some interval type and appears in both relations Shorthand for: PACK ((UNPACK R1 ON ( ACL ) ) MINUS (UNPACK R2 ON ( ACL ) ) ) ON ( ACL ) /* "temporal difference" (deprecated terminology) */

Copyright © C. J. Date 2005page 129 QUERY B : USING DURING  S_DURING { S#, DURING } MINUS SP_DURING { S#, DURING }  /* parens surrounding ACL in USING spec can be omitted*/ /* if ACL contains just one attribute name*/ U_MINUS result can have cardinality > that of left operand! USING A R1R2  R1 MINUS R2  AAA [d02:d04][d03:d03] [d02:d02] [d04:d04]

Copyright © C. J. Date 2005page 130 "U_UNION" : USING ( ACL )  R1 UNION R2  Shorthand for: PACK ( (UNPACK R1 ON ( ACL ) ) UNION (UNPACK R2 ON ( ACL ) ) ) ON ( ACL ) Result can have cardinality < that of either operand! USING A R1R2  R1 UNION R2  AAA [d02:d04][d03:d03][d02:d04] [d04:d04][d04:d04]

Copyright © C. J. Date 2005page 131 A NOTE ON OPTIMIZATION : USING A  R1 UNION R2  Shorthand for: PACK ( R1 UNION R2 ) ON A (i.e., UNPACKs unnec if ACL involves just one attribute) Analogous remarks apply to certain other "U_" ops (details omitted here)

Copyright © C. J. Date 2005page 132 "U_INTERSECT" : USING ( ACL )  R1 INTERSECT R2  Shorthand for: PACK ( ( UNPACK R1 ON ( ACL ) ) INTERSECT (UNPACK R2 ON ( ACL ) ) ) ON ( ACL ) Result can have cardinality > that of either operand! USING A R1R2  R1 INTERSECT R2  AAA [d01:d01][d01:d04] [d03:d07][d06:d09] [d01:d01] [d03:d04] [d06:d07]

Copyright © C. J. Date 2005page 133 EVERY CLASSICAL RELATIONAL OPERATOR HAS ITS "U_" COUNTERPART : "U_restrict" : USING ( ACL )  R WHERE p  Shorthand for: PACK ( ( UNPACK R ON ( ACL ) ) WHERE p ) ON ( ACL ) E.g.: USING DURING  S_DURING WHERE POINT FROM DURING INTERVAL_DATE ([d03:d07])  Result can have cardinality > that of its operand! (Exercise for the reader) 

Copyright © C. J. Date 2005page 134 "U_project" : USING ( ACL )  R { BCL }  Shorthand for: PACK ( ( UNPACK R ON ( ACL ) ) { BCL } ) ON ( ACL ) Every attribute in ACL must be in BCL too Recall Query A: Get S#-DURING pairs for suppliers who have been able to supply at least one part during at least one interval of time, where DURING designates a maximal interval during which supplier S# was in fact able to supply at least one part USING DURING  SP_DURING { S#, DURING } 

Copyright © C. J. Date 2005page 135 "U_JOIN" : USING ( ACL )  R1 JOIN R2  Shorthand for: PACK ( ( UNPACK R1 ON ( ACL ) ) JOIN (UNPACK R2 ON ( ACL ) ) ) ON ( ACL ) Every attribute in ACL must be common to R1 and R2 (thus, join is on at least all attributes in ACL) U_INTERSECT is a special case of U_JOIN

Copyright © C. J. Date 2005page 136 S_CITY_DURING { S#, CITY, DURING } KEY { S#, DURING } Get S#-CITY-P#-DURING tuples such that S# was located in CITY and able to supply P# throughout DURING USING DURING  S_CITY_DURING JOIN SP_DURING  FOR EXAMPLE :

Copyright © C. J. Date 2005page 137 "U_SUMMARIZE" : USING ( ACL )  SUMMARIZE R1 PER R2 ADD ( summary AS B )  Shorthand for: PACK ( SUMMARIZE ( UNPACK R1 ON ( ACL ) ) PER ( UNPACK R2 ON ( ACL’ ) )/* ACL’ = ACL except*/ ADD ( summary AS B ) ) )/* ignore attribs not */ ON ( ACL’ )/* in R2 */ For example: For each part number that has ever been a pmax value, get that part number together with the interval(s) during which it actually was that pmax value USING DURING  SUMMARIZE SP_DURING BY { DURING } ADD ( MAX ( P# ) AS PMAX ) 

Copyright © C. J. Date 2005page 138 RELATIONAL COMPARISONS : USING ( ACL )  R1 op R2  Shorthand for: ( UNPACK R1 ON ( ACL ) ) op ( UNPACK R2 ON ( ACL ) ) E.g.:R1R2A [d01:d03][d01:d02] [d02:d05][d03:d05] [d04:d04] R1 = R2 is false, but USING A  R1 = R2  is true

Copyright © C. J. Date 2005page 139 UNDERLYING INTUITION : An alternative way of thinking about "temporal relations" and the "U_" operators … Consider following temporal relation r: S#DURING S1[d04:d06] S2[d02:d04] S2[d06:d07] S3[d05:d07] S4[d03:d05] Predicate:Supplier S# was under contract during DURING

Copyright © C. J. Date 2005page 140 UNDERLYING INTUITION (cont.) : Can think of r as specifying state of affairs at each of six points in time d02, d03, …, d07 : i.e., can think of r as shorthand for sequence of six separate relations (sequence chronological, of course): r02r03r04r05r06r07 S#S#S#S#S#S# S2S2S1S1S1S2 S4S2S3S2S3 S4S4S3 Let REL_TO_SEQ be the operator that produces the sequence of relations r02, r03,..., r07 from r (and let SEQ_TO_REL be the inverse operator)

Copyright © C. J. Date 2005page 141 UNDERLYING INTUITION (cont.) : Consider (e.g.) U_JOIN Basic idea: 1.Use REL_TO_SEQ... For each individual point in time, apply regular JOIN to pair of relations that correspond to that time point 2.Use SEQ_TO_REL... Put the results of all those individual JOINs back together again U_JOIN = regular join on a time-point-by-time-point basis! Similarly for all of the other U_ ops

Copyright © C. J. Date 2005page 142 REGULAR RELATIONAL OPERATORS REVISITED : Consider U_MINUS once again—USING ( ACL )  R1 MINUS R2  —shorthand for: PACK ((UNPACK R1 ON ( ACL ) ) MINUS ( UNPACK R2 ON ( ACL ) ) ) ON ( ACL ) Suppose ACL is empty … USING ( )  R1 MINUS R2  —shorthand for: PACK ((UNPACK R1 ON ( ) ) MINUS ( UNPACK R2 ON ( ) ) ) ON ( )

Copyright © C. J. Date 2005page 143 BUT … !!! UNPACK r ON () = PACK r ON () = r Expansion reduces to just R1 MINUS R2 !!! Regular MINUS is just a special case of U_MINUS !!! So define MINUS syntax: [ USING ( ) ]  MINUS  /* allow USING specification (and  and  around rest of */ /* expression) to be omitted if and only if <attribute name */ /* commalist> is empty*/

Copyright © C. J. Date 2005page 144 No longer any need to talk about "U_MINUS" as such at all —all MINUS invocations effectively become U_MINUS invocations, and we can generalize the meaning of MINUS accordingly Similarly for all other relational operators: In all cases, regular operator is just that special case of the corresponding "U_" operator in which the USING spec mentions no attributes at all (and hence can be omitted) In other words, don’t need to talk about "U_" operators, as such, at all (except for emphasis) Regular operators permit (but don’t require) additional operand when they are applied to relations with interval attributes