INF1383 -Bancos de Dados

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

DATABASE DESIGN I - 1DL300

DATABASTEKNIK - 1DL116

RELATIONAL MODEL.

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

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

Boolean Algebra. Boolean Algebra

Minimal DFA. minimal DFA for L starting from any other

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

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

Coalgebra, Lecture 15: Equations for Deterministic Automata

Overview of Today s Lecture:

Lecture 3: Equivalence Relations

CS 330 Formal Methods and Models

Symbolic enumeration methods for unlabelled structures

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

Convert the NFA into DFA

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Nondeterminism and Nodeterministic Automata

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

September 13 Homework Solutions

Handout: Natural deduction for first order logic

Designing finite automata II

Bridging the gap: GCSE AS Level

Chapter 6 Techniques of Integration

Closure Properties of Regular Languages

Bases for Vector Spaces

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

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

1B40 Practical Skills

Lecture 08: Feb. 08, 2019

Harvard University Computer Science 121 Midterm October 23, 2012

CM10196 Topic 4: Functions and Relations

p-adic Egyptian Fractions

UNIT 5 QUADRATIC FUNCTIONS Lesson 3: Creating Quadratic Equations in Two or More Variables Instruction

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

Vectors , (0,0). 5. A vector is commonly denoted by putting an arrow above its symbol, as in the picture above. Here are some 3-dimensional vectors:

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

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

Finite Automata-cont d

Bernoulli Numbers Jeff Morton

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

CMSC 330: Organization of Programming Languages

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.

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

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

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

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

First Midterm Examination

Linear Inequalities. Work Sheet 1

Introduction to Group Theory

8. Complex Numbers. We can combine the real numbers with this new imaginary number to form the complex numbers.

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

Fundamental Theorem of Calculus

Review of Calculus, cont d

DEFINITION The inner product of two functions f 1 and f 2 on an interval [a, b] is the number. ( f 1, f 2 ) b DEFINITION 11.1.

Properties of Integrals, Indefinite Integrals. Goals: Definition of the Definite Integral Integral Calculations using Antiderivatives

