Notes. CS 640 Relational Algebra Winter / 16. Notes. CS 640 Relational Algebra Winter / 16. Notes

Similar documents
The Relational Model

An Introduction to Structured Query Language

An Introduction to Structured Query Language

An Introduction to Structured Query Language

An Introduction to Structured Query Language

An Introduction to Structured Query Language

After completing this unit, you should be able to: Use inner joins to retrieve data from more than one table

Notes. These slides are based on slide sets provided by M. T. Öszu and by R. Ramakrishnan and J. Gehrke. CS 640 Views Winter / 15.

Query Optimization Overview

DB2 SQL Workshop (Course Code CF12)

Query Optimization Overview

Databases. Relational Model, Algebra and operations. How do we model and manipulate complex data structures inside a computer system? Until

CMP-3440 Database Systems

To understand the concept of candidate and primary keys and their application in table creation.

IBM A Assessment: DB2 9 Fundamentals-Assessment. Download Full Version :

Relational Algebra. ICOM 5016 Database Systems. Roadmap. R.A. Operators. Selection. Example: Selection. Relational Algebra. Fundamental Property

Database Technologies. Madalina CROITORU IUT Montpellier

Data Modelling and Multimedia Databases M

Data Modelling and Multimedia Databases M

WHAT IS SQL. Database query language, which can also: Define structure of data Modify data Specify security constraints

E-R Diagram to Relational Schema. Translating Entity-Relationship to Relational Tables. Representing Weak Entity Sets. Representing Strong Entity Sets

Cost Models. the query database statistics description of computational resources, e.g.

DB2 SQL Workshop for Experienced Users (Course Code CF13)

CS430 Final March 14, 2005

RELATIONAL DATA MODEL: Relational Algebra

2.2.2.Relational Database concept

CS 377 Database Systems

After completing this unit, you should be able to: Define the terms

Translating Entity-Relationship to Relational Tables

Notes. Some of these slides are based on a slide set provided by Ulf Leser. CS 640 Query Processing Winter / 30. Notes

Translating Entity-Relationship to Relational Tables

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

The Relational Algebra

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1

What is an algebra? A formal system of manipulation of symbols to deal with general statements of relations.

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

GIFT Department of Computing Science Data Selection and Filtering using the SELECT Statement

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

A l Ain University Of Science and Technology

Ian Kenny. November 28, 2017

Relational Algebra. Procedural language Six basic operators

Relational Query Languages. Preliminaries. Formal Relational Query Languages. Example Schema, with table contents. Relational Algebra

Database Management Systems,

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

CS403- Database Management Systems Solved Objective Midterm Papers For Preparation of Midterm Exam

Chapter 6 The Relational Algebra and Relational Calculus

Relational Algebra. Chapter 4, Part A. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Part V. Working with Information Systems. Marc H. Scholl (DBIS, Uni KN) Information Management Winter 2007/08 1

Database Management Systems Paper Solution

پوهنتون کابل پوهنځی كمپيوترساینس

Introduction to Data Management. Lecture #11 (Relational Algebra)

Introduction Relational Algebra Operations

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational Algebra. Mr. Prasad Sawant. MACS College. Mr.Prasad Sawant MACS College Pune

Relational Algebra. Note: Slides are posted on the class website, protected by a password written on the board

Tables From Existing Tables

Introduction to Data Management CSE 344. Lectures 8: Relational Algebra

Chapter 2: Intro to Relational Model

CS403- Database Management Systems Solved MCQS From Midterm Papers. CS403- Database Management Systems MIDTERM EXAMINATION - Spring 2010

Database Management System. Relational Algebra and operations

Chapter 6 The Relational Algebra and Calculus

Relational Algebra Part I. CS 377: Database Systems

CMPT 354: Database System I. Lecture 5. Relational Algebra

Chapter 6 Part I The Relational Algebra and Calculus

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

School of Computing, Engineering and Information Sciences University of Northumbria. Set Operations

Sample Question Paper

Chapter 3B Objectives. Relational Set Operators. Relational Set Operators. Relational Algebra Operations

A subquery is a nested query inserted inside a large query Generally occurs with select, from, where Also known as inner query or inner select,

Relational Algebra and Calculus. Relational Query Languages. Formal Relational Query Languages. Yanlei Diao UMass Amherst Feb 1, 2007

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

CSCB20 Week 2. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Chapter 2: Intro to Relational Model

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

