R ELATIONAL A LGEBRA Joe Meehean 1. T ABLES FOR T ODAY ’ S L ECTURE 2 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre3.74 967CrumbRobertArt2.3.

Slides:



Advertisements
Similar presentations
Relational Database Operators
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Relational Algebra Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
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.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
Relational Algebra Ch. 7.4 – 7.6 John Ortiz. Lecture 4Relational Algebra2 Relational Query Languages  Query languages: allow manipulation and retrieval.
A DVANCED SQL Joe Meehean 1. SQL S ET O PERATIONS Syntax SELECT column1, column2, … FROM table1… WHERE conditions SET_KEYWORD SELECT column1, column2,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Relational Algebra 1 Chapter 5.1 V3.0 Napier University Dr Gordon Russell.
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.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
D ATABASE S YSTEMS I A DMIN S TUFF. 2 Mid-term exam Tuesday, Oct 2:30pm Room 3005 (usual room) Closed book No cheating, blah blah No class on Oct.
Oct 28, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
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.
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.
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.
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
CS 4432query processing1 CS4432: Database Systems II.
Introduction to Database Systems 1 Relational Algebra Relational Model: Topic 3.
Relational Algebra. Relational Query Languages n Query = “retrieval program” n Language examples: ù Theoretical : 1. Relational Algebra 2. Relational.
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.
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.
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra.
Databases Illuminated
Chapter 3 Section 3.4 Relational Database Operators
Copyright © Curt Hill The Relational Algebra What operations can be done?
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Relational Algebra References: Databases Illuminated by Catherine Ricardo, published by Jones and Bartlett in 2004 Fundamentals of Relational Databases.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
Relational Algebra  Souhad M. Daraghma. Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational.
I NTRODUCTION TO SQL II. T ABLE JOINS A simple SQL select statement is one that selects one or more columns from any single table There are two types.
R EVIEW. 22 Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000.
CS 4432query processing1 CS4432: Database Systems II Lecture #11 Professor Elke A. Rundensteiner.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
CS424 Relational Data Manipulation Relational Data Manipulation Relational tables are sets. Relational tables are sets. The rows of the tables can be considered.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
Relational Algebra MBAD 613 R. Nakatsu. Relational Data Manipulation Language Query-by-Example; Query-by-Form Transform-Oriented Languages Relational.
Advanced Relational Algebra & SQL (Part1 )
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
Views, Algebra Temporary Tables. Definition of a view A view is a virtual table which does not physically hold data but instead acts like a window into.
CMPT 258 Database Systems Relational Algebra (Chapter 4)
Relational Algebra p BIT DBMS II.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Basic SQL Queries.
Database Systems (資料庫系統)
CS4432: Database Systems II
Relational Algebra Chapter 4 1.
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.
Database Systems 10/13/2010 Lecture #4.
Relational Algebra.
Relational Algebra 1.
LECTURE 3: Relational Algebra
Relational Algebra Chapter 4 1.
More Relational Algebra
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Chapter 2: Intro to Relational Model
CENG 351 File Structures and Data Managemnet
Presentation transcript:

R ELATIONAL A LGEBRA Joe Meehean 1

T ABLES FOR T ODAY ’ S L ECTURE 2 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre CrumbRobertArt VogelzangAnnaMusic ParkPhilCS ParkAnnaCS3.9 OfferingIDStdNoCredits AA77324 BB87323 OfferingIDCourseName AA7Calculus I BB8Art History Students Enrolled Offering

R ELATIONAL A LGEBRA Algebra for tables Transform 1 or more tables into another table Based on a small set of operators 3

A LTERNATIVE T ERMINOLOGY Table-Oriented (Database) Set-Oriented (Mathematics) TableRelation RowTuple ColumnAttribute ANDΛ ORV 4

S ELECTION O PERATOR Represented by σ symbol AKA restrict operator Produces a subset of the input relation (table) subset of the tuples (rows) Uses condition to indicate which rows to retain condition can include: =, ≠,, ≥, ≤, V, Λ e.g., for relation Students(stdno, last_name, first_name, major, gpa) σ gpa > 3.5 (Students) gives the students that have gpa greater than 3.5 5

S ELECTION O PERATOR Conceptual Picture 6 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre CrumbRobertArt VogelzangAnnaMusic ParkPhilCS ParkAnnaCS3.9

S ELECTION O PERATOR Conceptual Picture 7 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre CrumbRobertArt VogelzangAnnaMusic ParkPhilCS ParkAnnaCS3.9

P ROJECTION O PERATOR Represented by π Produces a subset of the input table subset of the columns e.g., π last_name,major Student gives the Student relation without the first_name and stdnr attributes Also removes duplicates projection removes attributes, so duplicate rows can occur these duplicates are removed real database systems often do not remove duplicates 8

