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

Similar documents
RELATIONAL MODEL.

INF1383 -Bancos de Dados

DATABASE DESIGN I - 1DL300

DATABASTEKNIK - 1DL116

Learning Goals. Relational Query Languages. Formal Relational Query Languages. Formal Query Languages: Relational Algebra and Relational Calculus

Chapter 2 Finite Automata

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Reasoning and programming. Lecture 5: Invariants and Logic. Boolean expressions. Reasoning. Examples

Homework 3 Solutions

Linear Inequalities. Work Sheet 1

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

CS 330 Formal Methods and Models

p-adic Egyptian Fractions

Coalgebra, Lecture 15: Equations for Deterministic Automata

The Regulated and Riemann Integrals

Overview of Today s Lecture:

Boolean Algebra. Boolean Algebra

Riemann Sums and Riemann Integrals

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

Bob Brown Math 251 Calculus 1 Chapter 5, Section 4 1 CCBC Dundalk

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Minimal DFA. minimal DFA for L starting from any other

Riemann Sums and Riemann Integrals

Boolean algebra.

Parse trees, ambiguity, and Chomsky normal form

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Section 6.1 INTRO to LAPLACE TRANSFORMS

Introduction to Electrical & Electronic Engineering ENGG1203

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 275 Automata and Formal Language Theory

Symbolic enumeration methods for unlabelled structures

Designing Information Devices and Systems I Discussion 8B

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Nondeterminism and Nodeterministic Automata

The area under the graph of f and above the x-axis between a and b is denoted by. f(x) dx. π O

378 Relations Solutions for Chapter 16. Section 16.1 Exercises. 3. Let A = {0,1,2,3,4,5}. Write out the relation R that expresses on A.

Things to Memorize: A Partial List. January 27, 2017

AT100 - Introductory Algebra. Section 2.7: Inequalities. x a. x a. x < a

Finite Automata-cont d

Lecture Solution of a System of Linear Equation

Continuous Random Variables Class 5, Jeremy Orloff and Jonathan Bloom

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

Lecture 3: Equivalence Relations

Software Engineering using Formal Methods

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter 9 Definite Integrals

CS 330 Formal Methods and Models

Lecture 3: Curves in Calculus. Table of contents

P 1 (x 1, y 1 ) is given by,.

CHAPTER 1 Regular Languages. Contents

Geometric Sequences. Geometric Sequence a sequence whose consecutive terms have a common ratio.

Handout: Natural deduction for first order logic

Resources. Introduction: Binding. Resource Types. Resource Sharing. The type of a resource denotes its ability to perform different operations

1 Sets Functions and Relations Mathematical Induction Equivalence of Sets and Countability The Real Numbers...

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Lecture 08: Feb. 08, 2019

SOLVING SYSTEMS OF EQUATIONS, ITERATIVE METHODS

Improper Integrals, and Differential Equations

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

CS 330 Formal Methods and Models

STRUCTURE OF CONCURRENCY Ryszard Janicki. Department of Computing and Software McMaster University Hamilton, ON, L8S 4K1 Canada

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Bases for Vector Spaces

First Midterm Examination

3 Regular expressions

Non-deterministic Finite Automata

SWEN 224 Formal Foundations of Programming WITH ANSWERS

Lecture 2: January 27

Before we can begin Ch. 3 on Radicals, we need to be familiar with perfect squares, cubes, etc. Try and do as many as you can without a calculator!!!

Matrix Algebra. Matrix Addition, Scalar Multiplication and Transposition. Linear Algebra I 24

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

Homework Solution - Set 5 Due: Friday 10/03/08

First Midterm Examination

ɛ-closure, Kleene s Theorem,

Lecture 2e Orthogonal Complement (pages )

(e) if x = y + z and a divides any two of the integers x, y, or z, then a divides the remaining integer

set is not closed under matrix [ multiplication, ] and does not form a group.

W. We shall do so one by one, starting with I 1, and we shall do it greedily, trying

dy ky, dt where proportionality constant k may be positive or negative

CMSC 330: Organization of Programming Languages

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

Designing finite automata II

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Closure Properties of Regular Languages

2.4 Linear Inequalities and Interval Notation

