Venn Diagrams Database Principles.

Slides:



Advertisements
Similar presentations
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.
Advertisements

1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
Relational Algebra Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Relational Algebra Rohit Khokher. Relational Algebra Set Oriented Operations UnionIntersectionDifference Cartesian Product Relation Oriented Operations.
ENTITY RELATIONSHIP MODELLING
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 Principles SQL 2. Database Principles Aggregate Queries SQL has 5 built-in “column functions” called aggregate functions. –min(): Returns the.
Database Principles ER to RDM Mapping. Database Principles Mapping from ER to Relational Data Model the next phase Exercise: Give me some suggestions.
Basic Probability Sets, Subsets Sample Space Event, E Probability of an Event, P(E) How Probabilities are assigned Properties of Probabilities.
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.
Database Principles SQL 1. Database Principles Connecting to db2: Using your userID and password connect to our server. Connect to the Library database.
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.
FALL 2004CENG 351 File Structures and Data Managemnet1 Relational Algebra.
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. 2 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Chapter 14 Getting to First Base: Introduction to Database Concepts.
Database Principles Relational Algebra. Database Principles What is Relational Algebra? It is a language in which we can ask questions (query) of a database.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Database Principles Hard SQL Queries Explained. Database Principles Query 1, Problem 1: Find the books (author, title) which have not been borrowed by.
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.
In this section we will introduce a new concept which is the logarithm
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
An Introduction to Venn Diagrams Slideshow 55, MathematicsSlideshow 55, Mathematics Mr Richard Sasaki, Room 307Mr Richard Sasaki, Room 307.
Database Principles Relational Database Design I.
Database Design Concepts
Concepts of Database Management, Fifth Edition
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
Concepts of Database Management Seventh Edition
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
Sample space the collection of all possible outcomes of a chance experiment –Roll a dieS={1,2,3,4,5,6}
1 Relational Algebra and Calculas Chapter 4, Part A.
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
ICS 321 Fall 2011 The Relational Model of Data (i) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 8/29/20111Lipyeow.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
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.
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
CMPT 258 Database Systems Relational Algebra (Chapter 4)
Relational Algebra p BIT DBMS II.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Jianping Fan.
1 Relational Algebra and SQL. 2 Relational Query Languages Languages for describing queries on a relational database Relational AlgebraRelational Algebra.
Probability I.
Probability.
Probability I.
Relational Algebra Chapter 4 1.
Probability I.
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.
David M. Kroenke and David J
Relational Algebra Chapter 4 1.
Relational Algebra Chapter 4 - part I.
Probability I.
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Probability I.
Data Tables and Arrays.
22.1 Probability and Set Theory ACTIVATE PRIOR KNOWLEDGE
Probability I.
CENG 351 File Structures and Data Managemnet
Relational Algebra Chapter 4 - part I.
Presentation transcript:

Venn Diagrams Database Principles

Venn Diagrams are used to represent relationships between sets. They can also be used to represent set operations like union, intersection and set difference. Since Relational Algebra has operations corresponding to these set operations, Venn Diagrams are a useful design tool for Relational Algebra Queries. union intersection set difference Synthesize info Database Principles

Draw a Venn Diagram showing the following three sets: Exercise: Draw a Venn Diagram showing the following three sets: The set of all suppliers The set of suppliers of red parts The set of suppliers of non-red parts Label each part of the diagram. All Suppliers Suppliers who supply nothing at all Suppliers of Red Parts Eval info, implement sol’n, organize ideas Suppliers of both Red and non-Red Parts Suppliers of non-Red Parts Database Principles

Easy Queries: Queries without such words in the condition. Query Types: Hard Queries: These are queries that have words such as “only”, “all” and “no” in the query condition. Easy Queries: Queries without such words in the condition. What makes a query “easy” is that is can be answered with at most join, select and project operators. What makes a query “hard” is that you must use set difference or quotient to answer the query. Find the suppliers of all/no/only red parts Find the suppliers who supply some red part Database Principles

Easy Queries: Venn Diagrams do not play much part in solving easy queries. The problem is too easy to need a design phase. Easy queries are solved by joining all necessary tables, selecting the rows of interest and projecting the columns in the answer. Database Principles

This same approach can be used to solve hard queries. In probability, it is often easier to calculate the probability of the complement of an event (¬A) than the probability of the event itself (A). This same approach can be used to solve hard queries. Asked to find something hard: Start by stating and finding its complement Then use the set difference operator to throw away the newly found complement You are left with what you want Remember Pr(A) = 1 – Pr(¬A) Database Principles

Find the suppliers (SName) who supply only red parts. “Only” Query Find the suppliers (SName) who supply only red parts. PartSuppliers = πSNo(Supplies) . s5 . s2 . s3 . s1 suppliers of only red parts = ? . s4 Describe this set. OnlyRedPartSuppliers = PartSuppliers \ NonRedpartSuppliers FinalAnswer = πSName(Supplier OnlyRedPartSuppliers) suppliers of at least one part that is not red synthesize NonRedParts = πPNo(σColour != ‘red’ (Part)) NonRedPartSuppliers = πSNo(Supplies NonRedParts) Database Principles

It turns out they are not in the answer set. Exercise: In the previous Venn Diagram, find out where the Suppliers who supply nothing at all are located. It turns out they are not in the answer set. What if we want them in the answer set? Replace with PartSuppliers = πSNo(Supplies) PartSuppliers = πSNo(Supplier) Eval info Database Principles

Location of a Supplier is a property modeled as an attribute Negation Queries: Entity Properties: Location of a Supplier is a property modeled as an attribute What Parts a Supplier supplies is also a property modeled as a relationship Database Principles

Negation Queries (Some are Easy): Find the Suppliers who do not come from Boston. Find all entity instances where the value of Location is not Boston Query Mechanism: Look at all the entity instances and as you find one where the value of Location is something other than ‘Boston’, pick out and return that instance as part of the answer. SuppliersNotFromBoston = σLocation != ‘Boston’ (Supplier) Database Principles

Negation Queries (Some are Hard): Find the Suppliers who do not supply any Parts. Find all entity instances that do not participate in the <supplies> relationship. Query Mechanism: Pick a Supplier. Look at every row in the Supplies table and if you fail to see that Supplier even once then consider that Supplier as part of the answer set. Then move on to a new Supplier. So instead of selecting members of the answer set looking at rows one at a time (which is what happens when we use join) we need to consider all the rows in Supplies as a set and see if a particular Supplier is completely missing or not. NonSuppliers = πSNo(Supplier) \ πSNo(Supplies) Database Principles

Negation Queries (Summary): Negation queries that negate the value of an attribute are “easy” and can be resolved using join, select & project. Negation queries that negate the participation in a relationship are “hard” and need set difference. Database Principles

Queries that contain “all” or “every” in the query condition. Quotient Queries: Queries that contain “all” or “every” in the query condition. Venn diagrams not very useful. Q = R/S where: Q = the key to the thing you are looking for S = the key to the thing described in the “all” condition R = a table that contains the above two keys and is related to the query. S = the list of key values that satisfy the “all” condition Example: Find the books reserved by all cardholders from New Paltz Q = {isbn}, since we are looking for books S = {borrowerid}, since borrowerid is the key for cardholders S = πborrowerid(σb_addr = ‘New Paltz’ (Cardholder)) R = {isbn,borrowerid}, must combine Q and S. R = πisbn,borrowerid(Reserves) Q = R/S = {the books reserved by all cardholders from New paltz} Database Principles