Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science 15-415 - Database Applications C. Faloutsos Relational model.

Slides:



Advertisements
Similar presentations
CMU SCS Carnegie Mellon Univ. School of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture #4: Relational Algebra.
Advertisements

CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture#6: Rel. model - SQL part1 (R&G, chapter.
Relational Algebra Tim Kaddoura CS157A. Introduction  Relational query languages are languages for describing queries on a relational database  Three.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Integrity Constraints.
Relational Algebra Ch. 7.4 – 7.6 John Ortiz. Lecture 4Relational Algebra2 Relational Query Languages  Query languages: allow manipulation and retrieval.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
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.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Lecture#7 (cont’d): Rel. model - SQL part3.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Relational Algebra Relational Calculus. Relational Algebra Operators Relational algebra defines the theoretical way of manipulating table contents using.
Introduction to Database Systems 1 Relational Algebra Relational Model: Topic 3.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos E-R diagrams.
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.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture#7 : Rel. model - SQL part2 (R&G, chapters.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Rel. model - SQL part1.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model – SQL Part I (based on notes by Silberchatz,Korth,
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model III (based on notes by Silberchatz,Korth, and.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model – SQL Part II (based on notes by Silberchatz,Korth,
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
Relational Algebra - Chapter (7th ed )
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science Database Applications Lecture#6: Relational calculus.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
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.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Rel. model - SQL part3.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Relational Model I (based on notes by Silberchatz,Korth, and Sudarshan.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Part a The Relational Algebra and Relational Calculus Hours 1,2.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational domain calculus.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 – DB Applications C. Faloutsos & A. Pavlo Lecture#5: Relational calculus.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization - Functional Dependencies.
1 CS 430 Database Theory Winter 2005 Lecture 5: Relational Algebra.
CMPT 258 Database Systems Relational Algebra (Chapter 4)
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Rel. model - SQL part2.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Temple University – CIS Dept. CIS616– Principles of Data Management V. Megalooikonomou Relational Model – SQL (based on notes by Silberchatz,Korth, and.
1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou SQL (part 2) (based on slides by C. Faloutsos at CMU)
IST 210 The Relational Language Todd S. Bacastow January 2005.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Database design and normalization.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational tuple calculus.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Temple University – CIS Dept. CIS616– Principles of Database Systems V. Megalooikonomou Relational Model (based on notes by Silberchatz,Korth, and Sudarshan.
April 20022CS3X1 Database Design Relational algebra John Wordsworth Department of Computer Science The University of Reading Room.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
COMP3017 Advanced Databases
Lecture #4: Relational Algebra
Database Applications (15-415) Relational Calculus Lecture 6, September 6, 2016 Mohammad Hammoud.
Faloutsos & Pavlo SCS /615 Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization.
LECTURE 3: Relational Algebra
The Relational Algebra and Relational Calculus
Lecture#5: Relational calculus
Lecture #17: Schema Refinement & Normalization - Normal Forms
Computer Science 317 Database Management
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Presentation transcript:

Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Relational model

Carnegie Mellon C. Faloutsos2 Overview history concepts Formal query languages –relational algebra –rel. tuple calculus –rel. domain calculus

Carnegie Mellon C. Faloutsos3 History before: records, pointers, sets etc introduced by E.F. Codd in 1970 revolutionary! first systems: (System R; Ingres) Turing award in 1981

Carnegie Mellon C. Faloutsos4 Concepts Database: a set of relations (= tables) rows: tuples columns: attributes (or keys) superkey, candidate key, primary key

Carnegie Mellon C. Faloutsos5 Example Database:

Carnegie Mellon C. Faloutsos6 Example: cont’d Database: rel. schema (attr+domains) tuple k-th attribute (Dk domain)

Carnegie Mellon C. Faloutsos7 Example: cont’d rel. schema (attr+domains) instance

Carnegie Mellon C. Faloutsos8 Example: cont’d rel. schema (attr+domains) instance Di: the domain of the I-th attribute (eg., char(10) Formally: an instance is a subset of (D1 x D2 x …x Dn)

Carnegie Mellon C. Faloutsos9 Example: cont’d superkey (eg., ‘ssn, name’): determines record cand. key (eg., ‘ssn’, or ‘st#’): minimal superkey primary key: one of the cand. keys

Carnegie Mellon C. Faloutsos10 Overview history concepts Formal query languages –relational algebra –rel. tuple calculus –rel. domain calculus

Carnegie Mellon C. Faloutsos11 Formal query languages How do we collect information? Eg., find ssn’s of people in 415 (recall: everything is a set!) One solution: Rel. algebra, ie., set operators Q1: Which ones?? Q2: what is a minimal set of operators?

Carnegie Mellon C. Faloutsos12. set union U set difference ‘-’ Relational operators

Carnegie Mellon C. Faloutsos13 Example: Q: find all students (part or full time) A: PT-STUDENT union FT-STUDENT

Carnegie Mellon C. Faloutsos14 Observations: two tables are ‘union compatible’ if they have the same attributes (‘domains’) Q: how about intersection U

Carnegie Mellon C. Faloutsos15 Observations: A: redundant: STUDENT intersection STAFF = STUDENT - (STUDENT - STAFF) STUDENT STAFF

Carnegie Mellon C. Faloutsos16. set union set difference ‘-’ Relational operators U

Carnegie Mellon C. Faloutsos17 Other operators? eg, find all students on ‘Main street’ A: ‘selection’

Carnegie Mellon C. Faloutsos18 Other operators? Notice: selection (and rest of operators) expect tables, and produce tables (-> can be cascaded!!) For selection, in general:

Carnegie Mellon C. Faloutsos19 Selection - examples Find all ‘Smiths’ on ‘Forbes Ave’ ‘condition’ can be any boolean combination of ‘=‘, ‘>’, ‘>=‘,...

Carnegie Mellon C. Faloutsos20 selection. set union set difference R - S Relational operators R U S

Carnegie Mellon C. Faloutsos21 selection picks rows - how about columns? A: ‘projection’ - eg.: finds all the ‘ssn’ - removing duplicates Relational operators

Carnegie Mellon C. Faloutsos22 Cascading: ‘find ssn of students on ‘forbes ave’ Relational operators

Carnegie Mellon C. Faloutsos23 selection projection. set union set difference R - S Relational operators R U S

Carnegie Mellon C. Faloutsos24 Are we done yet? Q: Give a query we can not answer yet! Relational operators

Carnegie Mellon C. Faloutsos25 A: any query across two or more tables, eg., ‘find names of students in ’ Q: what extra operator do we need?? A: surprisingly, cartesian product is enough! Relational operators

Carnegie Mellon C. Faloutsos26 Cartesian product eg., dog-breeding: MALE x FEMALE gives all possible couples x =

Carnegie Mellon C. Faloutsos27 so what? Eg., how do we find names of students taking 415?

Carnegie Mellon C. Faloutsos28 Cartesian product A:

Carnegie Mellon C. Faloutsos29 Cartesian product

Carnegie Mellon C. Faloutsos30

Carnegie Mellon C. Faloutsos31 selection projection cartesian product MALE x FEMALE set union set difference R - S FUNDAMENTAL Relational operators R U S

Carnegie Mellon C. Faloutsos32 Relational ops Surprisingly, they are enough, to help us answer almost any query we want!! derived operators, for convenience –set intersection –join (theta join, equi-join, natural join) –‘rename’ operator –division

Carnegie Mellon C. Faloutsos33 Joins Equijoin:

Carnegie Mellon C. Faloutsos34 Cartesian product A:

Carnegie Mellon C. Faloutsos35 Joins Equijoin: theta-joins: generalization of equi-join - any condition

Carnegie Mellon C. Faloutsos36 Joins very popular: natural join: R S like equi-join, but it drops duplicate columns: STUDENT(ssn, name, address) TAKES(ssn, cid, grade)

Carnegie Mellon C. Faloutsos37 Joins nat. join has 5 attributes equi-join: 6

Carnegie Mellon C. Faloutsos38 Natural Joins - nit-picking if no attributes in common between R, S: nat. join -> cartesian product:

Carnegie Mellon C. Faloutsos39 Overview - rel. algebra fundamental operators derived operators –joins etc –rename –division examples

Carnegie Mellon C. Faloutsos40 rename op. Q: why? A: shorthand; self-joins; … for example, find the grand-parents of ‘Tom’, given PC(parent-id, child-id)

Carnegie Mellon C. Faloutsos41 rename op. PC(parent-id, child-id)

Carnegie Mellon C. Faloutsos42 rename op. first, WRONG attempt: (why? how many columns?) Second WRONG attempt:

Carnegie Mellon C. Faloutsos43 rename op. we clearly need two different names for the same table - hence, the ‘rename’ op.

Carnegie Mellon C. Faloutsos44 Overview - rel. algebra fundamental operators derived operators –joins etc –rename –division examples

Carnegie Mellon C. Faloutsos45 Division Rarely used, but powerful. Example: find suspicious suppliers, ie., suppliers that supplied all the parts in A_BOMB

Carnegie Mellon C. Faloutsos46 Division

Carnegie Mellon C. Faloutsos47 Division Observations: ~reverse of cartesian product It can be derived from the 5 fundamental operators (!!) How?

Carnegie Mellon C. Faloutsos48 Division Answer:

Carnegie Mellon C. Faloutsos49 Overview - rel. algebra fundamental operators derived operators –joins etc –rename –division examples

Carnegie Mellon C. Faloutsos50 Sample schema find names of students that take

Carnegie Mellon C. Faloutsos51 Examples find names of students that take

Carnegie Mellon C. Faloutsos52 Sample schema find course names of ‘smith’

Carnegie Mellon C. Faloutsos53 Examples find course names of ‘smith’

Carnegie Mellon C. Faloutsos54 Examples find ssn of ‘overworked’ students, ie., that take 412, 413, 415

Carnegie Mellon C. Faloutsos55 Examples find ssn of ‘overworked’ students, ie., that take 412, 413, 415: almost correct answer: U U U

Carnegie Mellon C. Faloutsos56 Examples find ssn of ‘overworked’ students, ie., that take 412, 413, Correct answer: U U U c-name=413 c-name=415

Carnegie Mellon C. Faloutsos57 Examples find ssn of students that work at least as hard as ssn=123 (ie., they take all the courses of ssn=123, and maybe more

Carnegie Mellon C. Faloutsos58 Sample schema

Carnegie Mellon C. Faloutsos59 Examples find ssn of students that work at least as hard as ssn=123 (ie., they take all the courses of ssn=123, and maybe more

Carnegie Mellon C. Faloutsos60 Conclusions Relational model: only tables (‘relations’) relational algebra: powerful, minimal: 5 operators can handle almost any query! most non-trivial op.: join