Chapter 3 Relational Model

Similar documents
Relational Algebra 2. Week 5

CS54100: Database Systems

RELATIONAL MODEL.

Relational Algebra & Calculus

Relational Algebra and Calculus

Query Processing. 3 steps: Parsing & Translation Optimization Evaluation

Advanced DB CHAPTER 5 DATALOG

Database Applications (15-415)

Schedule. Today: Jan. 17 (TH) Jan. 24 (TH) Jan. 29 (T) Jan. 22 (T) Read Sections Assignment 2 due. Read Sections Assignment 3 due.

Introduction to Data Management. Lecture #12 (Relational Algebra II)

INTRODUCTION TO RELATIONAL DATABASE SYSTEMS

Databases 2011 The Relational Algebra

Relational Calculus. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Database Applications (15-415)


General Overview - rel. model. Carnegie Mellon Univ. Dept. of Computer Science /615 DB Applications. Motivation. Overview - detailed

7 RC Simulates RA. Lemma: For every RA expression E(A 1... A k ) there exists a DRC formula F with F V (F ) = {A 1,..., A k } and

Relational Algebra Part 1. Definitions.

UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information

A Dichotomy. in in Probabilistic Databases. Joint work with Robert Fink. for Non-Repeating Queries with Negation Queries with Negation

Relational Algebra on Bags. Why Bags? Operations on Bags. Example: Bag Selection. σ A+B < 5 (R) = A B

Database Systems Relational Algebra. A.R. Hurson 323 CS Building

CS156: The Calculus of Computation Zohar Manna Winter 2010

Relational completeness of query languages for annotated databases

CS632 Notes on Relational Query Languages I

ER Modelling: Summary

Automata and Languages

CS5300 Database Systems

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 2. More operations: renaming. Previous lecture. Renaming.

ETIKA V PROFESII PSYCHOLÓGA

An Example file... log.txt

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

BİL 354 Veritabanı Sistemleri. Relational Algebra (İlişkisel Cebir)

CMPS 277 Principles of Database Systems. Lecture #9

Movies Title Director Actor

Sets are one of the basic building blocks for the types of objects considered in discrete mathematics.

With Question/Answer Animations. Chapter 2

Foundations of Databases

GAV-sound with conjunctive queries

T i t l e o f t h e w o r k : L a M a r e a Y o k o h a m a. A r t i s t : M a r i a n o P e n s o t t i ( P l a y w r i g h t, D i r e c t o r )

. ffflffluary 7, 1855.

Sets McGraw-Hill Education

This document has been prepared by Sunder Kidambi with the blessings of

Relational Algebra SPJRUD

Chapter 7: Relational Database Design

Computational Logic. Relational Query Languages with Negation. Free University of Bozen-Bolzano, Werner Nutt

03 Review of First-Order Logic

First Steps in Relational Lattice

Notes. Corneliu Popeea. May 3, 2013

Chapter 7: Relational Database Design. Chapter 7: Relational Database Design

â, Đ (Very Long Baseline Interferometry, VLBI)

The Structure of Inverses in Schema Mappings

On Monoids over which All Strongly Flat Right S-Acts Are Regular

hal , version 1-21 Oct 2009

Query answering using views

COSC 430 Advanced Database Topics. Lecture 2: Relational Theory Haibo Zhang Computer Science, University of Otago

Chapter 2 Sets, Relations and Functions

Querying Fuzzy Relational Databases Through Fuzzy Domain Calculus

Definite Logic Programs

Chapter Summary. Sets The Language of Sets Set Operations Set Identities Functions Types of Functions Operations on Functions Computability

From Constructibility and Absoluteness to Computability and Domain Independence

Subrings and Ideals 2.1 INTRODUCTION 2.2 SUBRING

CS 347 Distributed Databases and Transaction Processing Notes03: Query Processing

Comp 5311 Database Management Systems. 5. Functional Dependencies Exercises

arxiv: v1 [cs.db] 1 Sep 2015

hp calculators HP 35s Solving for roots Roots of an equation Using the SOLVE function Practice solving problems involving roots

Lecture 2: Syntax. January 24, 2018

6 The Relational Data Model: Algebraic operations on tabular data

