Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Relational Model L2DB.

Similar presentations


Presentation on theme: "The Relational Model L2DB."— Presentation transcript:

1 The Relational Model L2DB

2 Agenda The Relational Algebra Operations Expressions
Tuple Relational Calculus Domain Relational Calculus Implications for Query Processing Summary

3 Relational Algebra operations
Restrict r Project p Cartesian product ´ Natural join Union  Intersection  Difference - others

4 An example schema Book book# title author classCode publisher year
Member member# surname forename tel# address Loan book# member# dueDate Classification classCode className

5 Restrict r The Restrict operation selects a subset of tuples from the input relation according to some condition Specified by r<selection-condition> (R) Examples: rauthor=‘Dickens Charles’ (Books) rdueDate<= date(‘today’) (R)

6 Restrict in action rtel#=1131 Member member# surname forename tel#
address Shah Hanif 4123 1002 30 High St. Piaf Therese 4178 1131 11, The Crest Thom Natalie 5016 1132 11, The Crest Johns Phil 4268 1098 77, The Lane O’Reilly Sean 5286 1131 11, The Crest rtel#=1131 anon member# surname forename tel# address Piaf Therese 4178 1131 11, The Crest O’Reilly Sean 5286 1131 11, The Crest

7 Project p The Project operation returns a subset of attributes from the input relation Specified by p<attribute-list> (R) Examples: p author,title (Books) p book# (R)

8 Project in action Ptel#,surname Member member# surname forename tel#
address 4123 Shah Hanif 1002 30 High St. 4178 Piaf Therese 1131 11, The Crest 5016 Thom Natalie 1132 11, The Crest 4268 Johns Phil 1098 77, The Lane 5286 O’Reilly Sean 1131 11, The Crest Ptel#,surname anon tel# surname 1002 Shah 1131 Piaf 1132 Thom 1098 Johns 1131 O’Reilly

9 Cartesian Product ´ The Product operator takes in two relations and produces an output in which every tuple in the first relation is matched with every row in the second relation Specified by R1 ´ R2 Note: The operator takes its name from Rene Descartes, the French philosopher mathematician

10 Product in action ´ Loan Member book# member# dueDate member# surname
forename tel# address 57862 4178 22 Sept 08 4123 Shah Hanif 1002 30 High St. 31991 4123 15 Oct 08 4178 Piaf Therese 1131 11, The Crest 22264 4178 02 Sept 08 anon book# member# dueDate member# surname forename tel# address 57862 4178 22 Sept 08 4123 Shah Hanif 1002 30 High St. 57862 4178 22 Sept 08 4178 Piaf Therese 1131 11, The Crest 31991 4123 15 Oct 08 4123 Shah Hanif 1002 30 High St. 31991 4123 15 Oct 08 4178 Piaf Therese 1131 11, The Crest 22264 4178 02 Sept 08 4123 Shah Hanif 1002 30 High St. 22264 4178 02 Sept 08 4178 Piaf Therese 1131 11, The Crest

11 Natural join Natural join is the most common form of Join operation. It combines the data from two relations by matching values on attributes with the same name. Specified by R R2

12 Natural join in action Loan Member book# member# dueDate member# surname forename tel# address 57862 4178 22 Sept 08 4123 Shah Hanif 1002 30 High St. 31991 4123 15 Oct 08 4178 Piaf Therese 1131 11, The Crest 22264 4178 02 Sept 08 anon book# member# dueDate surname forename tel# address 57862 4178 22 Sept 08 Piaf Therese 1131 11, The Crest 31991 4123 15 Oct 08 Shah Hanif 1002 30 High St. 22264 4178 02 Sept 08 Piaf Therese 1131 11, The Crest Note: the effect of a natural join can be achieved by a Cartesian Product followed by a Restrict and a Project - see if you can work out how.

