Movies Title Director Actor

Similar documents
4 Conjunctive Queries

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

Query Processing. 3 steps: Parsing & Translation Optimization Evaluation

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

As indicated in the previous chapter, the conjunctive queries, even if extended by union,

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 Database: Identities of Relational Algebra; Example of Query Optimization

Relational Algebra SPJRUD

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

Relational Algebra and Calculus

α-acyclic Joins Jef Wijsen May 4, 2017

Relational Algebra Part 1. Definitions.

Relational completeness of query languages for annotated databases

Propositional and Predicate Logic - V

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

CSE 562 Database Systems

CS632 Notes on Relational Query Languages I

INTRODUCTION TO RELATIONAL DATABASE SYSTEMS

6 The Relational Data Model: Algebraic operations on tabular data

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

Query answering using views

GAV-sound with conjunctive queries

Obtaining More Answers From Information Integration Systems

3. Only sequences that were formed by using finitely many applications of rules 1 and 2, are propositional formulas.

Automata and Languages

CS54100: Database Systems

Chapter 0 Introduction. Fourth Academic Year/ Elective Course Electrical Engineering Department College of Engineering University of Salahaddin

CS 347 Parallel and Distributed Data Processing

Section 2: Classes of Sets

Guaranteeing No Interaction Between Functional Dependencies and Tree-Like Inclusion Dependencies

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

Chapter 3 Relational Model

1. Propositional Calculus

Forcing in Lukasiewicz logic

Tuple Relational Calculus

arxiv: v1 [cs.db] 1 Sep 2015

PROBABILITY LOGICS WITH VECTOR VALUED MEASURES. Vladimir Ristić

Fuzzy and Rough Sets Part I

Universal Algebra for Logics

9/19/2018. Cartesian Product. Cartesian Product. Partitions

Chapter 4. Measure Theory. 1. Measure Spaces

Proving simple set properties...

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

Efficient Query Evaluation on Probabilistic Databases

Equational Logic. Chapter Syntax Terms and Term Algebras

Relational-Database Design

TABLEAU SYSTEM FOR LOGIC OF CATEGORIAL PROPOSITIONS AND DECIDABILITY

Foundations of Databases

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

RELATION ALGEBRAS. Roger D. MADDUX. Department of Mathematics Iowa State University Ames, Iowa USA ELSEVIER

Complexity of Reasoning in Entity Relationship Models

The Structure of Inverses in Schema Mappings

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

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

Axiomatic set theory. Chapter Why axiomatic set theory?

Multi-Tuple Deletion Propagation: Approximations and Complexity

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

Mid-Semester Quiz Second Semester, 2012

ClC (X ) : X ω X } C. (11)

Relational Algebra & Calculus

Semantic Metatheory of SL: Mathematical Induction

From Constructibility and Absoluteness to Computability and Domain Independence

CMPS 277 Principles of Database Systems. Lecture #9

Completeness in the Monadic Predicate Calculus. We have a system of eight rules of proof. Let's list them:

Propagating Functional Dependencies with Conditions

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

BASIC MATHEMATICAL TECHNIQUES

ACLT: Algebra, Categories, Logic in Topology - Grothendieck's generalized topological spaces (toposes)

Logic and Databases. Phokion G. Kolaitis. UC Santa Cruz & IBM Research Almaden. Lecture 4 Part 1

On the complexity of division and set joins in the relational algebra

Locally Consistent Transformations and Query Answering in Data Exchange

1. Propositional Calculus

THE problem of updating a database through a set

Parallel-Correctness and Transferability for Conjunctive Queries

The non-logical symbols determine a specific F OL language and consists of the following sets. Σ = {Σ n } n<ω

Lifted Inference: Exact Search Based Algorithms

Database Theory VU , SS Ehrenfeucht-Fraïssé Games. Reinhard Pichler

LINDSTRÖM S THEOREM SALMAN SIDDIQI

Trichotomy Results on the Complexity of Reasoning with Disjunctive Logic Programs

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

Data Cleaning and Query Answering with Matching Dependencies and Matching Functions

Enumeration Complexity of Conjunctive Queries with Functional Dependencies

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

MATH1050 Greatest/least element, upper/lower bound

Data Cleaning and Query Answering with Matching Dependencies and Matching 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

arxiv: v1 [cs.db] 21 Sep 2016

Complete Partial Orders, PCF, and Control

Přednáška 12. Důkazové kalkuly Kalkul Hilbertova typu. 11/29/2006 Hilbertův kalkul 1

A Worst-Case Optimal Multi-Round Algorithm for Parallel Computation of Conjunctive Queries

{x : P (x)} P (x) = x is a cat

CLASSIFYING THE COMPLEXITY OF CONSTRAINTS USING FINITE ALGEBRAS

A Little Logic. Propositional Logic. Satisfiability Problems. Solving Sudokus. First Order Logic. Logic Programming

A Tableau Calculus for Minimal Modal Model Generation

Database Applications (15-415)

Design of abstract domains using first-order logic

mat.haus project Zurab Janelidze s Lectures on UNIVERSE OF SETS last updated 18 May 2017 Stellenbosch University 2017