Information Systems for Engineers. Exercise 5. ETH Zurich, Fall Semester Hand-out Due

F O R SOCI AL WORK RESE ARCH

B œ c " " ã B œ c 8 8. such that substituting these values for the B 3 's will make all the equations true

Applications of Discrete Mathematics to the Analysis of Algorithms

Exercise Sheet 1: Relational Algebra David Carral, Markus Krötzsch Database Theory, 17 April, Summer Term 2018

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #3: SQL---Part 1

DATABASE DESIGN I - 1DL300

I N A C O M P L E X W O R L D

Approximate Rewriting of Queries Using Views

DATABASTEKNIK - 1DL116

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

Homomorphism Preservation Theorem. Albert Atserias Universitat Politècnica de Catalunya Barcelona, Spain

But RECAP. Why is losslessness important? An Instance of Relation NEWS. Suppose we decompose NEWS into: R1(S#, Sname) R2(City, Status)

Instructor: Amol Deshpande

Fuzzy and Rough Sets Part I

Databases. Exercises on Relational Algebra

Provenance Semirings. Todd Green Grigoris Karvounarakis Val Tannen. presented by Clemens Ley

arxiv: v1 [cs.db] 21 Sep 2016

EECS-3421a: Test #2 Electrical Engineering & Computer Science York University

Chapter 2. Linear Algebra. rather simple and learning them will eventually allow us to explain the strange results of

P a g e 3 6 of R e p o r t P B 4 / 0 9

Languages. Theory I: Database Foundations. Relational Algebra. Paradigms. Projection. Basic Operators. Jan-Georg Smaus (Georg Lausen)

Packet #2: Set Theory & Predicate Calculus. Applied Discrete Mathematics

Knowledge Discovery. Zbigniew W. Ras. Polish Academy of Sciences, Dept. of Comp. Science, Warsaw, Poland

First-Order Logic (FOL)

Sets, Logic, Relations, and Functions

1 First-order logic. 1 Syntax of first-order logic. 2 Semantics of first-order logic. 3 First-order logic queries. 2 First-order query evaluation

Fundamentos lógicos de bases de datos (Logical foundations of databases)

A Language for Task Orchestration and its Semantic Properties

CSE 562 Database Systems

Today s topics. Introduction to Set Theory ( 1.6) Naïve set theory. Basic notations for sets

07 Equational Logic and Algebraic Reasoning

Transcription:

Chapter 3 Relational Model Table of Contents 1. Structure of Relational Databases 2. Relational Algebra 3. Tuple Relational Calculus 4. Domain Relational Calculus Chapter 3-1 1

1. Structure of Relational Databases z Basic Structure z Database Schema z Query Language Chapter 3-2 Basic Structure z Relational Database ii aq1 9aÑI Y ée: Entity- Relationshipa = 9aI Iñ z Table (Relation) Schema: Set of Attribute (Column, Field) Instance: Set of Record (Row, Tuple) z Domain î Attribute½ µ ÿñe ¾V õ: Customer(aq - %} 20, a - } 3, ) A table T of n attributes and D i : domain of i th attributes T D 1 D 2 D n-1 D n Chapter 3-3 2

Database Schema - ER Diagram account-number branch-city balance branch-name assets Account Account- Branch Branch Depositor Loan- Branch Customer Borrower Loan customer-name customer-city account-number street balance Chapter 3-4 Database Schema - Sample z Four Sample Schema - Entity Customer = (customer-name, street, customer-city) Branch = (branch-name, branch-city, assets) Account = (branch-name, account-number, balance) Loan = (branch-name, loan-number, amount) z Two Sample Schema - Relationship Depositor = (customer-name, account-number) Borrower = (customer-name, loan-number) Chapter 3-5 3

Database Schema - Design Issue z Single Relation Deposit + Customer Account-Info Account-Info = (branch-name, account-number, balance, customer-name, street, customer-city) z Problem Repetition of Information Incomplete Tuples z Advantage? Chapter 3-6 Formal Query Languages z Query Language Language in which a user requests information from DB Higher than programming languages z Two Categories of Query Language Procedural: éi ñi Ý Example: Relational Algebra Nonprocedural: Relational Calculus i z Types of Query Languages Relational Algebra, Tuple Calculus, Domain Calculus Chapter 3-7 4

