1 Relational Algebra, Part III, and Other Operators Hugh Darwen CS252.HACD: Fundamentals of Relational.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Relational Algebra Part II
LEUCEMIA MIELOIDE AGUDA TIPO 0
(Fuzzy Set Operations)
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 38.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Factors, Primes & Composite Numbers
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
You will need some paper!
0 - 0.
ALGEBRAIC EXPRESSIONS
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULTIPLYING MONOMIALS TIMES POLYNOMIALS (DISTRIBUTIVE PROPERTY)
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
ALGEBRAIC EXPRESSIONS
Fourth normal form: 4NF 1. 2 Normal forms desirable forms for relations in DB design eliminate redundancies avoid update anomalies enforce integrity constraints.
5NF and other normal forms
CS4026 Formal Models of Computation Running Haskell Programs – power.
GR2 Advanced Computer Graphics AGR
13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
1 Relational Algebra Hugh Darwen (invited lecturer) CS319: Relational Algebra (revisited, reviewed, revised,
1 Introduction to Relational Databases Hugh Darwen CS252.HACD: Fundamentals of Relational Databases.
1 Constraints and Updating Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section 7: Constraints.
1 Database Design Issues, Part I Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section.
1 Relational Algebra, Principles and Part I Hugh Darwen CS252.HACD: Fundamentals of Relational Databases.
Dr. Alexandra I. Cristea CS 319: Theory of Databases.
Dr. Alexandra I. Cristea CS 319: Theory of Databases: C3.
1 Values, Types, Variables, Operators Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section.
Dr. A.I. Cristea CS 319: Theory of Databases: FDs.
1 Predicates and Propositions Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section 3:
Dr. Alexandra I. Cristea CS 252: Fundamentals of Relational Databases: SQL5.
ZMQS ZMQS
1 Gauss-Jordan Method. How To complete Problem 2.2 # 29 Produced by E. Gretchen Gascon.
Reducing Order Enforcement Cost in Complex Query Plans Ravindra Guravannavar and S. Sudarshan (To appear in ICDE 2007)
Swiss Federal Institute of Technology Computer Engineering and Networks Laboratory Modular Performance Analysis with Real-Time Calculus Lothar Thiele,
ABC Technology Project
© S Haughton more than 3?
Twenty Questions Subject: Twenty Questions
Relational Algebra Chapter 4, Part A
Linking Verb? Action Verb or. Question 1 Define the term: action verb.
Squares and Square Root WALK. Solve each problem REVIEW:
1 Testing Stochastic Processes Through Reinforcement Learning François Laviolette Sami Zhioua Nips-Workshop December 9 th, 2006 Josée Desharnais.
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Test B, 100 Subtraction Facts
11 = This is the fact family. You say: 8+3=11 and 3+8=11
Week 1.
We will resume in: 25 Minutes.
Relational Algebra and Relational Calculus
1 Unit 1 Kinematics Chapter 1 Day
FIND THE AREA ( ROUND TO THE NEAREST TENTHS) 2.7 in 15 in in.
Salvatore Ruggieri SIGKDD2010 Frequent Regular Itemset Mining 2010/9/2 1.
ANHAI DOAN ALON HALEVY ZACHARY IVES CHAPTER 14: DATA PROVENANCE PRINCIPLES OF DATA INTEGRATION.
The Relational Algebra
Copyright © C. J. Date 2005page 1 AGENDA : 1. A few preliminaries 2. Laying the foundations 3.Building on the foundations.
Delta-Oriented Testing for Finite State Machines
Equivalence Relations
1 Database Design Issues, Part II Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section.
Introduction to Relational Databases
Presentation transcript:

1 Relational Algebra, Part III, and Other Operators Hugh Darwen CS252.HACD: Fundamentals of Relational Databases Section 6: Relational Algebra, Part III, and Other Operators

2 The Running Example … StudentIdName S1Anne S2Boris S3Cindy S4Devinder S5Boris StudentIdCourseId S1C1 S1C2 S2C1 S3C3 S4C1 IS_CALLEDIS_ENROLLED_ON StudentId is called NameStudentId is enrolled on CourseId

3 … and these CourseIdTitle C1Database C2HCI C3Op Systems C4Programming StudentIdCourseIdMark S1C185 S1C249 S2C149 S3C366 S4C193 COURSEEXAM_MARK CourseId is entitled TitleStudentId scored Mark in the exam for course CourseId

4 Some Useful Shorthands semijoin composition GROUP/UNGROUP UPDATE (not an update operator!) Relational operators: Other operators: relation comparisons tuple extraction (from a relation) attribute value extraction (from a tuple)

5 Semijoin StudentId is called Name AND is enrolled on some course. IS_CALLED MATCHING IS_ENROLLED_ON StudentIdName S1Anne S2Boris S3Cindy S4Devinder

6 Definition of MATCHING So, let s = r1 MATCHING r2. Then: The heading of s is the heading of r1. The body of s consists of each tuple of r1 that matches at least one tuple of r2 on their common attributes. It follows that in the case where there are no common attributes, s is empty if r2 is empty, and is otherwise equal to r1. r1 MATCHING r2 r1 JOIN ( r2 { common-attrs }) where common-attrs is the attributes in common to r1 and r2.

7 Composition StudentId is enrolled on a course entitled Title. IS_ENROLLED_ON COMPOSE COURSE StudentIdTitle S1Database S1HCI S2Database S3Op Systems S4Database

8 Definition of COMPOSE r1 COMPOSE r2 ( r1 JOIN r2 ) { ALL BUT common-attrs } where common-attrs is the attributes in common to r1 and r2. Exercise (see Notes): Is COMPOSE commutative? I.e., is r1 COMPOSE r2 equivalent to r2 COMPOSE r1? Is COMPOSE associative? I.e., are (r1 COMPOSE r2) COMPOSE r3 and r1 COMPOSE (r2 COMPOSE r3 ) equivalent?

9 Read-only Counterparts of Update Operators E.g. UPDATE ( IS_CALLED WHERE StudentId = S1 ) ( Name := Ann ) And the target is a relation, not a relvar Note lack of semicolon – this is an expression, not an imperative. INSERT rv1 r2? Counterpart is r1 UNION r2. DELETE rv WHERE c? Counterpart is r WHERE NOT(c).

10 GROUP/UNGROUP StudentIdName S1Anne S2Boris S3Cindy S4Devinder S5Boris NameStudentIds Anne Boris Cindy Devinder StudentId S1 StudentId S2 S5 StudentId S3 StudentId S4 GROUP UNGROUP AB

11 From A to B and Back Again B = A GROUP ( { StudentId } AS StudentIds ) A = B UNGROUP ( StudentIds )

12 Other Operators Operators on relations that do not yield relations: aggregate operators (already seen) relation comparison tuple extraction Operators on relations that do not yield relations: aggregate operators (already seen) relation comparison tuple extraction Operators on tuples that do not yield tuples: relation selection (already seen) attribute value extraction Operators that yield tuples: tuple selection (already seen) tuple counterparts of relational operators

13 Relation Comparison Case Study NameN_StudentIds Anne Boris Cindy Devinder StudentId S1 StudentId S2 S5 StudentId S3 StudentId S4 CourseIdC_StudentIds C1 C2 C3 StudentId S1 StudentId S1 S2 S4 StudentId S3 BC

14 Relation Comparison (1) (( B JOIN C ) WHERE N_StudentIds C_StudentIds) { Name, CourseId } Every student enrolled on CourseId is called Name (and at least one student is enrolled on CourseId). CourseIdName C2Anne C3Cindy

15 Relation Comparison (2) (( B JOIN C ) WHERE N_StudentIds C_StudentIds) { Name, CourseId } Every student called Name is enrolled on CourseId (and at least one student is called Name). NameCourseId AnneC1 AnneC2 CindyC3 DevinderC1

16 Tuple Extraction Given a relation r of cardinality 1 (no more, no less): TUPLE FROM r yields the single tuple contained in the body of r. E.g.: TUPLE FROM ( IS_CALLED WHERE StudentId = S1) gives TUPLE { StudentId S1, Name Anne }

17 Attribute Value Extraction Given a tuple t with an attribute a: a FROM t yields the value of the a attribute in t. E.g.: Name FROM TUPLE FROM ( IS_CALLED WHERE StudentId = S1) gives Anne

18 A Relational View of Arithmetic Recall the imagined relation PLUS: abc Now, to compute, e.g., 2+3 …

19 Adding 2 and 3 abc c FROM TUPLE FROM ( PLUS COMPOSE { RELATION { TUPLE { a 2, b 3 } } ) PLUS (okay, 2+3 is perhaps a little easier!)

20 Tuple Counterparts of Relational Operators Let t1, t2, … be tuples. Then we have: tuple projection: t1 { [ALL BUT] attribute-name-list } tuple join: t1 JOIN t2, and JOIN{t1,t2,…} tuple extension: EXTEND t1 ADD ( exp AS attribute-name ) tuple rename: t1 RENAME ( a AS b, … ) tuple update: UPDATE t1 ( attribute-name := exp ) tuple compose: t1 COMPOSE t2

21 EXERCISES (see Notes)