Recursive Views and Global Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 9, 2004 Some slide content.

Slides:



Advertisements
Similar presentations
1 Datalog: Logic Instead of Algebra. 2 Datalog: Logic instead of Algebra Each relational-algebra operator can be mimicked by one or several Database Logic.
Advertisements

XML: Extensible Markup Language
Relational Calculus and Datalog
From the Calculus to the Structured Query Language Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 22, 2005.
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
CPSC 504: Data Management Discussion on Chandra&Merlin 1977 Laks V.S. Lakshmanan Dept. of CS UBC.
D ATABASE S YSTEMS I R ELATIONAL A LGEBRA. 22 R ELATIONAL Q UERY L ANGUAGES Query languages (QL): Allow manipulation and retrieval of data from a database.
1 Global-as-View and Local-as-View for Information Integration CS652 Spring 2004 Presenter: Yihong Ding.
Virtual Data Integration Helena Galhardas DEI IST (based on the slides of the course: CIS 550 – Database & Information Systems, Univ. Pennsylvania, Zachary.
Advanced Views: XML-Relational Storage and Datalog Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 8, 2005.
Datalog and Data Integration Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 12, 2007 LSD Slides courtesy.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A Modified by Donghui Zhang.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Relational Algebra & Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 16, 2004 Some slide content.
Conjunctive Queries, Datalog, and Recursion Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 23, 2003 Some slide.
XML Views & Reasoning about Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 4, 2004 Some slide content.
Data Integration Techniques Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 30, 2003 Some slide content may.
CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman.
Data Integration Methods Zachary G. Ives University of Pennsylvania CIS 650 – Database & Information Systems February 16, 2004.
XML Views & Reasoning about Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 3, 2005 Some slide content.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra Chapter 4, Part A.
Bridging Different Data Representations Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 11, 2004.
Relational Algebra & Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 21, 2004 Some slide content.
Describing data sources. Outline Overview Schema mapping languages.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Rutgers University Relational Algebra 198:541 Rutgers University.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Relational Algebra Wrap-up and Relational Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 11, 2003.
Data Integration and Physical Storage Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 15, 2005.
Deductive Databases Chapter 25
CSCD343- Introduction to databases- A. Vaisman1 Relational Algebra.
Relational Algebra, R. Ramakrishnan and J. Gehrke (with additions by Ch. Eick) 1 Relational Algebra.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
The Relational Model: Relational Calculus
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
Data Integration Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 16, 2015 LSD Slides courtesy AnHai Doan.
Relational Algebra & Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 12, 2007 Some slide content.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4.
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 5: Classical Logic.
1 Relational Algebra. 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of data from a database. v Relational model supports.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
Relational Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 17, 2007 Some slide content courtesy.
Datalog Inspired by the impedance mismatch in relational databases. Main expressive advantage: recursive queries. More convenient for analysis: papers.
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1 Relational Algebra and Calculas Chapter 4, Part A.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
Relational Algebra.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
Database Management Systems 1 Raghu Ramakrishnan Relational Algebra Chpt 4 Xin Zhang.
CSCD34-Data Management Systems - A. Vaisman1 Relational Algebra.
Database Management Systems, R. Ramakrishnan1 Relational Algebra Module 3, Lecture 1.
Data Integration Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 14, 2007.
Bridging Different Data Representations Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 28, 2003 Some slide.
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
Presented by Kyumars Sheykh Esmaili Description Logics for Data Bases (DLHB,Chapter 16) Semantic Web Seminar.
CS589 Principles of DB Systems Fall 2008 Lecture 4d: Recursive Datalog with Negation – What is the query answer defined to be? Lois Delcambre
Extensions of Datalog Wednesday, February 13, 2001.
Relational Calculus Zachary G. Ives November 15, 2018
Relational Algebra & Calculus
Datalog, View Unfolding, Recursion and Foundations of Integration
XML Views & Reasoning about Views
XML Views & Reasoning about Views
Datalog Inspired by the impedance mismatch in relational databases.
Relational Algebra & Calculus
Presentation transcript:

Recursive Views and Global Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 9, 2004 Some slide content courtesy of Susan Davidson, Dan Suciu, & Raghu Ramakrishnan

2 Where We Are…  We’ve seen how views are useful both within a data model, and as a way of going from one model to another  You read the Shanmugasundaram paper on relational  XML conversion  There have been many follow-up pieces of work  There have been attempts to build “native XML” databases instead  Now we’re going to talk about another important way views can be used to fix a limitation of the XML  relational mappings  We’ll also talk about how certain classes of views can be manipulated and reasoned about in interesting ways  Then we’ll consider the use of views in integrating data

3 An Important Set of Questions  Views are incredibly powerful formalisms for describing how data relates: fn: rel  …  rel  rel  Can I define a view recursively?  Why might this be useful in the XML construction case? When should the recursion stop?  Suppose we have two views, v 1 and v 2  How do I know whether they represent the same data?  If v 1 is materialized, can we use it to compute v 2 ?  This is fundamental to query optimization and data integration, as we’ll see later

4 Reasoning about Queries and Views  SQL or XQuery are a bit too complex to reason about directly  Some aspects of it make reasoning about SQL queries undecidable  We need an elegant way of describing views (let’s assume a relational model for now)  Should be declarative  Should be less complex than SQL  Doesn’t need to support all of SQL – aggregation, for instance, may be more than we need

5 Let’s Go Back a Few Weeks… Domain Relational Calculus Queries have form: { | p } Predicate: boolean expression over x1,x2, …, xn  We have the following operations:  Rx i op x j x i op constconst op x i  x i. p  x j. p p  q, p  q  p, p  q where op is , , , , ,  and x i,x j,… are domain variables; p,q are predicates  Recall that this captures the same expressiveness as the relational algebra domain variables predicate

6 A Similar Logic-Based Language: Datalog Borrows the flavor of the relational calculus but is a “real” query language  Based on the Prolog logic-programming language  A “datalog program” will be a series of if-then rules (Horn rules) that define relations from predicates  Rules are generally of the form: R out (T 1 )  R 1 (T 2 ), R 2 (T 3 ), …, c(T 2 [ … T n ) where R out is the relation representing the query result, R i are predicates representing relations, c is an expression using arithmetic/boolean predicates over vars, and T i are tuples of variables

7 Datalog Terminology  An example datalog rule: idb(x,y)  r1(x,z), r2(z,y), z < 10  Irrelevant variables can be replaced by _ (anonymous var)  Extensional relations or database schemas (edbs) are relations only occurring in rules’ bodies – these are base relations with “ground facts”  Intensional relations (idbs) appear in the heads – these are basically views  Distinguished variables are the ones output in the head  Ground facts only have constants, e.g., r1(“abc”, 123) headsubgoals body

8 Datalog in Action  As in DRC, the output (head) consists of a tuple for each possible assignment of variables that satisfies the predicate  We typically avoid “ 8 ” in Datalog queries: variables in the body are existential, ranging over all possible values  Multiple rules with the same relation in the head represent a union  We often try to avoid disjunction (“ Ç ”) within rules  Let’s see some examples of datalog queries (which consist of 1 or more rules):  Given Professor(fid, name), Teaches(fid, serno, sem), Courses(serno, cid, desc), Student(sid, name)  Return course names other than CIS 550  Return the names of the teachers of CIS 550  Return the names of all people (professors or students)

9 Datalog is Relationally Complete  We can map RA  Datalog:  Selection  p : p becomes a datalog subgoal  Projection  A : we drop projected-out variables from head  Cross-product r  s: q(A,B,C,D)  r(A,B),s(C,D)  Join r ⋈ s : q(A,B,C,D)  r(A,B),s(C,D), condition  Union r U s: q(A,B)  r(A,B) ; q(C, D) :- s(C,D)  Difference r – s: q(A,B)  r(A,B), : s(A,B)  (If you think about it, DRC  Datalog is even easier)  Great… But then why do we care about Datalog?

10 A Query We Can’t Answer in RA/TRC/DRC… Recall our example of a binary relation for graphs or trees (similar to an XML Edge relation): edge(from, to) If we want to know what nodes are reachable: reachable(F, T, 1) :- edge(F, T)distance 1 reachable(F, T, 2) :- edge(F, X), edge(X, T)dist. 2 reachable(F, T, 3) :- edge(F, X), dist2(X, T)dist. 3 But how about all reachable paths? (Note this was easy in XPath over an XML representation -- //edge) (another way of writing  )

11 Recursive Datalog Queries Define a recursive query in datalog: reachable(F, T, 1) :- edge(F, T)distance 1 reachable(F, T, D + 1) :- edge(F, X), reachable(X, T, D)distance >1 What does this mean, exactly, in terms of logic?  There are actually three different (equivalent) definitions of semantics  All make a “closed-world” assumption: facts should exist only if they can be proven true from the input – i.e., assume the DB contains all of the truths out there!

12 Fixpoint Semantics One of the three Datalog models is based on a notion of fixpoint:  We start with an instance of data, then derive all immediate consequences  We repeat as long as we derive new facts In the RA, this requires a while loop!  However, that is too powerful and needs to be restricted  Special case: “inflationary semantics” (which terminates in time polynomial in the size of the database!)

13 Our Query in RA + while (inflationary semantics, no negation) Datalog: reachable(F, T, 1) :- edge(F, T) reachable(F, T, D+1) :- edge(F, X), reachable(X, T, D) RA procedure with while: reachable += edge ⋈ literal1 while change { reachable +=  F, T, D (  T ! X (edge) ⋈  F ! X,D ! D0 (reachable) ⋈ add1 ) } Note literal1(F,1) and add1(D0,D) are actually arithmetic and literal functions modeled here as relations.

14 Negation in Datalog Datalog allows for negation in rules  It’s essential for capturing RA set difference-style ops: Professor(, name), : Student(, name)  But negation can be tricky…  … You may recall that in the DRC, we had a notion of “unsafe” queries, and they return here… Single(X)  Person(X), : Married(X,Y)

15 Safe Rules/Queries Range restriction, which requires that every variable:  Occurs at least once in a positive relational predicate in the body,  Or it’s constrained to equal a finite set of values by arithmetic predicates Unsafe: q(X)  r(Y) q(X)  : r(X,X) q(X)  r(X) Ç t(Y) Safe: q(X)  r(X,Y) q(X)  X = 5 q(X)  : r(X,X), s(X) q(X)  r(X) Ç (t(Y),u(X,Y))  For recursion, use stratified semantics:  Allow negation only over edb predicates  Then recursively compute values for the idb predicates that depend on the edb’s (layered like strata)

16 Conjunctive Queries A single Datalog rule with no “ Ç,” “ :,” “ 8 ” can express select, project, and join – a conjunctive query  Conjunctive queries are possible to reason about statically  (Note that we can write CQ’s in other languages, e.g., SQL!) We know how to “minimize” conjunctive queries An important simplification that can’t be done for general SQL We can test whether one conjunctive query’s answers always contain another conjunctive query’s answers (for ANY instance)  Why might this be useful?

17 Example of Containment Suppose we have two queries: q1(S,C) :- Student(S, N), Takes(S, C), Course(C, X), inCSE(C), Course(C, “DB & Info Systems”) q2(S,C) :- Student(S, N), Takes(S, C), Course(C, X) Intuitively, q1 must contain the same or fewer answers vs. q2:  It has all of the same conditions, except one extra conjunction (i.e., it’s more restricted)  There’s no union or any other way it can add more data We can say that q2 contains q1 because this holds for any instance of our DB {Student, Takes, Course}

18 Wrapping up Datalog… We’ve seen a new language, Datalog  It’s basically a glorified DRC with a special feature, recursion  It’s much cleaner than SQL for reasoning about  … But negation (as in the DRC) poses some challenges We’ve seen that a particular kind of query, the conjunctive query, is written naturally in Datalog  Conjunctive queries are possible to reason about  We can minimize them, or check containment  Conjunctive queries are very commonly used in our next problem, data integration

19 The Data Integration Problem  We’ve seen that even with normalization and the same needs, different people will arrive at different schemas  In fact, most people also have different needs!  Often people build databases in isolation, then want to share their data  Different systems within an enterprise  Different information brokers on the Web  Scientific collaborators  Researchers who want to publish their data for others to use  This is the goal of data integration: tie together different sources, controlled by many people, under a common schema  Typically it’s based on conjunctive queries, as with Datalog

20 Building a Data Integration System Create a middleware “mediator” or “data integration system” over the sources  Can be warehoused (a data warehouse) or virtual  Presents a uniform query interface and schema  Abstracts away multitude of sources; consults them for relevant data  Unifies different source data formats (and possibly schemas)  Sources are generally autonomous, not designed to be integrated  Sources may be local DBs or remote web sources/services  Sources may require certain input to return output (e.g., web forms): “binding patterns” describe these

21 Data Integration System / Mediator Typical Data Integration Components Mediated Schema Wrapper Source Relations Mappings in Catalog Source Catalog QueryResults

22 Typical Data Integration Architecture Reformulator Query Processor Source Catalog Wrapper Query Query over sources Source Descrs. Queries + bindings Data in mediated format Results

23 Challenges of Mapping Schemas In a perfect world, it would be easy to match up items from one schema with another  Every table would have a similar table in the other schema  Every attribute would have an identical attribute in the other schema  Every value would clearly map to a value in the other schema Real world: as with human languages, things don’t map clearly!  May have different numbers of tables – different decompositions  Metadata in one relation may be data in another  Values may not exactly correspond  It may be unclear whether a value is the same

24 A Few Simple Examples  Movie(Title, Year, Director, Editor, Star1, Star2)  PieceOfArt(ID, Artist, Subject, Title, TypeOfArt)  MotionPicture(ID, Title, Year) Participant(ID, Name, Role) CustIDCustName 1234Ives, Z. PennIDEmpName 46732Zachary Ives

25 How Do We Relate Schemas? General approach is to use a view to define relations in one schema, given data in the other schema  This allows us to “restructure” or “recompose + decompose” our data in a new way We can also define mappings between values in a view  We use an intermediate table defining correspondences – a “concordance table”  It can be filled in using some type of code, and corrected by hand

26 Mapping Our Examples  Movie(Title, Year, Director, Editor, Star1, Star2)  PieceOfArt(ID, Artist, Subject, Title, TypeOfArt)  MotionPicture(ID, Title, Year) Participant(ID, Name, Role) CustIDCustName 1234Ives, Z. PennIDEmpName 46732Zachary Ives PieceOfArt(I, A, S, T, “Movie”) :- Movie(T, Y, A, _, S1, S2), ID = T || Y, S = S1 || S2 Movie(T, Y, D, E, S1, S2) :- MotionPicture(I, T, Y), Participant(I, D, “Dir”), Participant(I, E, “Editor”), Participant(I, S1, “Star1”), Participant(I, S2, “Star2”) T1 T2 ???

27 Two Important Approaches  TSIMMIS [Garcia-Molina+97] – Stanford  Focus: semistructured data (OEM), OQL-based language (Lorel)  Creates a mediated schema as a view over the sources  Spawned a UCSD project called MIX, which led to a company now owned by BEA Systems  Other important systems of this vein: Penn  Information Manifold [Levy+96] – AT&T Research  Focus: local-as-view mappings, relational model  Sources defined as views over mediated schema  Requires a special  Spawned Tukwila at Washington, and eventually a company as well  Led to peer-to-peer integration approaches (Piazza, etc.)

28 The Focus of these Systems  Focus: Web-based queryable sources  CGI forms, online databases, maybe a few RDBMSs  Each needs to be mapped into the system – not as easy as web search – but the benefits are significant vs. query engines  A few parenthetical notes:  Part of a slew of works on wrappers, source profiling, etc.  The creation of mappings can be partly automated – systems such as LSD, Cupid, Clio, … do this  Today most people look at integrating large enterprises (that’s where the $$$ is!) – Nimble, BEA, IBM

29 TSIMMIS  “The Stanford-IBM Manager of Multiple Information Sources” … or, a Yiddish stew  An instance of a “global-as-view” mediation system  One of the first systems to support semi-structured data, which predated XML by several years

30 Semi-structured Data: OEM  Observation: given a particular schema, its attributes may be unavailable from certain sources – inherent irregularity  Proposal: Object Exchange Model, OEM OID:  … How does it relate to XML?  … What problems does OEM solve, and not solve, in a heterogeneous system?

31 OEM Example Show this XML fragment in OEM: Bernstein Newcomer Principles of TP Chamberlin DB2 UDB

32 Queries in TSIMMIS  Specified in OQL-style language called Lorel  OQL was an object-oriented query language  Lorel is, in many ways, a predecessor to XQuery  Based on path expressions over OEM structures: select book where book.author = “DB2 UDB” and book.title = “Chamberlin”  This is basically like XQuery, which we’ll use in place of Lorel and the MSL template language. Previous query restated = for $b in document(“my-source”)/book where $b/title/text = “DB2 UDB” and $b/author/text() = “Chamberlin” return $b

33 Query Answering in TSIMMIS  Basically, it’s view unfolding, i.e., composing a query with a view  The query is the one being asked  The views are the MSL templates for the wrappers  Some of the views may actually require parameters, e.g., an author name, before they’ll return answers  Common for web forms (see Amazon, Google, …)  XQuery functions (XQuery’s version of views) support parameters as well, so we’ll see these in action

34 A Wrapper Definition in MSL  Wrappers have templates and binding patterns ($X) in MSL: B :- B: }> // $$ = “select * from book where author=“ $X //  This reformats a SQL query over Book(author, year, title)  In XQuery, this might look like: define function GetBook($X AS xsd:string) as book { for $x in sql(“select * from book where author=‘” + $x +”’”) return $x $x } The union of GetBook’s results, plus many others, is the view AllData()

35 How to Answer the Query  Given our query: for $b in AllData()/book where $b/title/text() = “DB2 UDB” and $b/author/text() = “Chamberlin” return $b  We want to find all wrapper definitions that:  Either contain output enough information that we can evaluate all of our conditions over the output  Or have already tested the conditions for us! define function AllData($x AS xsd:string) as element* { return GetBooks($x), … }

36 Query Composition with Views  We find all views that define book with author and title, and we compose the query with each: define function GetBook($x AS xsd:string) as book { for $b in sql(“select * from book where author=‘” + $x +”’”) return $b $x } for $b in AllData()/book where $b/title/text() = “DB2 UDB” and $b/author/text() = “Chamberlin” return $b We need a value for $x!

37 Matching View Output to Our Query’s Conditions  Determine that $b/book/author/text()  $x by matching the pattern on the function’s output: define function GetBook($x AS xsd:string) as book { for $b in sql(“select * from book where author=‘” + $x +”’”) return $b $x } where $x = “Chamberlin” for $b in GetBook($x)/book where $b/title/text() = “DB2 UDB” return $b

38 The Final Step: Unfolding where $x = “Chamberlin” for $b in { for $b in sql(“select * from book where author=‘” + $x +”’”) return $b $x }/book where $b/title/text() = “DB2 UDB” return $b

39 What Is the Answer? Given schema book(author, year, title) and datalog rules defining an instance: book(“Chamberlin”, “1992”, “DB2 UDB”) book(“Chamberlin”, “1995”, “DB2/CS”) What do we get for our query answer?

40 TSIMMIS  Early adopter of semistructured data  Can support irregular structure and missing attributes  Can support data from many different sources  Doesn’t fully solve heterogeneity problem, though!  Simple algorithms for view unfolding  Easily can be composed in a hierarchy of mediators

41 Limitations of TSIMMIS’ Approach  Some data sources may contain data with certain ranges or properties  “Books by Aho”, “Students at UPenn”, …  How do we express these? (Important for performance!)  Mediated schema is basically the union of the various MSL templates – as they change, so may the mediated schema  Next time we’ll see the opposite approach – and some very cool logical inference!