P ROJECTION O PERATOR Conceptual Picture 9 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre CrumbRobertArt VogelzangAnnaMusic ParkPhilCS ParkAnnaCS3.9

P ROJECTION O PERATOR Conceptual Picture 10 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre CrumbRobertArt VogelzangAnnaMusic ParkPhilCS ParkAnnaCS3.9

P ROJECTION O PERATOR Conceptual Picture 11 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre CrumbRobertArt VogelzangAnnaMusic ParkPhilCS ParkAnnaCS3.9

P RODUCT O PERATOR Represented by × AKA extended cross product operator Produces all possible combination of tuples (rows) between 2 relations (tables) # tuples (rows) in output # tuples in input1 * # tuples in input2 # attributes (columns) in output # attributes in input1 + #attributes in input2 12

P RODUCT E XAMPLE Student × Enrolled 13 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre VogelzangAnnaMusic3.5 OfferingIDStdNoCredits AA77324 BB87323 StdNoLast NameFirst Name MajorGPAOffering ID StdNoCredits 732ArnettWillTheatre3.74AA ArnettWillTheatre3.74BB VogelzangAnnaMusic3.5AA VogelzangAnnaMusic3.5BB8 7323

J OIN O PERATOR Represented by Also combines 2 tables Requires a condition between tuples all conditions from selection are OK Join is derived from product and selection R c S = σ c (R × S) 14

J OIN O PERATOR Equi-join matching condition is that 2 rows have same value for some attribute(s) c = d Natural join two relations have same attribute values of attributes must match for tuple to be included duplicate attribute is not included in resulting relation no need to include condition for natural join 15

J OIN O PERATOR E XAMPLE Student Enrolled 16 StdNoLast Name First Name MajorGPA 732ArnettWillTheatre VogelzangAnnaMusic3.5 OfferingIDStdNoCredits AA77324 BB87323 StdNoLast NameFirst Name MajorGPAOffering ID Credits 732ArnettWillTheatre3.74AA ArnettWillTheatre3.74BB8 3

Q UESTIONS ? 17

Q UICK R EVIEW Select operator (σ) removes tuples (rows) from relation (table) Project operator (π) removes attributes (columns) from relation (table) Cross product operator (×) combines attributes from 2 relations matches every tuple from both input relations Join operator ( ) combines attributes from 2 relations matches tuples based on condition often same value for an attribute 18

R ENAME O PERATOR Represented by ρ Renames relations or attributes (or both) Rename relation ρ(Z, A) relation A is now called Z Rename attributes ρ((old1 → new1, old2 → new2, old3 → new3), A) A’s attributes old1, old2, and old3 are renamed 19

R ENAME O PERATOR Rename both attributes and relation ρ(Z, (old1 → new1, old2 → new2, old3 → new3), A) Simplify expressions ρ( music_majors, σ major = music student) π last_name, first_name (σ gpa > 3.5 music_majors) 20

U NION O PERATOR Represented by U Combines two relations Result contains all tuples in both relations e.g., orange and green parts σ major = music students U σ major = theatre students 21

I NTERSECTION O PERATOR Represented by ∩ Combines two relations Results contains only tuples that are in both input relations e.g., music majors with good gpa σ major = music students ∩ σ gpa > 3.5 students 22

D IFFERENCE O PERATOR Represented by − Combines two relations Tuples in the first table, but not in second e.g. music majors that don’t have a good gpa σ major = music students − ­­ σ gpa > 3.5 students 23

U NION C OMPATIBLE Relations are union compatible if they have the same number of attributes AND corresponding attributes have the same data type (ints, chars, etc…) usually means relations have same attributes Union, intersect, and difference require union compatible relations e.g. red parts supplied by XYZ ρ(XYZparts, parts (catalog σ sname=XYZ supplier)) σ color = red parts ∩ π pname, pid, color XYZparts 24

D IVISION O PERATOR Represented by / Combines two relations, A & B A has two attributes (x,y) B has one attribute (y) A/B is all x’s such that (x,y) exists in A for all y’s in B Result has only a singe atribute (x) 25

D IVISION O PERATOR For each x value in A consider the set of y values x maps to in A if this set contains all y values in B then x is in A/B e.g. student enrolled in all offerings ρ(super_student_ids, π std_no,offering_id enrolled / π offering_id offerings) π lastname, firstname (students super_student_ids) 26

D IVISION O PERATOR Derive A/B think about what doesn’t belong in result get set of all x,y mappings (π x A) × B remove those mappings that appear in A ((π x A) × B) − A what’s left must be x’s that don’t map to all y’s π x ( ((π x A) × B) − A ) remove them from the set of x’s π x A − π x ( ((π x A) × B) − A ) 27

Q UESTIONS ? 28