The Relational Model L2DB.

Slides:



Advertisements
Similar presentations
Relational Database Operators
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
D ATABASE S YSTEMS I R ELATIONAL A LGEBRA. 22 R ELATIONAL Q UERY L ANGUAGES Query languages (QL): Allow manipulation and retrieval of data from a database.
Relational Algebra Dashiell Fryer. What is Relational Algebra? Relational algebra is a procedural query language. Relational algebra is a procedural query.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
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 2 The Relational Database Model
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Rutgers University Relational Algebra 198:541 Rutgers University.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Chapter 3 Section 3.4 Relational Database Operators
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
Chapter 7 Relational Algebra. Topics in this Chapter Closure Revisited The Original Algebra: Syntax and Semantics What is the Algebra For? Further Points.
Relational Algebra A presentation for CS 457 By Dawn Haddan.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
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 and Calculas Chapter 4, Part A.
Relational Algebra.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Chapter 5 Relational Algebra and Relational Calculus Pearson Education © 2009.
Advanced Relational Algebra & SQL (Part1 )
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
CMPT 258 Database Systems Relational Algebra (Chapter 4)
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Relational Algebra p BIT DBMS II.
3 1 Database Systems The Relational Database Model.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
1 Relational Algebra and SQL. 2 Relational Query Languages Languages for describing queries on a relational database Relational AlgebraRelational Algebra.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Ritu CHaturvedi Some figures are adapted from T. COnnolly
COMP3017 Advanced Databases
Fundamental of Database Systems
Relational Algebra Chapter 4 1.
Relational Algebra.
Lecture 2 The Relational Model
Theory behind the relational engine
Theory behind the relational engine
Relational Algebra Chapter 4, Part A
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
Chapter 3 The Relational Database Model
Relational Algebra.
Data Base System Lecture 9: Rational Algebra and Relational Calculus
Relational Algebra 1.
Relational Algebra Chapter 4 1.
Database solutions Basic terminology Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology rooms: 3.21 C, 15.
Relational Algebra Chapter 4 - part I.
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Data Manipulation using Relational Algebra
Chapter 2: Intro to Relational Model
Lecture 16 : The Relational Data Model
Lecture 16 : The Relational Data Model
Database Dr. Roueida Mohammed.
CENG 351 File Structures and Data Managemnet
Database solutions Basic terminology Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology rooms: 3.21 C, 15.
Relational Algebra Chapter 4 - part I.
Relational Database Operators
04 SQL & Relational Algebra
Presentation transcript:

The Relational Model L2DB

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

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

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

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)

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

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)

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

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

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

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 R1 R2

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.

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

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

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

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

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

- 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

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.

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

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

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.

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

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

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