The Relational Algebra

Similar documents
Relational Algebra. Relational Algebra Overview. Relational Algebra Overview. Unary Relational Operations 8/19/2014. Relational Algebra Overview

Chapter 6 Part I The Relational Algebra and Calculus

Chapter 5 Relational Algebra. Nguyen Thi Ai Thao

Chapter 6 The Relational Algebra and Calculus

Chapter 8: The Relational Algebra and The Relational Calculus

The Relational Algebra and Calculus. Copyright 2013 Ramez Elmasri and Shamkant B. Navathe

Chapter 6 5/2/2008. Chapter Outline. Database State for COMPANY. The Relational Algebra and Calculus

CS 377 Database Systems

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

COSC344 Database Theory and Applications. σ a= c (P) S. Lecture 4 Relational algebra. π A, P X Q. COSC344 Lecture 4 1

UNIT 2 RELATIONAL MODEL

RELATIONAL DATA MODEL: Relational Algebra

2.2.2.Relational Database concept

Chapter 6 The Relational Algebra and Relational Calculus

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

CIS 611. Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6-1

Relational Algebra Part I. CS 377: Database Systems

CMP-3440 Database Systems

Chapter 8: Relational Algebra

Ian Kenny. November 28, 2017

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

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

CSIE30600/CSIEB0290 Database Systems Relational Algebra and Calculus 2

Outline. CSIE30600 Database Systems Relational Algebra and Calculus 2

What happens. 376a. Database Design. Execution strategy. Query conversion. Next. Two types of techniques

Chapter 6 - Part II The Relational Algebra and Calculus

Introduction to Query Processing and Query Optimization Techniques. Copyright 2011 Ramez Elmasri and Shamkant Navathe

Relational Algebra. Ron McFadyen ACS

ECE 650 Systems Programming & Engineering. Spring 2018

Algorithms for Query Processing and Optimization. 0. Introduction to Query Processing (1)

Institute of Southern Punjab, Multan

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

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

Chapter 3. Algorithms for Query Processing and Optimization

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Introduction Relational Algebra Operations

CSC 742 Database Management Systems

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU

Slides by: Ms. Shree Jaswal

NESTED QUERIES AND AGGREGATION CHAPTER 5 (6/E) CHAPTER 8 (5/E)

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

Relational Databases

CSEN 501 CSEN501 - Databases I

Relational Model, Relational Algebra, and SQL

Chapter 18 Strategies for Query Processing. We focus this discussion w.r.t RDBMS, however, they are applicable to OODBS.

Fundamentals of Database Systems

Simple SQL Queries (contd.)

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,

SQL STRUCTURED QUERY LANGUAGE

Relational Algebra and Calculus

Relational Algebra & Calculus. CS 377: Database Systems

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

DATABASE DESIGN I - 1DL300

A l Ain University Of Science and Technology

SQL: A COMMERCIAL DATABASE LANGUAGE. Data Change Statements,

Relational Model and Relational Algebra. Slides by: Ms. Shree Jaswal

Agenda. Database Systems. Session 5 Main Theme. Relational Algebra, Relational Calculus, and SQL. Dr. Jean-Claude Franchitti

Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries

Chapter 19 Query Optimization

DATABASE DESIGN II - 1DL400

CS317 File and Database Systems

Data Models. CS552- Chapter Three

II. Structured Query Language (SQL)

COSC344 Database Theory and Applications. Lecture 6 SQL Data Manipulation Language (1)

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

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

SIT772 Database and Information Retrieval WEEK 6. RELATIONAL ALGEBRAS. The foundation of good database design

Relational Algebra 1

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Wentworth Institute of Technology COMP570 Database Applications Fall 2014 Derbinsky. Physical Tuning. Lecture 10. Physical Tuning

Relational Query Languages

Relational Algebra. Procedural language Six basic operators

Oracle Database 10g: Introduction to SQL

More SQL: Complex Queries, Triggers, Views, and Schema Modification

Concepts of Database Management Eighth Edition. Chapter 2 The Relational Model 1: Introduction, QBE, and Relational Algebra

Relational Algebra and SQL

COSC344 Database Theory and Applications. Lecture 5 SQL - Data Definition Language. COSC344 Lecture 5 1

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Relational Database Management Systems for Epidemiologists: SQL Part II

Chapter 12: Query Processing. Chapter 12: Query Processing

Database Systems External Sorting and Query Optimization. A.R. Hurson 323 CS Building

Informationslogistik Unit 4: The Relational Algebra

SQL:Union, Intersection, Difference. SQL: Natural Join

Darshan Institute of Engineering & Technology Relational Model

Set theory is a branch of mathematics that studies sets. Sets are a collection of objects.

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Evaluation of Relational Operations: Other Techniques

Databases - Relational Algebra. (GF Royle, N Spadaccini ) Databases - Relational Algebra 1 / 24

This lecture. Projection. Relational Algebra. Suppose we have a relation

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

Chapter 8. Joined Relations. Joined Relations. SQL-99: Schema Definition, Basic Constraints, and Queries