2. Relational Algebra z  Procedural Query Language E a E Relation1 r)i EÙ µi é Relation1 Ê z Fundamental Operations Unary Operation: Select, Project, Rename Binary Operations: Cartesian Product, Union, Set Difference z Additional Operations Set Intersection, Join, Division, Assignment Chapter 3-8 Select z Notation: σ P (r) P: Predicate (Sequence of Comparison/Logical Operators) Operators:,, =,, <,, >, r: Relation Loan 9a½ Perryridge ýe á? σ branch-name = Perryridge (Loan) Perryridge ý½ $1200 a í I? σ branch-name = Perryridge amount > 1200 (Loan) Chapter 3-9 5

Project z Notation: Π A1, A2,, Ar (r) Ai: Attribute of Relation r s Loan 9a½ ±y u%- í õn? Π loan-number, amount (Loan) Loan 9a½ í õna $3000 a e ±ye u%- í õn? Π loan-number, amount (σ amount > 3000 (Loan)) Composition of Relational Operations Chapter 3-10 Union z Notation: r s r and s are compatible relations. Attribute Æi Attribute type Æi (Domain: Equal) -vé ] E Í ÍÑE aq? Π customer-name (borrower) Π customer-name (depositor) Chapter 3-11 6

Set Difference z Notation: r - s r and s are compatible relations. Attribute Æi Attribute type Æi (Domain: Equal) -v½ õõ- Ea í - 7- Í Í ÑE aq? Π customer-name (borrower) - Π customer-name (depositor) Chapter 3-12 Cartesian Product z Notation: r s é relatione É Attribute : re attribute + se attribute õaé : re õaé se õaé Perryridge ý½ í - ÍÑE aq? Loan = (branch-name, loan-number, amount) Borrower = (customer-name, loan-number) Π customer-name (σ loan.loan-number = borrower.loan-number ( σ branch-name = Perryridge (Loan Borrower))) Chapter 3-13 7

Rename z Notation: ρ x(a1, A2,, An) (E) Expression EE éi x½ Mæ (Ai: Attribute list of x) Find the largest account balance in the bank. Π balance (account) - Π account.balance (σ account.balance < d.balance (account ρ d (account))) Smith- ÆiI ±É ü ] ½ ]ée Í Í? Π customer.customer-name (σ customer. street = smith-addr.street customer.customer-city = smith-addr.city (customer ρ smith-addr(street, city) (Π street, customer-city (σ customer-name = Smith (customer))))) Chapter 3-14 Formal Definition of Relational Algebra z Basic Expression A relation in the database A constant relation z General Relational Algebra Expression E 1 E 2 (E 1 and E 2 : Relational algebra expressions) E 1 - E 2 E 1 E 2 σ P (E 1 ), P: a predicate on attribute in E 1 Π S (E 1 ), S: a list consisting of some attributes in E 1 ρ x (E 1 ), x: a new name for the result of E 1 Chapter 3-15 8

Additional Operations z Set Intersection Operation z Natural Join Operation z Division Operation z Assignment Operation Chapter 3-16 Set Intersection z Notation: r s r and s are compatible relations. Attribute Æi Attribute type Æi (Domain: Equal) r s = r - (r - s) Find all customers who have both a loan and an account Π customer-name (borrower) Π customer-name (depositor) Chapter 3-17 9

Natural Join z Notation r s = Π R S (σ r.a1 = s.a1 r.a2 = s.a2 r.an = s.an (r s)) If R S =, then r s = r s Theta Join: r θ s = σ θ (r s) Harrison ½ Í u Ía õõe -v? Π branch-name (σ customer-city= Harrison (customer account depositor)) Find all customers who have both a loan and an account Π customer-name (borrower depositor) Chapter 3-18 Division z Notation: r ø s For All ½ í µe½ r(a, B) ø s(b) Brooklyn ½ ñei Í -v½ ±yi í± Í Π customer-name, branch-name (depositor account) ø Π branch-name (σ branch-city= Brooklyn (branch)) z Note r ø s = Π R-S (r) - Π R-S ((Π R-S (r) s) - Π R-S,S (r)) Chapter 3-19 10