A Matrix Algebra Primer

CM10196 Topic 4: Functions and Relations

Quadratic Forms. Quadratic Forms

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

4.1. Probability Density Functions

5: The Definite Integral

along the vector 5 a) Find the plane s coordinate after 1 hour. b) Find the plane s coordinate after 2 hours. c) Find the plane s coordinate

State space systems analysis (continued) Stability. A. Definitions A system is said to be Asymptotically Stable (AS) when it satisfies

Fundamental Theorem of Calculus

Combinational Logic. Precedence. Quick Quiz 25/9/12. Schematics à Boolean Expression. 3 Representations of Logic Functions. Dr. Hayden So.

Advanced Calculus: MATH 410 Notes on Integrals and Integrability Professor David Levermore 17 October 2004

Scientific notation is a way of expressing really big numbers or really small numbers.

Duality # Second iteration for HW problem. Recall our LP example problem we have been working on, in equality form, is given below.

Transcription:

BİL 354 Veritnı Sistemleri Reltionl lger (İlişkisel Ceir)

Reltionl Queries Query lnguges: llow mnipultion nd retrievl of dt from dtse. Reltionl model supports simple, powerful QLs: Strong forml foundtion sed on logic. llows for much optimiztion. Query Lnguges!= progrmming lnguges! QLs not intended to e used for complex clcultions. QLs support esy, efficient ccess to lrge dt sets.

Forml Reltionl Query Lnguges Two mthemticl Query Lnguges form the sis for rel lnguges (e.g. SQL), nd for implementtion: Reltionl lger: More opertionl, very useful for representing execution plns. Reltionl Clculus: Lets users descrie wht they wnt, rther thn how to compute it. (Nonopertionl,declrtive.) 3

Wht is Reltionl lger? n lger whose opernds re reltions or vriles tht represent reltions. Opertors re designed to do the most common things tht we need to do with reltions in dtse. The result is n lger tht cn e used s query lnguge for reltions. 4

Reltionl lger Procedurl lnguge Six sic opertors select project union set difference Crtesin product renme The opertors tke one or more reltions s inputs nd give new reltion s result. Dtse System Concepts 3.5 Silerschtz, Korth nd Sudrshn

Select Opertion Exmple Reltion r B C D 7 5 7 3 3 0 =B ^ D > 5 (r) B C D 7 3 0 Dtse System Concepts 3.6 Silerschtz, Korth nd Sudrshn

Select Opertion Nottion: p (r) p is clled the selection predicte Defined s: p (r) = {t t r nd p(t)} Where p is formul in propositionl clculus consisting of terms connected y : (nd), (or), (not) Ech term is one of: <ttriute> op <ttriute> or <constnt> where op is one of: =,, >,. <. Exmple of selection: rnch-nme= Perryridge (ccount) Dtse System Concepts 3.7 Silerschtz, Korth nd Sudrshn

Project Opertion Exmple Reltion r: B C 0 0 30 40,C (r) C C = Dtse System Concepts 3.8 Silerschtz, Korth nd Sudrshn

Project Opertion Nottion:,,, k (r) where, re ttriute nmes nd r is reltion nme. The result is defined s the reltion of k columns otined y ersing the columns tht re not listed Duplicte rows removed from result, since reltions re sets E.g. To eliminte the rnch-nme ttriute of ccount ccount-numer, lnce (ccount) Dtse System Concepts 3.9 Silerschtz, Korth nd Sudrshn

Union Opertion Exmple Reltions r, s: B B 3 r s r s: B 3 Dtse System Concepts 3.0 Silerschtz, Korth nd Sudrshn

Union Opertion Nottion: r s Defined s: r s = {t t r or t s} For r s to e vlid.. r, s must hve the sme rity (sme numer of ttriutes). The ttriute domins must e comptile (e.g., nd column of r dels with the sme type of vlues s does the nd column of s) E.g. to find ll customers with either n ccount or lon customer-nme (depositor) customer-nme (orrower) Dtse System Concepts 3. Silerschtz, Korth nd Sudrshn

Set Difference Opertion Exmple Reltions r, s: B B 3 r s r s: B Dtse System Concepts 3. Silerschtz, Korth nd Sudrshn

