Matt Dube Doctoral Student, Spatial Information Science and Engineering Predicates, Joins, and Algebra, Oh my!

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 5A Relational Algebra.
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.
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Algebra Fall 2014.
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.
1 Relational Algebra. Motivation Write a Java program Translate it into a program in assembly language Execute the assembly language program As a rough.
Relational Algebra Dashiell Fryer. What is Relational Algebra? Relational algebra is a procedural query language. Relational algebra is a procedural query.
Relational Algebra Ch. 7.4 – 7.6 John Ortiz. Lecture 4Relational Algebra2 Relational Query Languages  Query languages: allow manipulation and retrieval.
CS4432: Database Systems II Query Operator & Algebraic Expressions 1.
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
Relational Algebra – Basis for Relational Query Languages Based on presentation by Juliana Freire.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
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.
Nov 18, 2003Murali Mani Relational Algebra B term 2004: lecture 10, 11.
Murali Mani Relational Algebra. Murali Mani What is Relational Algebra? Defines operations (data retrieval) for relational model SQL’s DML (Data Manipulation.
PHP and MySQL Code Reuse, OO, Error Handling and MySQL (Intro)
RELATIONAL ALGEBRA Objectives
Formal Theories SIE 550 Lecture Matt Dube Doctoral Student - Spatial.
Chapter 3 Section 3.4 Relational Database Operators
Relational Algebra Instructor: Mohamed Eltabakh 1.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Chapter 9 Joining Data from Multiple Tables
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Relational Algebra (Chapter 7)
Relational Algebra – Part 2
Advanced Relational Algebra & SQL (Part1 )
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)
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
CSC271 Database Systems Lecture # 7. Summary: Previous Lecture  Relational keys  Integrity constraints  Views.
Relational Algebra Instructor: Mohamed Eltabakh 1.
LECTURE THREE RELATIONAL ALGEBRA 11. Objectives  Meaning of the term relational completeness.  How to form queries in relational algebra. 22Relational.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
Ritu CHaturvedi Some figures are adapted from T. COnnolly
COMP3017 Advanced Databases
Module 2: Intro to Relational Model
COP4710 Database Systems Relational Algebra.
Properties of Operations for Real Numbers
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Relational Model
Set, Combinatorics, Probability & Number Theory
Relational Algebra - Part 1
Relational Algebra at a Glance
Relational Algebra Chapter 4 1.
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.
LECTURE 3: Relational Algebra
Relational Algebra Chapter 4 1.
The Relational Algebra and Relational Calculus
Instructor: Mohamed Eltabakh
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Chapter 2: Intro to Relational Model
The Relational Algebra
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Syllabus Introduction Website Management Systems
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Unit Relational Algebra 1
Relational Algebra Chapter 4 - part I.
Chapter 4 Relational Algebra
Presentation transcript:

Matt Dube Doctoral Student, Spatial Information Science and Engineering Predicates, Joins, and Algebra, Oh my!

Wednesday’s Lecture Projection (unary) Horizontal reduction Selection (unary) Vertical reduction Renaming (unary) Making attributes kosher Cartesian Product (binary or more) Most expensive operator, consisting of all possible combinations Union (binary or more) Linker Difference (binary or more) What’s mine is only mine

Today Relations as first order language predicates Efficiencies in combination Algebra Join

Projection Projection takes a tuple and reduces its number of attributes dog(fido,dalmatian,bob). Suppose we would like a table that stored only the owner’s name and the dog’s name. petname(A,B):-dog(B,C,A). This is a projection.

Selection Selections act upon particular criteria dog(fido,dalmatian,bob). Suppose we want to return anyone who owns a dalmatian and what the name of the dog is dalmatian(A,B):-dog(A,dalmatian,B). This is a selection. Note the constant for the variable.

Renaming Renaming changes the name of an attribute or a relation. dog(fido,dalmatian,bob). Suppose I now want to call all dogs hippos. hippo(A,B,C):-dog(A,B,C). This is a renaming. It makes more sense with an attribute if you consider attributes spilled out in binary listings.

Cartesian Product Cartesian products bind two different relations together, maintaining all attributes dog(fido,dalmatian,bob). coffee(starbucks,brazil). Suppose we want something to give us data about all coffee and dogs javadog(A,B,C,D,E):-coffee(A,B),dog(C,D,E). This is a Cartesian product. Note that it is an AND statement and needs all variables.

Union Unions link different relations together in similar strucutres dog(fido,dalmatian,bob). cat(mittens,coon,matt). Suppose we want to know all pets. Dogs and cats are pets. pet(A,B,C):-dog(A,B,C) ∨ cat(A,B,C). This is a union of the dog relation and the cat relation.

Difference Differences show what is in one set, but not the other dog(fido,dalmatian,bob). cat(fido,dalmatian,bob). dog(rover,pitbull,joe). Suppose I want to find dogs who don’t share qualities with a cat. onlydog(A,B,C):-dog(A,B,C),cat(A,B,C),!. (fail it) onlydog(A,B,C):-dog(A,B,C). Only unique dogs are produced here.

