Database Systems 04 Relational Algebra

Database Systems 04 Relational Algebra

1 SCIENCE PASSION TECHNOLOGY Database Systems 04 Relational Algebra Matthias Boehm Graz University of Technology, Austria Computer Science and Biomedical Engineering Institute of Interactive Systems and Data Science BMVIT endowed chair for Data Management Last update: Mar 25, 2019 2 Announcements/Org . #1 Video Recording . Since last week, video/audio recording . Link in TeachCenter & TUbe (but not public yet) . #2 Exercise Submission . Submission through TeachCenter (max 5MB, draft possible) . Starting today (deadline Apr 02, 12.59pm ) Nobody left behind (if problems, contact us via newsgroup or email) INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Data Model 3 Recap: Relations and Terminology . Domain D (value domain): e.g., Set S, INT, Char[20] Attribute . Relation R A1 A2 A3 . Relation schema RS: INT INT BOOL Set of k attributes {A 1,…,Ak} 3 7 T . Attribute Aj: value domain Dj = dom(Aj) . Relation: subset of the Cartesian product 1 2 T over all value domains Dj 3 4 F ⊆⊆⊆ ××× ××× ××× ≥≥≥ R D1 D2 ... Dk, k 1 Tuple 1 7 T . Additional Terminology cardinality: 4 . Tuple : row of k elements of a relation rank: 3 . Cardinality of a relation: number of tuples in the relation . Rank of a relation: number of attributes . Semantics: Set := no duplicate tuples (in practice: Bag := duplicates allowed) . Order of tuples and attributes is irrelevant INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Data Model 4 Relational Algebra vs Tuple Calculus . Comparison Calculus-oriented Languages Scheme for Data Sub Languages QUEL ALPHA Relational Calculus (Tuple Calculus ) bidirectional mapping possible (relational completeness ) Relational Algebra [E. F. Codd: Relational Completeness of Data (SQL) Base Sublanguages. IBM Research Report RJ987, 1972 ] Algebra-oriented Languages INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 5 Agenda . Relational Algebra . Tuple Calculus . Physical Operators (Preview Lecture 08) INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 6 Database Research Self-Assessment 2018 PID Firstname Lastname Affiliation LID 102 Anastasia Ailamaki EPFL 1 104 Peter Bailis Stanford 105 Magdalena Balazinska U Washington 3 107 Peter Boncz CWI 2 108 Surajit Chaudhuri MS Research 3 111 Luna Dong Amazon 3 113 Juliana Freire NYU 5 115 Joe Hellerstein UC Berkley 6 116 Stratos Idreos Harvard 7 117 Donald Kossman MS Research 118 Tim Kraska MIT 7 120 Volker Markl TU Berlin 8 122 Tova Milo Tel Aviv University 9 123 C. Mohan IBM Research 10 124 Thomas Neumann TU Munich 11 126 Fatma Ozcan IBM Research 10 130 ChristopherINF.01014UF Databases Re / 706.004 Databases 1 Stanford– 04 Relational Algebra and 4 Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 7 Database Research Self-Assessment 2018, cont. PID … Affiliation LID LID Location 102 EPFL 1 1 Lausanne,SUI 104 Stanford 2 Amsterdam, NLD 105 U Washington 3 3 Seattle, USA 107 CWI 2 4 Stanford, USA 108 MS Research 3 5 New York, USA 111 Amazon 3 6 Berkley, USA 113 NYU 5 7 Cambridge, USA 115 UC Berkley 6 8 Berlin, GER 116 Harvard 7 9 Tel Aviv, ISR 117 MS Research 10 San Jose, USA 118 MIT 7 11 Munich, GER 120 TU Berlin 8 122 Tel Aviv University 9 123 IBM Research 10 124 TU Munich 11 126 IBM Research 10 130INF.01014UF Databases Stanford / 706.004 Databases 1 4 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 8 Relational Algebra INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 9 Core Relational Algebra . Relational Algebra . Operands: relations (normalized, variables for computing new values) . Operators : traditional set operations and specific relational operations . Basic Operations (minimal) . Cartesian product R×××S Traditional Specific . Union R∪∪∪S Set Relational . Difference R–S Operations Operations . Projection πi1, ..., im(R) R×××S . Selection σF(R) Basic πi1, ..., im(R) R∪∪∪S Operations . Derived Operations R–S σF(R) . Intersection R∩∩∩S ⨝ . Join R S Derived R∩∩∩S R⨝S . Division R÷÷÷S Operations R÷÷÷S . Rename ρS(R) INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 10 Extended Relational Algebra . Extended Relational Algebra . Relational algebra introduced with set semantics (no duplicate tuples) . SQL with bag semantics (more flexibility and performance) . Codd’72: In a practical environment it would need to be augmented by a counting and summing capability, together with […] library functions […]. Additional Operations (Ext) . Duplicate elimination δ(R) Basic Ext . Grouping γA,f(B) R Derived . Sorting τA(R) . Bag (aka Multiset) Terminology AB a b . Multiplicity: # occurrences of an instance b c . Cardinality: # tuples (i.e., # instances weighted by multiplicity) a b INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 11 Basic Cartesian Product Ext Derived . Definition: R×××S := {(r,s) | r ∈∈∈ R, s ∈∈∈ S} . Set of all pairs of inputs (equivalent in set /bag ) SF Bay Area . Example LID Location PID Firstname Lastname Affiliation LID 4 Stanford, USA 104 Peter Bailis Stanford 6 Berkley, USA 130 Christopher Re Stanford 4 ××× 10 San Jose, USA PID Firstname Lastname Affiliation LID LID Location 104 Peter Bailis Stanford 4 Stanford, USA 130 Christopher Re Stanford 4 4 Stanford, USA 104 Peter Bailis Stanford 6 Berkley, USA 130 Christopher Re Stanford 4 6 Berkley, USA 104 Peter Bailis Stanford 10 San Jose, USA 130 Christopher Re Stanford 4 10 San Jose, USA INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 12 Basic Union Ext Derived . Definition: R∪∪∪S := {x | x ∈∈∈ R ∨∨∨ x ∈∈∈ S} . Set: set union with duplicate elimination (idempotent: S∪∪∪S = S ) . Bag: bag union (commutative but not idempotent) . Example w/ set semantics Firstname Lastname Affiliation Firstname Lastname Affiliation Anastasia Ailamaki EPFL Anastasia Ailamaki EPFL Peter Boncz CWI Peter Boncz CWI Volker Markl TU Berlin Volker Markl TU Berlin Thomas Neumann TU Munich Thomas Neumann TU Munich Magdalena Balazinska U Washington Firstname Lastname Affiliation Juliana Freire NYU Anastasia Ailamaki EPFL Tova Milo Tel Aviv University Magdalena Balazinska U Washington Juliana Freire NYU Union requires Tova Milo Tel Aviv University compatible schema INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 13 Basic Difference Ext Derived . Definition: R–S := {x | x ∈∈∈ R ∧∧∧ x ∉∉∉ S} (sometimes \) . Set: set difference . Bag: element multiplicity of R minus multiplicity min(R,S) . Example w/ bag semantics Affiliation Affiliation Stanford Stanford U Washington U Washington Affiliation MS Research NYU Amazon MS Research – UC Berkley NYU Amazon Harvard IBM Research UC Berkley MIT Harvard TU Berlin MIT Stanford Difference requires IBM Research compatible schema INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 14 Basic Projection and Selection Ext Derived . Projection πi1, ..., im(R) Example: Affiliation . Set: selection of attributes with πAffiliation (R) w/ EPFL duplicate elimination set semantics Stanford . Bag: selection of attributes U Washington CWI . Extended Projection MS Research Arithmetic expressions: π (R) . A,A*B Amazon . Duplicate occurrences: πA,A,B (R) NYU . Selection (restriction) σ (R) UC Berkley F Harvard . Selection of tuples satisfying the predicate F MIT (equivalent in set /bag ) TU Berlin . Example: σ (R) Affiliation=‘IBM Research‘ Tel Aviv University PID Firstname Lastname Affiliation LID IBM Research 123 C. Mohan IBM Research 10 TU Munich 126 Fatma Ozcan IBM Research 10 INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 15 Query Trees . Composition of Complex Queries . Relational algebra expressions data flow graph (tree) . Leaf nodes represent base relations; root node represent result . Example πFirstname,Affiliation,Location ( σP.LID=L.LID (Participant × Location)) Firstname Affiliation Location πFirstname,Affiliation,Location Anastasia EPFL Lausanne, SUI Magdalena U Seattle, Operations σP.LID=L.LID Washington USA Peter CWI Amsterdam, Intermediates NLD ××× Surajit MS Seattle, Research USA ……… Participant Location INF.01014UF Databases / 706.004 Databases 1 – 04 Relational Algebra and Tuple Calculus Matthias Boehm, Graz University of Technology, SS 2019 Relational Algebra 16 Basic Intersection Ext Derived . Definition R∩∩∩S := R – (R – S) (derived from basic operations) . Set: set intersection derived from difference . Bag: bag intersection, with element multiplicity min(R,S) . Example Firstname Lastname Affiliation Anastasia Ailamaki EPFL Peter Boncz CWI Volker Markl

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    32 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us