13 Union  Union takes in two compatible relations and returns a relation that contains the tuples that appear in either or both. The relational algebra demands that the input relations are compatible, i.e. they are of the same type

14 Union in action  StaffLoan StudentLoan book# member# dueDate book#
57862 4178 22 Sept 08 31991 4123 15 Oct 08 31991 4123 15 Oct 08 32277 4178 18 Sept 08 22264 4178 02 Sept 08 59999 4690 29 Oct 08 59999 4691 29 Oct 08 anon book# member# dueDate 57862 4178 22 Sept 08 31991 4123 15 Oct 08 22264 4178 02 Sept 08 32277 4178 18 Sept 08 59999 4690 29 Oct 08 59999 4691 29 Oct 08

15 Intersection  Intersection takes in two compatible relations and returns a relation that contains the tuples that appear in both. Again the relational algebra demands that the input relations are compatible, i.e. they are of the same type

16 Intersection in action
StaffLoan StudentLoan book# member# dueDate book# member# dueDate 57862 4178 22 Sept 08 31991 4123 15 Oct 08 31991 4123 15 Oct 08 32277 4178 18 Sept 08 22264 4178 02 Sept 08 59999 4690 29 Oct 08 59999 4691 29 Oct 08 anon book# member# dueDate 31991 4123 15 Oct 08

17 Difference - The difference operator takes in two compatible relations X and Y and returns a relation that contains the tuples that appear in X but NOT in Y

18 - Difference in action StaffLoan StudentLoan book# member# dueDate
57862 4178 22 Sept 08 31991 4123 15 Oct 08 31991 4123 15 Oct 08 32277 4178 18 Sept 08 22264 4178 02 Sept 08 59999 4690 29 Oct 08 59999 4691 29 Oct 08 anon book# member# dueDate 57862 4178 22 Sept 08 22264 4178 02 Sept 08

19 Other operators Codd originally described a set of eight operators
Some of these operators are not essential because they can be derived from others Many authors have contributed further operators to the algebra divide, semijoin, outer join, … The set of operators provided in any relational implementation is relationally complete if it is at least as powerful as Codd’s original set.

20 Relational Algebra expressions
The power of relational algebra arises from its ability to compose expressions Examples p title (rauthor=‘Greene Graham’ (Book)) will return the titles of books written by Graham Greene p title,author(rmember#=4128 (Loan Book)) will return the titles and authors of books on loan to library member 4128

21 Relational Algebra trees
p title((rmember#=4128 Loan) Book) Member ) An expression, such as the above can be represented as a tree: p title Expression result Intermediate results rmember#=4128 Loan Book Member Base relvars

22 Equivalence of algebra expressions
Consider the following two expressions p title,surname((rmember#=4128 Loan) Book) Member ) ptitle,surname(rmember#=4128 ((Loan Book)) (psurname,member#Member ))) The expressions are quite different in the operations, particularly in the order in which the operations are applied. However, the two expressions will always yield the same result i.e. the expressions are equivalent. If we consider, the size of the intermediate results and the number of tuples processed by each operator, we can assess that the first expression is likely to be more efficient than the second.

23 Implications for Query Processing
The database query language SQL is (loosely) based on the tuple relational calculus The database query language QBE is based on the domain relational calculus Either of these can be converted into relational algebra, which provides a processing model to execute the query In a relational DBMS a software component known as a Query Optimizer converts a query into an efficient operation tree that is similar to the relational algebra

24 Summary The relational model comprises: The model
a structural specification a means of enforcing integrity a means of manipulating data The model provides a solid theoretical basis for database processing, based on set theory and first-order predicate logic supplies the foundation for relational DBMS implementation

25 Caveat Commercial RDBMS products and the SQL standard language are based on the relational model However, none of them conform to the relational model the extent to which existing systems deviate from the model and the implications of this is a matter of great controversy see the reading list for further study of this area


Download ppt "The Relational Model L2DB."

Similar presentations


Ads by Google