Set Difference Opertion Nottion r s Defined s: r s = {t t r nd t s} Set differences must e tken etween comptile reltions. r nd s must hve the sme rity ttriute domins of r nd s must e comptile Dtse System Concepts 3.3 Silerschtz, Korth nd Sudrshn

Crtesin-Product Opertion-Exmple Reltions r, s: B C D E r 0 0 0 0 r x s: s B C D E 0 0 0 0 0 0 0 0 Dtse System Concepts 3.4 Silerschtz, Korth nd Sudrshn

Nottion r x s Defined s: Crtesin-Product Opertion r x s = {t q t r nd q s} ssume tht ttriutes of r(r) nd s(s) re disjoint. (Tht is, R S = ). If ttriutes of r(r) nd s(s) re not disjoint, then renming must e used. Dtse System Concepts 3.5 Silerschtz, Korth nd Sudrshn

Composition of Opertions Cn uild expressions using multiple opertions Exmple: =C (r x s) r x s B C D E =C (r x s) 0 0 0 0 0 0 0 0 B C D E 0 0 0 Dtse System Concepts 3.6 Silerschtz, Korth nd Sudrshn

Renme Opertion llows us to nme, nd therefore to refer to, the results of reltionl-lger expressions. llows us to refer to reltion y more thn one nme. Exmple: x (E) returns the expression E under the nme X If reltionl-lger expression E hs rity n, then x (,,, n) (E) returns the result of expression E under the nme X, nd with the ttriutes renmed to,,., n. Dtse System Concepts 3.7 Silerschtz, Korth nd Sudrshn

Bnking Exmple rnch (rnch-nme, rnch-city, ssets) customer (customer-nme, customer-street, customer-only) ccount (ccount-numer, rnch-nme, lnce) lon (lon-numer, rnch-nme, mount) depositor (customer-nme, ccount-numer) orrower (customer-nme, lon-numer) Dtse System Concepts 3.8 Silerschtz, Korth nd Sudrshn

Exmple Queries Find ll lons of over $00 mount > 00 (lon) Find the lon numer for ech lon of n mount greter thn $00 lon-numer ( mount > 00 (lon)) Dtse System Concepts 3.9 Silerschtz, Korth nd Sudrshn

Exmple Queries Find the nmes of ll customers who hve lon, n ccount, or oth, from the nk customer-nme (orrower) customer-nme (depositor) Find the nmes of ll customers who hve lon nd n ccount t nk. customer-nme (orrower) customer-nme (depositor) Dtse System Concepts 3.0 Silerschtz, Korth nd Sudrshn

Exmple Queries Find the nmes of ll customers who hve lon t the Perryridge rnch. customer-nme ( rnch-nme= Perryridge ( orrower.lon-numer = lon.lon-numer (orrower x lon))) Find the nmes of ll customers who hve lon t the Perryridge rnch ut do not hve n ccount t ny rnch of the nk. customer-nme ( rnch-nme = Perryridge ( orrower.lon-numer = lon.lon-numer (orrower x lon))) customer-nme (depositor) Dtse System Concepts 3. Silerschtz, Korth nd Sudrshn

Exmple Queries Find the nmes of ll customers who hve lon t the Perryridge rnch. Query customer-nme ( rnch-nme = Perryridge ( orrower.lon-numer = lon.lon-numer (orrower x lon))) Query customer-nme ( lon.lon-numer = orrower.lon-numer ( ( rnch-nme = Perryridge (lon)) x orrower)) Dtse System Concepts 3. Silerschtz, Korth nd Sudrshn

Find the lrgest ccount lnce Renme ccount reltion s d The query is: Exmple Queries lnce (ccount) - ccount.lnce ( ccount.lnce < d.lnce (ccount x d (ccount))) Dtse System Concepts 3.3 Silerschtz, Korth nd Sudrshn

Forml Definition sic expression in the reltionl lger consists of either one of the following: reltion in the dtse constnt reltion Let E nd E e reltionl-lger expressions; the following re ll reltionl-lger expressions: E E E - E E x E p (E ), P is predicte on ttriutes in E s (E ), S is list consisting of some of the ttriutes in E x (E ), x is the new nme for the result of E Dtse System Concepts 3.4 Silerschtz, Korth nd Sudrshn