MA123, Chapter 10: Formulas for integrals: integrals, antiderivatives, and the Fundamental Theorem of Calculus (pp.

CHAPTER 1 Regular Languages. Contents

Riemann Sums and Riemann Integrals

Boolean Algebra. Boolean Algebras

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

APPENDIX. Precalculus Review D.1. Real Numbers and the Real Number Line

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

CS12N: The Coming Revolution in Computer Architecture Laboratory 2 Preparation

Fachgebiet Rechnersysteme1. 1. Boolean Algebra. 1. Boolean Algebra. Verification Technology. Content. 1.1 Boolean algebra basics (recap)

Riemann Sums and Riemann Integrals

The Regulated and Riemann Integrals

Lecture Solution of a System of Linear Equation

Chapters Five Notes SN AA U1C5

Ehrenfeucht-Fraïssé Games: Applications and Complexity. Department of Mathematics and Computer Science University of Udine, Italy ESSLLI 2010 CPH

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!!!

FABER Formal Languages, Automata and Models of Computation

Homework 3 Solutions

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

Chapter 2 Finite Automata

Farey Fractions. Rickard Fernström. U.U.D.M. Project Report 2017:24. Department of Mathematics Uppsala University

Introduction to Electrical & Electronic Engineering ENGG1203

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

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?

CS 330 Formal Methods and Models

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

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

and that at t = 0 the object is at position 5. Find the position of the object at t = 2.

Designing Information Devices and Systems I Discussion 8B

Riemann Integrals and the Fundamental Theorem of Calculus

Lecture 3: Curves in Calculus. Table of contents

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

7. Indefinite Integrals

Pre-Session Review. Part 1: Basic Algebra; Linear Functions and Graphs

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

Chapter 3 Single Random Variables and Probability Distributions (Part 2)

1.4 Nonregular Languages

Lecture 2: January 27

Name Ima Sample ASU ID

INTRODUCTION TO LINEAR ALGEBRA

Context-Free Grammars and Languages

Transcription:

3//0 INF383 -ncos de Ddos Prof. Sérgio Lifschitz DI PUC-Rio Eng. Computção, Sistems de Informção e Ciênci d Computção LGER RELCIONL lguns slides sedos ou modificdos dos originis em Elmsri nd Nvthe, Fundmentls of Dtse Systems, 4th Edition 004 Person Eduction, Inc. e Dtse System Concepts, McGrw Hill 5th Edition 005 Silerschtz, Korth nd Sudrshn INF383 D Sérgio Lifschitz Query Lnguges Lnguge in which user requests informtion from the dtse. Ctegories of lnguges Procedurl Non-procedurl, or declrtive Pure lnguges: Reltionl lger Tuple reltionl clculus Domin reltionl clculus Pure lnguges form underlying sis of query lnguges tht people use. INF383 D Sérgio Lifschitz Slide -56

3//0 Reltionl lger The sic set of opertions for the reltionl model is known s the reltionl lger. These opertions enle user to specify sic retrievl requests. The result of retrievl is new reltion, which my hve een formed from one or more reltions. The lger opertions thus produce new reltions, which cn e further mnipulted using opertions of the sme lger. sequence of reltionl lger opertions forms reltionl lger expression, whose result will lso e reltion tht represents the result of dtse query (or retrievl request). INF383 D Sérgio Lifschitz Slide 3-56 Reltionl lger Procedurl lnguge Five sic opertors select: σ project: union: set difference: Crtesin product: x INF383 D Sérgio Lifschitz Slide 4-56

3//0 Unry Reltionl Opertions SELECT Opertion SELECT opertion is used to select suset of the tuples from reltion tht stisfy selection condition. It is filter tht keeps only those tuples tht stisfy qulifying condition those stisfying the condition re selected while others re discrded. In generl, the select opertion is denoted y σ <selection condition> (R) where the symol σ (sigm) is used to denote the select opertor, nd the selection condition is oolen expression specified on the ttriutes of reltion R INF383 D Sérgio Lifschitz Slide 5-56 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: =,, >,. <. INF383 D Sérgio Lifschitz Slide 6-56 3

3//0 Select Opertion Exmple C D Reltion r 5 7 7 3 3 0 σ = ^ D > 5 (r) C D 3 7 0 INF383 D Sérgio Lifschitz Slide 7-56 SELECT Opertion properties The SELECT opertion σ <selection condition> (R) produces reltion S tht hs the sme schem s R The SELECT opertion σ is commuttive; i.e., σ <condition> (σ < condition> ( R)) = σ <condition> (σ < condition> ( R)) cscded SELECT opertion my e pplied in ny order; i.e., σ <condition> (σ < condition> (σ <condition3> ( R)) = σ <condition> (σ < condition3> (σ < condition> ( R))) cscded SELECT opertion my e replced y single selection with conjunction of ll the conditions; i.e., σ <condition> (σ < condition> (σ <condition3> ( R)) = σ <condition> ND < condition> ND < condition3> ( R))) INF383 D Sérgio Lifschitz Slide 8-56 4

3//0 Unry Reltionl Opertions (cont.) PROJECT Opertion This opertion selects certin columns from the tle nd discrds the other columns. The PROJECT cretes verticl prtitioning one with the needed columns (ttriutes) contining results of the opertion nd other contining the discrded Columns. The generl form of the project opertion is π<ttriute list>(r) where π (pi) is the symol used to represent the project opertion nd <ttriute list> is the desired list of ttriutes from the ttriutes of reltion R. The project opertion removes ny duplicte tuples, so the result of the project opertion is set of tuples nd hence vlid reltion. INF383 D Sérgio Lifschitz Slide 9-56 Nottion: Project Opertion ( r ),, K, k 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 INF383 D Sérgio Lifschitz Slide 0-56 5

3//0 Project Opertion Exmple Reltion r: C 0 0 30 40,C (r) C C = INF383 D Sérgio Lifschitz Slide -56 PROJECT Opertion properties The numer of tuples in the result of projection π <list> (R) is lwys less or equl to the numer of tuples in R. If the list of ttriutes includes key of R, then the numer of tuples is equl to the numer of tuples in R. π <list> (π <list> (R) ) = π <list> (R) s long s <list> contins the ttriutes in <list> INF383 D Sérgio Lifschitz Slide -56 6

3//0 Reltionl lger Opertions From Set Theory UNION Opertion The result of this opertion, denoted y R S, is reltion tht includes ll tuples tht re either in R or in S or in oth R nd S. Duplicte tuples re eliminted. The two opernds must e type comptile. Type Comptiility The opernd reltions R (,,..., n ) nd R (,,..., n ) must hve the sme numer of ttriutes, nd the domins of corresponding ttriutes must e comptile; tht is, dom( i )=dom( i ) for i=,,..., n. INF383 D Sérgio Lifschitz Slide 3-56 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 (sme type of vlues) INF383 D Sérgio Lifschitz Slide 4-56 7

3//0 Union Opertion Exmple Reltions r, s: 3 r s r s: 3 INF383 D Sérgio Lifschitz Slide 5-56 Reltionl lger Opertions From Set Theory (cont.) Set Difference (or MINUS) Opertion The result of this opertion, denoted y R - S, is reltion tht includes ll tuples tht re in R ut not in S. The two opernds must e "type comptile. INF383 D Sérgio Lifschitz Slide 6-56 8

3//0 Set Difference Opertion Nottion r s Defined s: r s = {t t r nd t s} Set differences must e tken etween comptile reltions. INF383 D Sérgio Lifschitz Slide 7-56 Set Difference Opertion Exmple Reltions r, s: 3 r s r s: INF383 D Sérgio Lifschitz Slide 8-56 9

3//0 Reltionl lger Opertions From Set Theory (cont.) CRTESIN (or cross product) Opertion This opertion is used to comine tuples from two reltions in comintoril fshion. In generl, the result of R(,,..., n ) x S(,,..., m ) is reltion Q with degree n + m ttriutes Q(,,..., n,,,..., m ), in tht order. The resulting reltion Q hs one tuple for ech comintion of tuples one from R nd one from S. Hence, if R hs n R tuples (denoted s R = n R ), nd S hs n S tuples, then R x S will hve n R * n S tuples. The two opernds do NOT hve to e "type comptile INF383 D Sérgio Lifschitz Slide 9-56 Crtesin-Product Opertion Nottion r x s Defined s: 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. INF383 D Sérgio Lifschitz Slide 0-56 0

3//0 Crtesin-Product Opertion Exmple Reltions r, s: C D E r 0 0 0 0 r x s: C D E s 0 0 0 0 0 0 0 0 INF383 D Sérgio Lifschitz Slide -56 Renming ttriutes ttriute renming: chnge the nme of n ttriute δ (R) chnge to in reltion R Exmple: R(,) δ C (R) R (C,) is renmed to C in R, content is unchnged. INF383 D Sérgio Lifschitz Slide -56

3//0 Renming Reltions 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 ( ( E ),,..., n ) returns the result of expression E under the nme X, nd with the ttriutes renmed to,,., n. INF383 D Sérgio Lifschitz Slide 3-56 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 My use vrile in susequent expressions. INF383 D Sérgio Lifschitz Slide 4-56

3//0 Composition of Opertions nd ssignments Expressions using multiple opertions. Exmple: σ =C (r x s) () T r x s () Resp σ =C ( T ) C D E 0 0 0 0 0 0 0 0 C D E 0 0 0 INF383 D Sérgio Lifschitz Slide 5-56 R Expression: Forml Definition sic expression in reltionl lger (R) 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 INF383 D Sérgio Lifschitz Slide 6-56 3

3//0 dditionl Opertions dditionl opertions tht do not dd ny power to the reltionl lger, ut my simplify common queries. Set intersection Nturl join Division Generlized Projection ggregte Functions Outer Join INF383 D Sérgio Lifschitz Slide 7-56 Reltionl lger Opertions From Set Theory (cont.) INTERSECTION OPERTION The result of this opertion, denoted y R S, is reltion tht includes ll tuples tht re in oth R nd S. The two opernds must e "type comptile" INF383 D Sérgio Lifschitz Slide 8-56 4

3//0 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) INF383 D Sérgio Lifschitz Slide 9-56 Set-Intersection Opertion Exmple Reltion r, s: r r s 3 r s INF383 D Sérgio Lifschitz Slide 30-56 5

3//0 Reltionl lger Opertions From Set Theory (cont.) oth union nd intersection re commuttive opertions: R S = S R, nd R S = S R oth union nd intersection cn e treted s n-ry opertions pplicle to ny numer of reltions s oth re ssocitive: R (S T) = (R S) T, nd (R S) T = R (S T) The minus opertion is not commuttive; tht is, in generl R - S S R INF383 D Sérgio Lifschitz Slide 3-56 inry Reltionl Opertions JOIN Opertion The sequence of crtesin product followed y select is used quite commonly to identify nd select relted tuples from two reltions It is specil opertion, clled JOIN, denoted y This opertion is very importnt for ny reltionl dtse with more thn single reltion, ecuse it llows us to process reltionships mong reltions. The generl form of join opertion on two reltions R(,,..., n ) nd S(,,..., m ) is: R <join condition>s where R nd S cn e ny reltions tht result from generl reltionl lger expressions. INF383 D Sérgio Lifschitz Slide 3-56 6

3//0 inry Reltionl Opertions (cont.) EQUIJOIN Opertion The most common use of join involves join conditions with equlity comprisons only. Such join, where the only comprison opertor used is =, is clled n EQUIJOIN. In the result of n EQUIJOIN we lwys hve one or more pirs of ttriutes (whose nmes need not e identicl) tht hve identicl vlues in every tuple. NTURL JOIN Opertion ecuse one of ech pir of ttriutes with identicl vlues is superfluous, new opertion clled nturl join denoted y * ws creted to get rid of the second (superfluous) ttriute in n EQUIJOIN condition. The stndrd definition of nturl join requires tht the two join ttriutes, or ech pir of corresponding join ttriutes, hve the sme nme in oth reltions. If this is not the cse, renming opertion is pplied first. INF383 D Sérgio Lifschitz Slide 33-56 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 t hs the sme vlue s t r on r t hs the sme vlue s t s on s Exmple: R = (,, 3, 4) e S = (,, 4) Result schem = (,, 3, 4, ) r s is defined s: r., r., r.3, r.4, s. (σ r. = s. r.4 = s.4 (r x s)) INF383 D Sérgio Lifschitz Slide 34-56 7

3//0 8 INF383 D Sérgio Lifschitz Slide 35-56 Nturl Join Opertion Exmple Reltions r, s: δ 4 C D 3 3 D E δ r δ C D E δ s r s INF383 D Sérgio Lifschitz Slide 36-56 Complete Set of Reltionl Opertions The set of opertions including select σ, project π, union, set difference -, nd crtesin product X is clled complete set ecuse ny other reltionl lger expression cn e expressed y comintion of these five opertions. For exmple: R <join condition> S = σ <join condition> (R X S)

3//0 inry Reltionl Opertions (cont.) DIVISION Opertion The division opertion is pplied to two reltions R(Z) S(X), where X suset Z. Let Y = Z - X (nd hence Z = X Y); tht is, let Y e the set of ttriutes of R tht re not ttriutes of S. The result of DIVISION is reltion T(Y) tht includes tuple t if tuples t R pper in R with t R [Y] = t, nd with t R [X] = t s for every tuple t s in S. For tuple t to pper in the result T of the DIVISION, the vlues in t must pper in R in comintion with every tuple in S. INF383 D Sérgio Lifschitz Slide 37-56 Division Opertion Exmple Reltions r, s: δ δ δ 3 3 4 6 r s: INF383 D Sérgio Lifschitz Slide 38-56 9

3//0 Division Opertion Suited to queries tht include the phrse for ll. r s Let r nd s e reltions on schems R nd S respectively where R = (,, m,,, n ) S = (,, n ) The result of r s is reltion on schem R S = (,, m ) r s = { t t R-S (r) u s ( tu r ) } Where tu mens the conctention of tuples t nd u to produce single tuple INF383 D Sérgio Lifschitz Slide 39-56 nother Division Exmple Reltions r, s: C D E D E r 3 s r s: C INF383 D Sérgio Lifschitz Slide 40-56 0

3//0 Property Division Opertion (Cont.) 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 To see why r s = R-S (r ) R-S ( ( R-S (r ) x s ) R-S,S (r )) 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. INF383 D Sérgio Lifschitz Slide 4-56 Generlized Projection Extends the projection opertion y llowing rithmetic functions to e used in the projection list. F E is ny reltionl-lger expression, F,..., F n ( E) Ech of F, F,, F n re re rithmetic expressions involving constnts nd ttriutes in the schem of E. INF383 D Sérgio Lifschitz Slide 4-56

3//0 dditionl Reltionl Opertions ggregte Functions nd Grouping type of request tht cnnot e expressed in the sic reltionl lger is to specify mthemticl ggregte functions on collections of vlues from the dtse. Exmples of such functions include retrieving the verge or totl slry of ll employees or the totl numer of employee tuples. These functions re used in simple sttisticl queries tht summrize informtion from the dtse tuples. Common functions pplied to collections of numeric vlues include SUM, VERGE, MXIMUM, nd MINIMUM. The COUNT function is used for counting tuples or vlues. INF383 D Sérgio Lifschitz Slide 43-56 ggregte Functions nd Opertions ggregtion function tkes collection of vlues nd returns single vlue s result. vg: verge vlue min: minimum vlue mx: mximum vlue sum: sum of vlues count: numer of vlues ggregte opertion in reltionl lger ϑ ) ( E G, G, K, Gn F ( ), F (, K, Fn ( n ) E is ny reltionl-lger expression G, G, G n is list of ttriutes on which to group (cn e empty) Ech F i is n ggregte function Ech i is n ttriute nme INF383 D Sérgio Lifschitz Slide 44-56

3//0 ggregte Opertion nd Generlized Projection - exmples Reltion r: g sum(cc) (r) CC CP 7 7 6 3 3 0 3, (CC CP) (r) CC - CP 5 sum(cc ) 0 7 7 INF383 D Sérgio Lifschitz Slide 45-56 nking Dtse Exmple rnch (rnch_nme, rnch_city, ssets) customer (customer_nme, customer_street, customer_city) ccount (ccount_numer, rnch_nme, lnce) lon (lon_numer, rnch_nme, mount) depositor (customer_nme, ccount_numer) orrower (customer_nme, lon_numer) INF383 D Sérgio Lifschitz Slide 46-56 3

3//0 ggregte Opertion Exmple Reltion ccount grouped y rnch-nme: rnch_nme ccount_numer lnce Perryridge Perryridge righton righton Redwood -0-0 -7-5 - 400 900 750 750 700 rnch_nme g sum(lnce) (ccount) rnch_nme Perryridge righton Redwood sum(lnce) 300 500 700 INF383 D Sérgio Lifschitz Slide 47-56 ggregte Functions (Cont.) Result of ggregtion does not hve nme Cn use renme opertion to give it nme For convenience, we permit renming s prt of ggregte opertion rnch_nme g sum(lnce) s sum_lnce (ccount) INF383 D Sérgio Lifschitz Slide 48-56 4

3//0 Null Vlues It is possile for tuples to hve null vlue, denoted y null, for some of their ttriutes null signifies n unknown vlue or tht vlue does not exist. The result of ny rithmetic expression involving null is null. ggregte functions simply ignore null vlues (s in SQL) For duplicte elimintion nd grouping, null is treted like ny other vlue nd two nulls re ssumed to e the sme (s in SQL) INF383 D Sérgio Lifschitz Slide 49-56 Null Vlues (cont.) Comprisons with null vlues return the specil truth vlue: unknown If flse ws used insted of unknown, then not ( < 5) would not e equivlent to >= 5 Three-vlued logic using the truth vlue unknown: OR: (unknown or true) = true, (unknown or flse) = unknown (unknown or unknown) = unknown ND: (true nd unknown) = unknown, (flse nd unknown) = flse, (unknown nd unknown) = unknown NOT: (not unknown) = unknown Result of select predicte is treted s flse if it evlutes to unknown INF383 D Sérgio Lifschitz Slide 50-56 5

3//0 dditionl Reltionl Opertions (cont.) The OUTER JOIN Opertion In NTURL JOIN tuples without mtching (or relted) tuple re eliminted from the join result. Tuples with null in the join ttriutes re lso eliminted. This mounts to loss of informtion. set of opertions, clled outer joins, cn e used when we wnt to keep ll the tuples in R, or ll those in S, or ll those in oth reltions in the result of the join, regrdless of whether or not they hve mtching tuples in the other reltion. INF383 D Sérgio Lifschitz Slide 5-56 dditionl Reltionl Opertions (cont.) Types of OUTER JOIN The left outer join opertion keeps every tuple in the first or left reltion R in R S; if no mtching tuple is found in S, then the ttriutes of S in the join result re filled or pdded with null vlues. similr opertion, right outer join, keeps every tuple in the second or right reltion S in the result of R S. third opertion, full outer join, denoted y keeps ll tuples in oth the left nd the right reltions when no mtching tuples re found, pdding them with null vlues s needed. INF383 D Sérgio Lifschitz Slide 5-56 6

3//0 Outer Join nking D Exmple (/4) Reltion lon lon_numer L-70 L-30 L-60 rnch_nme Downtown Redwood Perryridge mount 3000 4000 700 Reltion orrower customer_nme lon_numer Jones Smith Hyes L-70 L-30 L-55 INF383 D Sérgio Lifschitz Slide 53-56 Outer Join Exmple (/4) FIRST: recll the inner Join (nturl join) lon orrower lon_numer rnch_nme mount customer_nme L-70 L-30 Downtown Redwood 3000 4000 Jones Smith INF383 D Sérgio Lifschitz Slide 54-56 7

3//0 Outer Join Exmple (3/4) Left Outer Join lon orrower lon_numer rnch_nme mount customer_nme L-70 L-30 L-60 Downtown Redwood Perryridge 3000 4000 700 Jones Smith null Right Outer Join lon orrower lon_numer rnch_nme mount customer_nme L-70 L-30 L-55 Downtown Redwood null 3000 4000 null Jones Smith Hyes INF383 D Sérgio Lifschitz Slide 55-56 Outer Join Exmple (4/4) Full Outer Join lon orrower lon_numer rnch_nme mount customer_nme L-70 L-30 L-60 L-55 Downtown Redwood Perryridge null 3000 4000 700 null Jones Smith null Hyes INF383 D Sérgio Lifschitz Slide 56-56 8