Combination of Operations All of our operators produce relations Remember, some of the operators need to refine the output to have a relation output (think projection of a non-key) Since all operators produce relations, this system of operators is a closed system Closed systems take in inputs of a particular form (in our case relation) and output that form in return. Since the system is closed, we can string together operators.

Equivalent Combinations π a 1,…,a n ( σ A (R)) = σ A ( π a 1,…,a n (R)) σ A (R – P) = σ A (R) – σ A (P) σ A ∧ B (R) = σ A ( σ B (R)) = σ B ( σ A (R)) σ A ∨ B (R) = σ A (R) ∪ σ B (R) σ A (R x P) = σ B ∧ C ∧ D (R x P) = σ D ( σ B (R) x σ C (P))

Optimization π a 1,…,a n ( σ A (R)) = σ A ( π a 1,…,a n (R)) σ A (R – P) = σ A (R) – σ A (P) σ A ∧ B (R) = σ A ( σ B (R)) = σ B ( σ A (R)) σ A ∨ B (R) = σ A (R) ∪ σ B (R) σ A (R x P) = σ B ∧ C ∧ D (R x P) = σ D ( σ B (R) x σ C (P)) Project, then select. Difference, then select. Union, then select. Break apart complex selections

Algebra From the arabic Al-jabr, meaning “reunion” Algebras are mathematical structures formed off of operators You are familiar with an algebra from your studies in mathematics (+, -, *, /), which can be boiled down to simply + and * Algebras are closed systems under their operators and also have identities for every operator (+ 0, - 0, * 1, / 1)

Relational Algebra What is the identity form for each operator? Projection Project all of the attributes Selection Select the entire key structure Renaming Rename the attribute to the same name Cartesian Product Cross with an empty relation Union Union with a subset of the original relation Difference Difference with a mutually exclusive set

Why is an Algebra important? Algebras (reunions) are what allows for operations to be strung together An example of an important consequence: operational efficiency You have seen the relational algebra equivalencies, but there is an easier example that you already know.

Here’s the test: What are the key properties of an algebra? Closed under operations Every operation has an identity state Why is an algebra important for a system? Stringing together operators Efficient processes (think the distributive property) Operational equivalence

Joins Joins are what we would call a higher level operation Higher level operation? Think of an exponent (successive multiplications of terms) Why can we use higher level operations? (You already know the answer…) Most important operator for some key reasons Done by imposing a condition on a pair of attributes

Types of Joins Inner Joins Equi-Joins Natural Joins Outer Joins

Inner Join Selection on a Cartesian Product Selection involves some sort of criteria between a member of one relation and a member of the other (similar to the keys for the Cartesian product)

Inner Join a1a2 abc45 cde52 b1b2 45zyx 23ijk σ A.a2>B.b1 (A x B) AB

Inner Join a1a2b1b2 ab c 45 zyx ab c 4523ijk cd e 5245zyx cd e 5223ijk σ A.a2>B.b1 (A x B) A x B

Inner Join a1a2b1b2 ab c 45 zyx ab c 4523ijk cd e 5245zyx cd e 5223ijk σ A.a2>B.b1 (A x B) A x B

Inner Join a1a2b1b2 ab c 45 zyx ab c 4523ijk cd e 5245zyx cd e 5223ijk σ A.a2>B.b1 (A x B) A x B

Inner Join a1a2b1b2 ab c 4523ijk cd e 5245zyx cd e 5223ijk σ A.a2>B.b1 (A x B)

Equi-Join Another selection on a Cartesian product As the name implies, this has to do with two of the attributes being equal

Equi-Join a1a2 abc45 cde52 b1b2 45zyx 23ijk σ A.a2=B.b1 (A x B) AB

Equi-Join a1a2b1b2 ab c 45 zyx ab c 4523ijk cd e 5245zyx cd e 5223ijk σ A.a2=B.b1 (A x B) A x B

Equi-Join a1a2b1b2 ab c 45 zyx σ A.a2=B.b1 (A x B)

Natural Join σ (A x B) attribute_1 and attribute_2 must have same name only one column with this attribute shows up in the result (i.e., a projection follows) Selection on a Cartesian product (Equi-Join) followed by a projection

Natural Join xxyy abc45 cde52 yyzz 45zyx 23ijk σ A.yy=B.yy (A x B) AB

Natural Join xxyy zz ab c 45 zyx ab c 4523ijk cd e 5245zyx cd e 5223ijk σ A.a2=B.b1 (A x B) A x B

Natural Join xxyy zz ab c 45 zyx π ( σ A.a2=B.b1 (A x B))

Natural Join xxyyzz abc45zyx π ( σ A.a2=B.b1 (A x B))

Outer Joins An outer join is a join which allows for NULL values to be involved Three types Left Outer Join Everything in the left relation will be present, regardless if found in B or not Right Outer Join Everything in the right relation will be present, regardless if found in A or not Full Outer Join Both left and right outer joins

Summary Converted operators into a first order language parallel Showed how to combine operators for efficiency Defined the concept of algebra Showed the different types of joins