Database Technologies. Madalina CROITORU IUT Montpellier

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Evaluation of Relational Operations: Other Techniques

Relational Algebra and Relational Calculus. Pearson Education Limited 1995,

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

CS

II. Structured Query Language (SQL)

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

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Transcription:

The Relational Algebra

Relational Algebra Relational algebra is the basic set of operations for the relational model These operations enable a user to specify basic retrieval requests (or queries) 27-Jan-14 2

Relational Algebra Overview Relational Algebra consists of several groups of operations Unary Relational Operations SELECT (symbol: (sigma)) PROJECT (symbol: (pi)) RENAME (symbol: (rho)) Relational Algebra Operations From Set Theory UNION ( ), INTERSECTION ( ), DIFFERENCE (or MINUS, ) CARTESIAN PRODUCT ( x ) Binary Relational Operations JOIN (several variations of JOIN exist) DIVISION Additional Relational Operations OUTER JOINS, OUTER UNION AGGREGATE FUNCTIONS 27-Jan-14 3

Unary Relational Operations SELECT (symbol: (sigma)) PROJECT (symbol: (pi)) RENAME (symbol: (rho)) 27-Jan-14 4

Database State for COMPANY All examples discussed below refer to the COMPANY database shown here. 27-Jan-14 5

SELECT The SELECT operation (denoted by (sigma)) is used to select a subset of the tuples from a relation based on a selection condition The selection condition acts as a filter Keeps only those tuples that satisfy the qualifying condition Tuples satisfying the condition are selected whereas the other tuples are discarded (filtered out) 27-Jan-14 6

SELECT Examples: Select the EMPLOYEE tuples whose department number is 4: DNO = 4 (EMPLOYEE) Select the employee tuples whose salary is greater than $30,000: SALARY > 30,000 (EMPLOYEE) 27-Jan-14 7

SELECT In general, the select operation is denoted by <selection condition> (R) where the symbol (sigma) is used to denote the select operator the selection condition is a Boolean (conditional) expression specified on the attributes of relation R tuples that make the condition true are selected (appear in the result of the operation) tuples that make the condition false are filtered out (discarded from the result of the operation) 27-Jan-14 8

SELECT The Boolean expression specified in <selection condition> is made up of a number of clauses of the form: <attribute name> <comparison op> <constant value> or <attribute name> <comparison op> <attribute name> Where <attribute name> is the name of an attribute of R, <comparison op> id normally one of the operations {=,>,>=,<,<=,!=} Clauses can be arbitrarily connected by the Boolean operators and, or and not 27-Jan-14 9

SELECT For example, to select the tuples for all employees who either work in department 4 and make over $25000 per year, or work in department 5 and make over $30000, the select operation should be: (DNO=4 AND Salary>25000 ) OR (DNO=5 AND Salary>30000 ) (EMPLOYEE) 27-Jan-14 10

The following query results refer to this database state 27-Jan-14 11

PROJECT PROJECT Operation is denoted by (pi) If we are interested in only certain attributes of relation, we use PROJECT This operation keeps certain columns (attributes) from a relation and discards the other columns. 27-Jan-14 12

PROJECT PROJECT creates a vertical partitioning The list of specified columns (attributes) is kept in each tuple The other attributes in each tuple are discarded 27-Jan-14 13

PROJECT Example: To list each employee s first and last name and salary, the following is used: LNAME, FNAME,SALARY (EMPLOYEE) 27-Jan-14 14

Examples of applying SELECT and PROJECT operations 27-Jan-14 15

Single expression versus sequence of relational operations We may want to apply several relational algebra operations one after the other Either we can write the operations as a single relational algebra expression by nesting the operations, or We can apply one operation at a time and create intermediate result relations. In the latter case, we must give names to the relations that hold the intermediate results. 27-Jan-14 16

Single expression versus sequence of relational operations To retrieve the first name, last name, and salary of all employees who work in department number 5, we must apply a select and a project operation We can write a single relational algebra expression as follows: FNAME, LNAME, SALARY ( DNO=5 (EMPLOYEE)) OR We can explicitly show the sequence of operations, giving a name to each intermediate relation: DEP5_EMPS DNO=5 (EMPLOYEE) RESULT FNAME, LNAME, SALARY (DEP5_EMPS) 27-Jan-14 17

Example of applying multiple operations and RENAME 27-Jan-14 18

RENAME The RENAME operator is denoted by (rho) In some cases, we may want to rename the attributes of a relation or the relation name or both Useful when a query requires multiple operations Necessary in some cases (see JOIN operation later) RENAME operation which can rename either the relation name or the attribute names, or both 27-Jan-14 19

RENAME The general RENAME operation can be expressed by any of the following forms: S (R) changes: the relation name only to S (B1, B2,, Bn ) (R) changes: the column (attribute) names only to B1, B1,..Bn S (B1, B2,, Bn ) (R) changes both: the relation name to S, and the column (attribute) names to B1, B1,..Bn 27-Jan-14 20