CSCB20 Week 4. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Relational Query Languages

Midterm Review. Winter Lecture 13

CSCB20 Week 3. Introduction to Database and Web Application Programming. Anna Bretscher Winter 2017

Chapter 3: Introduction to SQL. Chapter 3: Introduction to SQL

Chapter 2. DB2 concepts

MIS Database Systems Relational Algebra

Relational Algebra. Relational Query Languages

Basic operators: selection, projection, cross product, union, difference,

QUERY PROCESSING & OPTIMIZATION CHAPTER 19 (6/E) CHAPTER 15 (5/E)

Fundamentals of Database Systems

Relational Algebra. Lecture 4A Kathleen Durant Northeastern University

SQL Data Query Language

King Fahd University of Petroleum and Minerals

Relational Query Languages: Relational Algebra. Juliana Freire

IBM DB2 9 Family Fundamentals. Download Full Version :

Database Management Systems,

Comp 5311 Database Management Systems. 2. Relational Model and Algebra

Notes. These slides are based on a slide set provided by Prof. M. Tamer Öszu. CS 640 E-R Model Winter / 23. Notes

Databases 1. Daniel POP

Relational Database: The Relational Data Model; Operations on Database Relations

Assignment 6: SQL III

RDBMS- Day 4. Grouped results Relational algebra Joins Sub queries. In today s session we will discuss about the concept of sub queries.

A View to a Kill. Please reload this page to view the headlines. 1 of 21 5/20/2009 9:18 AM. by Craig Mullins. Discussion Points

Database Technology Introduction. Heiko Paulheim

Transcription:

Relational Algebra Tamer Özsu David R. Cheriton School of Computer Science University of Waterloo CS 640 Principles of Database Management and Use Winter 2013 CS 640 Relational Algebra Winter 2013 1 / 16 Database Schema Used in Examples Department Project ProjNo DeptNo RespEmp MajProj Emp_Act EmpNo ProjNo ActNo EmStDate EmEnDate EmPTime DeptNo DeptName MgrNo AdmrDept Employee EmpNo FirstName MidInit LastName WorkDept HireDate Salary CS 640 Relational Algebra Winter 2013 2 / 16 Relational Algebra ˆ the relational algebra consists of a set of operators ˆ relational algebra is closed ˆ each operator takes as input zero or more relations ˆ each operator denes a single output relation in terms of its input relation(s) ˆ relational operators can be composed to form expressions that dene new relations in terms of existing relations. ˆ Notation: R is a relation name; E is a relational algebra expression CS 640 Relational Algebra Winter 2013 3 / 16

Primary Relational Operators ˆ Relation Name: R ˆ Selection: condition (E ) ˆ result schema is the same as E 's ˆ result instance includes the subset of the tuples of E that each satises the condition ˆ Projection: attributes (E ) ˆ result schema includes only the specied attributes ˆ result instance could have as many tuples as E, except that duplicates are eliminated CS 640 Relational Algebra Winter 2013 4 / 16 Primary Relational Operators (cont'd) ˆ Rename: (R(F ); E ) ˆ F is a list of terms of the form oldname! newname ˆ returns the result of E with columns renamed according to F. ˆ remembers the result as R for future expressions ˆ Product: E 1 E 2 ˆ result schema has all of the attributes of E 1 and all of the attributes of E 2 ˆ result instance includes one tuple for every pair of tuples (one from each expression result) in E 1 and E 2 ˆ sometimes called cross-product or Cartesian product ˆ renaming is needed when E 1 and E 2 have common attributes CS 640 Relational Algebra Winter 2013 5 / 16 Cross Product Example R AAA BBB a 1 b 1 a 2 b 2 a 3 b 3 S CCC DDD c 1 d 1 c 2 d 2 R S AAA BBB CCC DDD a 1 b 1 c 1 d 1 a 2 b 2 c 1 d 1 a 3 b 3 c 1 d 1 a 1 b 1 c 2 d 2 a 2 b 2 c 2 d 2 a 3 b 3 c 2 d 2 CS 640 Relational Algebra Winter 2013 6 / 16

