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.

Slides:



Advertisements
Similar presentations
Relational Algebra Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
Advertisements

Relational Algebra Rohit Khokher. Relational Algebra Set Oriented Operations UnionIntersectionDifference Cartesian Product Relation Oriented Operations.
1 CHAPTER 4 RELATIONAL ALGEBRA AND CALCULUS. 2 Introduction - We discuss here two mathematical formalisms which can be used as the basis for stating and.
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.
Relational Algebra Ch. 7.4 – 7.6 John Ortiz. Lecture 4Relational Algebra2 Relational Query Languages  Query languages: allow manipulation and retrieval.
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 Content based on Chapter 4 Database Management Systems, (Third Edition), by Raghu Ramakrishnan and Johannes Gehrke. McGraw Hill, 2003.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  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.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
R ELATIONAL A LGEBRA M ORE POINTERS FROM T UESDAY.
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.
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.
CS 4432query processing1 CS4432: Database Systems II.
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.
Introduction to Database Systems 1 Relational Algebra Relational Model: Topic 3.
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 and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
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, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
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.
CS 4432query processing1 CS4432: Database Systems II Lecture #11 Professor Elke A. Rundensteiner.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
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.
Relational Algebra.
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.
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.
IST 210 The Relational Language Todd S. Bacastow January 2004.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
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)
Relational Algebra p BIT DBMS II.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Jianping Fan.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
1 CS122A: Introduction to Data Management Lecture #7 Relational Algebra I Instructor: Chen Li.
Relational Algebra. CENG 3512 Relational Query Languages Query languages: Allow manipulation and retrieval of data from a database. Relational model supports.
Database Systems (資料庫系統)
CS4432: Database Systems II
Relational Algebra Chapter 4 1.
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.
Relational Algebra.
Relational Algebra 1.
LECTURE 3: Relational Algebra
Relational Algebra Chapter 4 1.
Relational Algebra Chapter 4 - part I.
Relational Algebra Chapter 4, Sections 4.1 – 4.2
CENG 351 File Structures and Data Managemnet
Relational Algebra & Calculus
Relational Algebra Chapter 4 - part I.
Presentation transcript:

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 21 The amount of time we spent on each topic in class is a good indication of importance & likelihood of exam question

3 Assignment 4 solution posted (with algebra) Assignment 6 posted For procedure question, sample on next page might help

4

D ATABASE S YSTEMS I W EEK 6: R EVIEW

6 R EVIEW A transaction has the following properties: Atomicity: all-or-nothing property Consistency: must leave the DB in a consistent state if DB is consistent when the transaction begins Isolation: transaction is performed as if only one transaction at a time (serial processing) Durability: effects of completed transactions are permanent What is a transaction?

7 E NTITY -R ELATIONSHIP D IAGRAMS An Entity-Relationship diagram ( ER diagram ) is a graph with nodes representing entity sets, attributes and relationship sets. Entity sets denoted by rectangles. Attributes denoted by ovals. Relationship sets denoted by diamonds. Edges ( lines ) connect entity sets to their attributes and relationship sets to their entity sets. lot dname budget did since name Works_In DepartmentsEmployees ssn

8 R ELATIONAL D ATABASE Rows are called tuples (or records ), columns called attributes (or fields ). Attributes are referenced not by column number, but by name. Order of attributes does not matter Attribute types are called domains. Domains consist of atomic values such as integers or strings. No structured values such as lists or sets The order of tuples does not matter, a relation is a set of tuples. The order of tuples resulting from a relational query is undefined.

9 R ELATIONSHIP S ETS ER Diagram Relational CREATE TABLE Works_In( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments); SQL

10 F ORMAL Q UERY L ANGUAGES Two mathematical query languages form the basis for “real” languages (e.g. SQL), and for implementation: Relational Algebra (RA) More procedural, very useful for representing execution plans, relatively close to SQL. Composed of a collection of operators A step-by-step procedure for computing the answer Relational Calculus (RC) Lets users describe what they want, rather than how to compute it. (Non-procedural, declarative.) Describes the answer, not the steps. Understanding these formal query languages is important for understanding SQL and query processing.

11 P RELIMINARIES A query is applied to relation instances, and the result of a query is also a relation instance. Inputs and Outputs of Queries are relations Query evaluated on instances of input relations Different instance (DB?) as input = different answer Schemas of input relations for a query are fixed (but query will run regardless of instance!) The schema for the result of a given query is also fixed! Determined by definition of input relations and query language constructs.

12 R ELATIONAL A LGEBRA O PERATIONS Basic operations Selection ( ) Selects a subset of rows from relation. Projection ( ) Deletes unwanted columns from relation. Cartesian product ( ) Combine two relations. Set-difference ( ) Tuples in relation 1, but not in relation 2. Union ( ) Tuples in relation 1 or in relation 2.

13 Renames relations / attributes, without changing the relation instance. relation R is renamed to S, attributes are renamed A1,..., An Rename only some attributes using the positional notation to reference attributes No renaming of attributes, just the relation R ENAMING

14 P ROJECTION Similar in concept to VIEWs S2 Other fields are projected out

15 S ELECTION S2

16 U NION Concatenates S1 and S2 Result contains ALL tuples that occur in either S1 or S2 Schemas must be identical If they have the same number of fields Fields have same domains S1 S2 SELECT * FROM S1 UNION SELECT * FROM S2 SELECT * FROM S1 UNION SELECT * FROM S2

17 I NTERSECTION Result contains ALL tuples that occur in both S1 or S2 Schemas must be identical S1 S2 SELECT * FROM S1 INTERSECT SELECT * FROM S2 SELECT * FROM S1 INTERSECT SELECT * FROM S2

18 S ET -D IFFERENCE Result contains ALL tuples that occur in S1 but not in S2 Schemas must be identical S1 S2 SELECT * FROM S1 MINUS SELECT * FROM S2 SELECT * FROM S1 MINUS SELECT * FROM S2

19 C ARTESIAN P RODUCT Field names in conflict become unnamed R1 S1

20 J OIN Condition Join Each tuple of the one relation is paired with each tuple of the other relation if the two tuples satisfy the join condition. Condition c refers to attributes of both R and S.

21 Find names of sailors who’ve reserved boat #103. Solution 1: Solution 2: Solution 3: Which is most efficient? Why? E XAMPLE Q UERIES

22 Find names of sailors who’ve reserved a red boat. Information about boat color only available in Boats; so need an extra join: A more efficient solution: A query optimizer can find the second solution given the first one. E XAMPLE Q UERIES

23 How to find number of sailors? E XAMPLE Q UERIES

24 How to find oldest sailor? E XAMPLE Q UERIES