Chapter 6 Relational Algebra and The Relational Calculus
Chapter 6 Relational Algebra and The Relational Calculus
Chapter 6 Relational Algebra and The Relational Calculus
Figures (ppt) 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Reference: Ramez Elmasri and Shamkant Navathe, Fundamentals of Database Systems, 5th edition, Addison-Wesley, 2007. See www.aw-bc.com/elmasri Contents: 1. 2. 3. 4. 5. 6. 7. Unary relational operations: SELECT and PROJECT Relational algebra operations from set theory Binary relational operations: JOIN and DIVISION Additional relational operations Examples of queues in relational algebra Tuple relational calculus Domain relational calculus Summary Review questions Exercises Selected bibliography
Importance:
y y y
Foundation for operations on relational models Basis for implementing and optimizing queries in RDBMS Understand how implementation is supposed to work
Chapter 6 is intended to be formal/theoretical SQL is derived from relational algebra and calculus NOT identical Class (or abstract data type) is
y
Attributes
Operations
Chapter 5 Relational Model was about attributes/objects (relations/tables, attributes, domains, constraints) Chapter 6 is about operations that apply to those Chapters 8 & 9 (SQL) is about an implementation
See Table 6.1, p. 191, for summary Exercise: Give an example of each
6.1.1 SELECT
NOT identical to SQL SELECT statement Select a subset of tuples from a relation that satisfy a selection condition Notation: <sigma><selection condition>(R) R - Relational algebra expression whose result is a relation Examples:
y y
<selection condition> - Number of clauses: <attribute name> <comparison op> <constant value> or <attribute name> <comparison op> <attribute name> <attribute name> - Attribute from R <comparison op> - One of {=, <, <=, >, >=, !=}
<constant value> - Constant value from the attribute domain Selection condition clauses connected by AND, OR, NOT Action of SELECT:
y y y
Apply <selection condition> independently to each tuple t in R substituting attributes If TRUE, tuple t is selected No provision for choosing attributes
SELECT is unary - applies to one relation Operation is applied to each tuple individually
6.1.2 PROJECT
SELECT selects some rows from a relation while discarding others PROJECT selects some columns while discarding others Notation: <pi><attribute list>(R) R - Relational algebra expression whose result is a relation <attribute list> - Desired attributes from the relation R Action of PROJECT:
y y y y
Relation containing attributes from <attribute list> From each tuple t in R In the order listed in <attribute list> Removes duplicate tuples
<pi>(T1)
6.1.3 RENAME
Notation: <rho>S(B1, B2, ..., Bn)(R) - Renames relation R to S and attributes Ai to Bi <rho>S(R) - Renames relation R to S <rho>(B1, B2, ..., Bn)(R) - Renames attributes Ai to Bi
Same number of attributes Each corresponding pair of attributes has same domain
UNION and INTERSECTION are commutative and associative SET DIFFERENCE is not commutative
y y y y
New relation Combine every tuple from R with every tuple from S Number of tuples = Number of tuples in R x number of tuples in S (Attributes) = ( Attributes of R, Attributes of S )
6.3.2 EQUIJOIN
<join condition> involves only = Pairs of attributes are equal
<join condition> involves only = Result has only one of the equal pairs
Chapter
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Slides (ppt)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Figures (ppt) 1 2 3 4 5 6 7 8 9 10 11 12 13 14