Select,Project,Product Examples ˆ Note: Use Emp to mean the Employee relation, Proj the project relation ˆ Find the last names and hire dates of employees who make more than $100000. LastName;HireDate (Salary>100000(Emp)) ˆ For each project for which department E21 is responsible, nd the name of the employee in charge of that project. ProjNo;LastName (DeptNo=E21(RespEmp=EmpNo(Emp Proj ))) CS 640 Relational Algebra Winter 2013 7 / 16 Joins ˆ Conditional join: E 1 condition E 2 ˆ equivalent to condition (E 1 E 2 ) ˆ special case: equijoin Proj (RespEmp=EmpNo) Emp ˆ Natural join (E 1 E 2 ) ˆ The result of E 1 E 2 can be formed by the following steps 1 form the cross-product of E1 and E2 (renaming duplicate attributes) 2 eliminate from the cross product any tuples that do not have matching values for all pairs of attributes common to schemas E1 and E2 3 project out duplicate attributes ˆ if no attributes in common, this is just a product CS 640 Relational Algebra Winter 2013 8 / 16 Example: Natural Join ˆ Consider the natural join of the Project and Department tables, which have attribute DeptNo in common ˆ the schema of the result will include attributes ProjName, DeptNo, RespEmp, MajProj, DeptName, MgrNo, and AdmrDept ˆ the resulting relation will include one tuple for each tuple in the Project relation (why?) CS 640 Relational Algebra Winter 2013 9 / 16

Set-Based Relational Operators ˆ Union (R [ S): ˆ schemas of R and S must be union compatible ˆ result includes all tuples that appear either in R or in S or in both ˆ Dierence (R S): ˆ schemas of R and S must be union compatible ˆ result includes all tuples that appear in R and that do not appear in S ˆ Intersection (R \ S): ˆ schemas of R and S must be union compatible ˆ result includes all tuples that appear in both R and S ˆ Union Compatible: ˆ Same number of elds. ˆ 'Corresponding' elds have the same type CS 640 Relational Algebra Winter 2013 10 / 16 Relational Division X A B C a 1 b 1 c 1 a 1 b 1 c 2 a 1 b 2 c 2 a 2 b 1 c 1 a 2 b 1 c 2 a 2 b 2 c 2 a 2 b 3 c 3 a 3 b 1 c 1 S B C b 1 c 1 b 1 c 2 b 2 c 2 X =S A a 1 a 2 CS 640 Relational Algebra Winter 2013 11 / 16 Division is the Inverse of Product R A a 1 a 2 S B C b 1 c 1 b 1 c 2 b 2 c 2 R S A B C a 1 b 1 c 1 a 1 b 1 c 2 a 1 b 2 c 2 a 2 b 1 c 1 a 2 b 1 c 2 a 2 b 2 c 2 (R S )=S A a 1 a 2 CS 640 Relational Algebra Winter 2013 12 / 16

Summary of Relational Operators E ::= R j condition (E ) j attributes (E ) j (R(F ); E ) j E 1 E 2 j E 1 condition E 2 j E 1 E 2 j E 1 [ E 2 j E 1 \ E 2 j E 1 E 2 j E 1 = E 2 CS 640 Relational Algebra Winter 2013 13 / 16 Algebraic Equivalences ˆ This: ProjNo;LastName (DeptNo=E21(RespEmp=EmpNo(E P ))) ˆ is equivalent to this: ProjNo;LastName (DeptNo=E21(E RespEmp=EmpNo P )) ˆ is equivalent to this: ProjNo;LastName (E RespEmp=EmpNo DeptNo=E21(P )) ˆ is equivalent to this: ProjNo;LastName ( ( LastName;EmpNo(E )) RespEmp=EmpNo ( ProjNo;RespEmp(DeptNo=E21(P )))) CS 640 Relational Algebra Winter 2013 14 / 16 Relational Completeness Denition (Relationally Complete) A query language that is at least as expressive as relational algebra is said to be relationally complete. Languages that are relationally complete: ˆ Relational Algebra ˆ Query by Example (QBE) ˆ SQL ˆ etc. ˆ SQL has additional expressive power because it captures duplicate tuples, unknown values, aggregation, ordering,... CS 640 Relational Algebra Winter 2013 15 / 16

Discussion Next Week Topic: SQL (SEQUEL2) and QBE Read: ˆ D.D. Chamberlin et al.: SEQUEL 2: A Unied Approach to Data Denition, Manipulation, and Control. IBM Journal of Research and Development 20 (6): 560-575 (1976). ˆ M.M. Zloof: Query-by-Example: A Data Base Language. IBM Systems Journal 16 (4): 324-343 (1977). CS 640 Relational Algebra Winter 2013 16 / 16