dditionl Opertions We define dditionl opertions tht do not dd ny power to the reltionl lger, ut tht simplify common queries. Set intersection Nturl join Division ssignment Dtse System Concepts 3.5 Silerschtz, Korth nd Sudrshn

Set-Intersection Opertion Nottion: r s Defined s: r s ={ t t r nd t s } ssume: r, s hve the sme rity ttriutes of r nd s re comptile Note: r s = r - (r - s) Dtse System Concepts 3.6 Silerschtz, Korth nd Sudrshn

Set-Intersection Opertion - Exmple Reltion r, s: B B 3 r s r s B Dtse System Concepts 3.7 Silerschtz, Korth nd Sudrshn

Nottion: r s Nturl-Join Opertion Let r nd s e reltions on schems R nd S respectively. Then, r s is reltion on schem R S otined s follows: Consider ech pir of tuples t r from r nd t s from s. If t r nd t s hve the sme vlue on ech of the ttriutes in R S, dd tuple t to the result, where Exmple: t hs the sme vlue s t r on r t hs the sme vlue s t s on s R = (, B, C, D) S = (E, B, D) Result schem = (, B, C, D, E) r s is defined s: r., r.b, r.c, r.d, s.e ( r.b = s.b r.d = s.d (r x s)) Dtse System Concepts 3.8 Silerschtz, Korth nd Sudrshn

Silerschtz, Korth nd Sudrshn 3.9 Dtse System Concepts Nturl Join Opertion Exmple Reltions r, s: B 4 C D B 3 3 D E r B C D E s r s

Division Opertion Suited to queries tht include the phrse for ll. Let r nd s e reltions on schems R nd S respectively where R = (,, m, B,, B n ) S = (B,, B n ) The result of r s is reltion on schem R S = (,, m ) r s r s = { t t R-S (r) u s ( tu r ) } Dtse System Concepts 3.30 Silerschtz, Korth nd Sudrshn

Silerschtz, Korth nd Sudrshn 3.3 Dtse System Concepts Division Opertion Exmple Reltions r, s: r s: B B 3 3 4 6 r s

Silerschtz, Korth nd Sudrshn 3.3 Dtse System Concepts nother Division Exmple B C D E 3 Reltions r, s: r s: D E B C r s

Division Opertion (Cont.) Property Let q r s Then q is the lrgest reltion stisfying q x s r Definition in terms of the sic lger opertion Let r(r) nd s(s) e reltions, nd let S R r s = R-S (r) R-S ( ( R-S (r) x s) R-S,S (r)) To see why R-S,S (r) simply reorders ttriutes of r R-S ( R-S (r) x s) R-S,S (r)) gives those tuples t in R-S (r) such tht for some tuple u s, tu r. Dtse System Concepts 3.33 Silerschtz, Korth nd Sudrshn

ssignment Opertion The ssignment opertion () provides convenient wy to express complex queries. Write query s sequentil progrm consisting of series of ssignments followed y n expression whose vlue is displyed s result of the query. ssignment must lwys e mde to temporry reltion vrile. Exmple: Write r s s temp R-S (r) temp R-S ((temp x s) R-S,S (r)) result = temp temp The result to the right of the is ssigned to the reltion vrile on the left of the. My use vrile in susequent expressions. Dtse System Concepts 3.34 Silerschtz, Korth nd Sudrshn

Exmple Queries Find ll customers who hve n ccount from t lest the Downtown nd the Uptown rnches. Query CN ( BN= Downtown (depositor ccount)) CN ( BN= Uptown (depositor ccount)) where CN denotes customer-nme nd BN denotes rnch-nme. Query customer-nme, rnch-nme (depositor ccount) temp(rnch-nme) ({( Downtown ), ( Uptown )}) Dtse System Concepts 3.35 Silerschtz, Korth nd Sudrshn

Exmple Queries Find ll customers who hve n ccount t ll rnches locted in Brooklyn city. customer-nme, rnch-nme (depositor ccount) rnch-nme ( rnch-city = Brooklyn (rnch)) Dtse System Concepts 3.36 Silerschtz, Korth nd Sudrshn