Comp 5311 Database Management Systems. 5. Functional Dependencies Exercises

Transcription:

Movies Title Director Actor The Trouble with Harry Hitchcock Gwenn The Trouble with Harry Hitchcock Forsythe The Trouble with Harry Hitchcock MacLaine The Trouble with Harry Hitchcock Hitchcock Cries and Whispers Bergman Andersson Cries and Whispers Bergman Sylwan Cries and Whispers Bergman Thulin Cries and Whispers Bergman Ullman Location Theater Address Phone Number Gaumont Opéra 31 bd. des Italiens 47 42 60 33 Saint André des Arts 30 rue Saint André des Arts 43 26 48 18 Le Champo 51 rue des Ecoles 43 54 51 60 Georges V 144 av. des Champs-Elysées 45 62 41 46 Les 7 Montparnassiens 98 bd. du Montparnasse 43 20 32 20 Pariscope Theater Title Schedule Gaumont Opéra Cries and Whispers 20:30 Saint André des Arts The Trouble with Harry 20:15 Georges V Cries and Whispers 22:15 Les 7 Montparnassiens Cries and Whispers 20:45 Figure 3.1: The CINEMA database

(4.1) Who is the director of Cries and Whispers? (4.2) Which theaters feature Cries and Whispers? (4.3) What are the address and phone number of the Le Champo? (4.4) List the names and addresses of theaters featuring a Bergman film. (4.5) Is a film directed by Bergman playing in Paris? (4.6) List the pairs of persons such that the first directed the second in a movie, and vice versa. (4.7) List the names of directors who have acted in a movie they directed. (4.8) List pairs of actors that acted in the same movie. (4.9) On any input produce Apocalypse Now, Coppola as the answer. (4.10) Where can I see Annie Hall or Manhattan? (4.11) What are the films with Allen as actor or director? (4.12) What films with Allen as actor or director are currently featured at the Concorde? (4.13) List all movies that were directed by Hitchcock or that are currently playing at the Rex. (4.14) List all actors and director of the movie Apocalypse Now. Figure 4.1: Examples of conjunctive queries, some of which require union

Relational Model [AHV, Ch. 3] (p.30) - Infinite set att of attributes: A, B,... (sets of attributes are denoted by U, U 1,U 2,...). - For convenience, attributes are totally ordered by att. - Countably infinite set dom of constants: a, b, c,... - Countably infinite set relname of relation names: R 1,R 2,... - sort is a function that associates a finite set of attributes with each relation name R. - For each finite subset U of att there are infinitely many R with sort(r) =U. 5

- A relation schema is a relation name R, sometimes written R[U] when sort(r) =U or R[n], when U = {A 1,A 2,...,A n }. - arity(r) = n, when sort(r) = n. - A database schema R is a finite non-empty set of relation names. Sometimes written R = {R 1 [U 1 ],...,R m [U m ]}. Example: CINEMA = {Movies, Location, Pariscope} sort(movies) ={Title, Director, Actor} sort(location)={theater, Address, Phone Number} sort(pariscope) ={Theater, Title, Schedule} 6

Named vs. Unnamed Perspective (Section 3.2, p.31) Named: attribute names can be explicitly referred to. A tuple over a relation schema R[U] is a function from U to dom. R A B C u a b c u(a) = a u(b) = b u(c) = c Tuples are written A : a, B : b, C : c. For a tuple over R[U] and V U: u[v ]=u V (restriction). u[ab] = A : a, B : b. 7

Unnamed Version (p.32) dom n = dom dom... dom If arity(r) =n, then a tuple over R is an element of dom n. u = a, b, c u(i): i thelementofu u(2) = b Because of att, there is a one-to-one correspondence between the named and unnamed versions: A : a, B : b, C : c a, b, c att 1 :a, 2:b, 3:c 8

Conventional vs. Logic Programming Perspective (Section 3.3, p.32) Conventional: a relation (relation instance) I of R is a finite set of tuples over R. A database instance I over schema R is a mapping I(R) that associates an instance I with each R in R. Logic programming: Let arity(r) =n. A fact over R is an expression of the form R(a 1,a 2,...,a n ) with a i dom for 1 i n. If u = a 1,...,a n we can also write R(u). A relation instance of R is a finite set of facts over R. A database instance of R = {R 1,...,R m } is the union of relation instances over R 1,R 2,...,R m. 9

Example (p.33) Schema = {R,S}, sort(r) =AB, sort(s) =B R A B a b c b a a Named conventional S A d I(R) ={f 1,f 2,f 3 }, I(S) ={g} f 1 (A) =a, f 1 (B) =b, f 2 (A) =c, f 2 (B) =b f 3 (A) =a, f 3 (B) =a, g(a) =d Unnamed conventional I(R) ={ a, b, c, b, a, a }, I(S) ={ d } Named logic programming I = {R(A : a, B : b), R(A : c, B : b), R(A : a, B : a), S(A : d)} 10