Assignment z Notation: r E Relational algebra expression EE éi õae r ½ Mæ âži Ê1 ÙÙ E Ê)I qmm 9 : r ø s temp1 Π R-S (r) temp2 Π R-S ((temp1 s) - Π R-S,S (r)) result = temp1 - temp2 Chapter 3-20 3. Tuple Relational Calculus z Tuple Calculus½ QueryE Iñ Ê: {t P(t)} t: tuple variable, P: predicate Eå: Pi %)I E Í tupleñe ¾V t[a] or t[1]: Component of a tuple variable $1200a í I ±ye -v, ±yu%, í õn? {t t loan t[amount] > 1200} Chapter 3-21 11

Existential Quantifier: z Notation: t r (Q(t)) Relation r½ ]a Qi ¹^E tuple tí a? s $1200a í I ±ye ±yu%? {t s loan(t[loan-number] = s[loan-number] s[amount] > 1200} Perryridge ý½ í I ÍE aq? {t s borrower(t[customer-name] = s[customer-name] u loan(u[loan-number] = s[loan-number] u[branch-name] = Perryridge ))} Chapter 3-22 Universal Quantifier: z Notation: t r (Q(t)) Relation re Í tupleña ]a Qi ¹^? Brooklyn ½ ñei Í ý½ õõi Í? {t u branch(u[branch-city] = Brooklyn s depositor(t[customer-name] = s[customer-name] w account(w[account-no] = s[account-no] w[branch-name] = u[branch-name])))} Chapter 3-23 12

Formal Definition z Expression Form {t P(t)}, P: formula A formula is built up out of atoms. z Atom s r (s: tuple variable, r: relation) s[x] Θ u[y] (s, u: tuple variable, x: attribute, Θ: <,, =,, >, ) s[x] Θ c (s: tuple variable, x: attribute, c: constant) Chapter 3-24 Formal Definition - ±z z Formulai ~E ÉF An atom is a formula. P 1 : formula, then so are P 1 and (P 1 ). P 1, P 2 : formulae, then so are P 1 P 2, P 1 P 2, P 1 P 2 P 1 (s): formula and r: relation, then s r (P 1 (s)) and s r (P 1 (s)) are formulae. z Equivalence Rule P 1 P 2 ( P 1 P 2 ) t r (P 1 (t)) t r ( P 1 (t)) P 1 P 2 P 1 P 2 Chapter 3-25 13

Safety of Expression z Problem of Tuple Relational Calculus Infinite Relation Example: {t (t loan)} z Concept of Domain: dom(p) Set of all values that appear explicitly in P, or Set of all values that appear in one or more relations whose names appear in P. Example: dom(t loan t[amount] > 1200) {1200} loan Chapter 3-26 Concept of Safe Expression z {t P(t)}í safei ]a All values that appear in the result are values from dom(p) s {t t loan t[amount] > 1200} safe {t (t loan)} safe z Expressive Power of Languages The tuple relational calculus restricted to safe expression is equivalent in expressive power to the relational algebra. Chapter 3-27 14

4. Domain Relational Calculus z Notation: {<x 1, x 2,, x n > P(x 1, x 2,, x n )} x i : domain variable P: formula composed of atoms z Formal Definition of Domain Relational Calculus Tuple relational calculus- ]E Æi aý Atom: domain variable½ ía E Constant: domain constant Notational Shorthand a, b, c (P(a, b, c)) = a ( b ( c (P(a, b, c)))) Chapter 3-28 Example Queries z $1200a í I ±ye -v, ±yu%, õn? {< b, l, a > < b, l, a > loan a > 1200} z $1200a í I ±ye ±yu%? {< l > a, b (< b, l, a > loan a > 1200)} z Perryridge ý½ í I Í ü í õn? {< c, a > l (< c, l > borrower b (< b, l, a > loan b = Perryridge ))} z Brooklyn E Í ý½ õõi Í? {< c > x, y, z (< x, y, z > branch y = Brooklyn a, b (< x, a, b > account < c, a > depositor ))} Chapter 3-29 15

Expressive Power of Languages All three of the following are equivalent: z The relational algebra z The tuple relational calculus restricted to safe expressions z The domain relational calculus restricted to safe expressions Chapter 3-30 16