Unnamed logic programming I = {R(a, b), R(c, b), R(a, a), S(d)} We shall move freely between the different perspectives. One more concept: Let var be a countably infinite set of variables x, y, z, x 1,y 1,... ranging over dom. A free tuple over R[U] is a function from U to dom var. Free tuples can have variables. An atom over R is an expression R(e 1,e 2,...,e n ), where each e i is a variable or constant. If all e i are constants, R(e 1,e 2,...,e n ) is called a ground atom (a.k.a. fact). 11

Algebraic Languages (Section 4.4, p.52) Two versions: one for the unnamed model and one for the named model Unnamed model: SPC-algebra List the names and addresses of theatres featuring a Bergman film. Step-by-step: I 1 := σ 2= Bergman (Movies) I 2 := I 1 Pariscope I 3 := σ 1=5 (I 2 ) I 4 := π 4 (I 3 ) I 5 := π 2,3 ( σ1=2 (I 4 Location) ) 32

As one expression: π 2,3 (σ 1=2 (π 4 (σ 1=5 (σ 2= Bergman (Movies) Pariscope)) Location)) Another equivalent query: π 4,8 (σ 4=7 (σ 1=5 (σ 2= Bergman (Movies Pariscope Location)))) Is algebra a procedural language? 33

The SPC operators, formally (p.53) Selection (atomic selection): σ j=a (I) = {t I t(j) =a} σ j=k (I) = {t I t(j) =t(k)} Projection: π j1,j 2,...,j n (I) ={ t(j 1 ),t(j 2 ),...,t(j n ) t I} Cartesian product: If arity(i) =n and arity(j) =m, then I J = { t(1),...,t(n),s(1),...,s(m) t I, s J} and arity(i J) =n + m. 34

SPC queries (p.54) The set of SPC-queries (Select, Project, Cartesian Product) consists of: Input relation: Expression R, with arity equal to arity(r). Unary singleton constant: Expression { a }, where a dom, witharity equal to 1. Furthermore, if q 1 and q 2 are SPC-queries, then: Selection: σ j=a (q 1 ) is a SPC query where j arity(q 1 ), with arity = arity(q 1 ). σ j=k (q 1 ) is a SPC query where j, k arity(q 1 ), with arity = arity(q 1 ). Projection: π j1,...,j n (q 1 ) is a SPC query where j 1,...,j n arity(q 1 ),witharity = n. Cartesian product: q 1 q 2 is a SPC query with arity = arity(q 1 )+arity(q 2 ). 35

Define the semantics of SPC queries (exercise). Unsatisfiable queries, e.g. σ 1=a (σ 1=b (R)). Derived Operators: Intersection I J = {t I t J}. I J = def π 1,...,n (σ 1=n+1 (...(σ n=2n (I J))...)), where arity(i) =arity(j) =n. Positive conjunctive selection σ F G (I) = def σ F (σ G (I)) Equijoin Let F = j 1 = k 1 j 2 = k 2... j n = k n. I F J = def σ j1 =m+k 1... j n =m+k n (I J), where arity(i) =m. 36

Named Perspective: SPJR algebra (p.56) Natural join: sort(r) = {A, B, C} sort(s) = {C, D} R S = {t over {A, B, C, D} for some u R and v S t[abc] =u and t[cd]=v} List the names and addresses of theatres featuring a Bergman film π Theater,Address ((σ Director= Bergman (Movies) Pariscope) Location) List pairs of actors that acted in the same movie We need to join Movies with itself (autojoin). We need renaming. 38

The operators of SPJR-algebra (p.57) Selection σ A=a (I) ={t I t(a) =a}, A sort(i) σ A=B (I) ={t I t(a) =t(b)}, A,B sort(i) Projection π A1,A 2,...,A n (I) ={t[a 1,...,A n ] t I}, {A 1,...,A n } sort(i) Natural join I J = {t sort(t) =sort(i) sort(j) and for some u I and v J t[sort(i)] = u and t[sort(j)] = v} Special cases: intersection and cross-product. Renaming (example) R A B C a b c c d e δ AC EF (R) E B F a b c c d e 39

Formally: renaming function f : U att If U = {A, B, C} and f(a) =A,f(B) =B, f(c) =C, we write AC A C.Now: δ f (I) = {t sort(t) =f(sort(i)) and for some s I, t(f(a)) = s(a), for each A sort(i)} Normal form for SPJR-algebra: π B1,...,Bn ({ A 1 : a 1 }... { A m : a m } σ F (δ f1 (R 1 )... δ fk (R k ))) Every SPJR-query can be rewritten into normal form, while preserving equivalence. 40

Lemma 4.4.7 (p.60) The SPC and SPJR algebras are equivalent. Idea of proof: use normal forms: π j1,...,j n ({ a 1 }... { a m }) σ F (R 1... R k ) and π Aj1,...,A j n ({ A 1 : a 1 }... { A m : a m } σ G (δ f1 (R 1 )... δ fk (R k ))) Theorem 4.4.8: The following classes of queries are equivalent: 1. Rule-based conjunctive queries. 2. Tableau queries. 3. Conjunctive calculus queries. 4. Satisfiable SPC-algebra. 5. Satisfiable SPJR-algebra. 41