Views and XML/Relational Mappings Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 21, 2003.

Slides:



Advertisements
Similar presentations
COP4540 Database Management System Midterm Review
Advertisements

XML: Extensible Markup Language
From the Calculus to the Structured Query Language Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 22, 2005.
CSE 6331 © Leonidas Fegaras XML and Relational Databases 1 XML and Relational Databases Leonidas Fegaras.
Hierarchies & Trees in SQL by Joe Celko copyright 2008.
Relational Databases for Querying XML Documents: Limitations & Opportunities VLDB`99 Shanmugasundaram, J., Tufte, K., He, G., Zhang, C., DeWitt, D., Naughton,
Advanced Views: XML-Relational Storage and Datalog Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 8, 2005.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
Query Evaluation. SQL to ERA SQL queries are translated into extended relational algebra. Query evaluation plans are represented as trees of relational.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Manish Bhide, Manoj K Agarwal IBM India Research Lab India {abmanish, Amir Bar-Or, Sriram Padmanabhan IBM Software Group, USA
Xyleme A Dynamic Warehouse for XML Data of the Web.
Querying XML: XQuery and XSLT Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 21, 2004 Some slide content courtesy.
XML Views & Reasoning about Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 4, 2004 Some slide content.
CS 206 Introduction to Computer Science II 10 / 01 / 2008 Instructor: Michael Eckmann.
2005rel-xml-ii1 The SilkRoute system  The system goals  Scenario, examples  View Forests  View forest and query composition  View forest efficient.
1 COS 425: Database and Information Management Systems XML and information exchange.
1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot.
XML Views & Reasoning about Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 3, 2005 Some slide content.
Storage of XML Data XML data can be stored in –Non-relational data stores Flat files –Natural for storing XML –But has all problems discussed in Chapter.
Database Systems and XML David Wu CS 632 April 23, 2001.
Storing and Querying Ordered XML Using a Relational Database System By Khang Nguyen Based on the paper of Igor Tatarinov and Statis Viglas.
XML Querying and Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 1, 2005 Some slide content courtesy.
Views: Alternate Data Representations Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 2, 2004 Some slide content.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
Introduction to Structured Query Language (SQL)
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
CIS607, Fall 2005 Semantic Information Integration Article Name: Clio Grows Up: From Research Prototype to Industrial Tool Name: DH(Dong Hwi) kwak Date:
XML Querying and Views Helena Galhardas DEI IST (slides baseados na disciplina CIS 550 – Database & Information Systems, Univ. Pennsylvania, Zachary Ives)CIS.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
4/20/2017.
8/17/20151 Querying XML Database Using Relational Database System Rucha Patel MS CS (Spring 2008) Advanced Database Systems CSc 8712 Instructor : Dr. Yingshu.
Table & Query Design for Hierarchical Data without CONNECT-BY -- A Path Code Approach Charles Yu Database Architect Elance Inc. Elance Inc.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
XML-to-Relational Schema Mapping Algorithm ODTDMap Speaker: Artem Chebotko* Wayne State University Joint work with Mustafa Atay,
Chapter 4 The Relational Model.
Querying Tree-Structured Data Using Dimension Graphs Dimitri Theodoratos (New Jersey Institute of Technology, USA) Theodore Dalamagas (National Techn.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
A Summary of XISS and Index Fabric Ho Wai Shing. Contents Definition of Terms XISS (Li and Moon, VLDB2001) Numbering Scheme Indices Stored Join Algorithms.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
Querying XML – Concluded Introduction to Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 9, 2003 Some.
RRXS Redundancy reducing XML storage in relations O. MERT ERKUŞ A. ONUR DOĞUÇ
Views Lesson 7.
2007. Software Engineering Laboratory, School of Computer Science S E Web-Harvest Web-Harvest: Open Source Web Data Extraction tool 이재정 Software Engineering.
Lecture A/18-849B/95-811A/19-729A Internet-Scale Sensor Systems: Design and Policy Lecture 24 – Part 2 XML Query Processing Phil Gibbons April.
Union-find Algorithm Presented by Michael Cassarino.
CSCI-383 Object-Oriented Programming & Design Lecture 18.
Grade Book Database Presentation Jeanne Winstead CINS 137.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
COMP3030 Database Management System Final Review
Computing & Information Sciences Kansas State University Friday, 20 Oct 2006CIS 560: Database System Concepts Lecture 24 of 42 Friday, 20 October 2006.
© 2008 IBM Corporation Presentation URLs from Resource URLs Last updated Sep. 22, 2008.
XML Data Management Zachary G. Ives University of Pennsylvania CIS 650 – Implementing Data Management Systems November 25, 2008.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
XML Schema – XSLT Week 8 Web site:
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
XML: Extensible Markup Language
Database.
Views and XML Views of Relations
Teaching slides Chapter 8.
XML Views & Reasoning about Views
XML Views & Reasoning about Views
XML Querying and Views Zachary G. Ives November 1, 2007
Presentation transcript:

Views and XML/Relational Mappings Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 21, 2003

2 Administrivia  HW3’s returned  Your first paper review/summary: Shanmugasundaram et al., handed out today  Start thinking about your projects!  You now have working knowledge of most concepts  See for more details  Due 10/28: 1-2 page plan with your group members, your milestones, and division of tasks

3 Views in SQL and XQuery  A view is a named query  We use the name of the view to invoke the query (treating it as if it were the relation it returns) SQL: CREATE VIEW V(A,B,C) AS SELECT A,B,C FROM R WHERE R.A = “123” XQuery: declare function V() as element(content)* { for $r in doc(“R”)/root/tree, $a in $r/a, $b in $r/b, $c in $r/c where $a = “123” return {$a, $b, $c} } SELECT * FROM V, R WHERE V.B = 5 AND V.C = R.C for $v in V()/content, $r in doc(“r”)/root/tree where $v/b = $r/b return $v Using the views:

4 What’s Useful about Views Providing security/access control  We can assign users permissions on different views  Can select or project so we only reveal what we want! Can be used as relations in other queries  Allows the user to query things that make more sense Describe transformations from one schema (the base relations) to another (the output of the view)  The basis of converting from XML to relations or vice versa  This will be incredibly useful in data integration, discussed soon… Allow us to define recursive queries

5 Materialized vs. Virtual Views  A virtual view is a named query that is actually re-computed every time – it is merged with the referencing query CREATE VIEW V(A,B,C) AS SELECT A,B,C FROM R WHERE R.A = “123”  A materialized view is one that is computed once and its results are stored as a table  Think of this as a cached answer  These are incredibly useful!  Techniques exist for using materialized views to answer other queries  Materialized views are the basis of relating tables in different schemas SELECT * FROM V, R WHERE V.B = 5 AND V.C = R.C

6 Views Should Stay Fresh  Views (sometimes called intensional relations) behave, from the perspective of a query language, exactly like base relations (extensional relations)  But there’s an association that should be maintained:  If tuples change in the base relation, they should change in the view (whether it’s materialized or not)  If tuples change in the view, that should reflect in the base relation(s)

7 View Maintenance and the View Update Problem  There exist algorithms to incrementally recompute a materialized view when the base relations change  We can try to propagate view changes to the base relations  However, there are lots of views that aren’t easily updatable:  We can ensure views are updatable by enforcing certain constraints (e.g., no aggregation), but this limits the kinds of views we can have!  Several research projects at Penn are looking at problems related to this AB BC R S ABC R⋈SR⋈S delete?

8 Switching Gears Slightly: Views as a Bridge between Data Models A claim I made several times: “XML can’t represent anything that’s not also representable in the relational model” If I’m not lying, then we must be able to represent XML in relations  Store a relational view of XML (or create an XML view of relations)  You may have seen a hint of this previously, and thought about it on the midterm!

9 A View as a Translation between XML and Relations  You just read the first paper that tried to do this (Florescu & Kossmann)  Their focus was on showing that this worked better than a system designed “from the ground up” for semistructured data  You’ll be reviewing the most-cited paper in this area (Shanmugasundaram et al), and there are many more (Fernandez et al., …)  Techniques already making it into commercial systems  XPERANTO at IBM Research will appear in DB2 v8 or 9  SQL Server has some XML support; Oracle is also doing some XML  … Now you’ll know how it works!

10 Issues in Mapping Relational  XML  We know the following:  XML is a tree  XML is SEMI-structured  There’s some structured “stuff”  There is some unstructured “stuff”  Issues relate to describing XML structure, particularly parent/child in a relational encoding  Relations are flat  Tuples can be “connected” via foreign-key/primary-key links

11 The Simplest Way to Encode a Tree  You saw this one in your midterm: XYZ 14  If we have no IDs, we CREATE values…  BinaryLikeEdge(key, label, type, value, parent) keylabeltypevalueparent 0treeref-- 1contentref-0 2sub- content ref-1 3i-contentref-1 4-strXYZ2 5-int143 What are shortcomings here?

12 Florescu/Kossmann Improved Edge Approach  Consider order, typing; separate the values  Edge(parent, ordinal, label, flag, target)  Vint(vid, value)  Vstring(vid, value) parentordlabelflagtarget -1treeref0 01contentref1 11sub-contentstrv2 11i-contentintv3 vidvalue v314 vidvalue v2XYZ

13 How Do You Compute the XML?  Assume we know the structure of the XML tree (we’ll see how to avoid this later)  We can compute an “XML-like” SQL relation using “outer unions” – we first this technique in XPERANTO  Idea: if we take two non-union-compatible expressions, pad each with NULLs, we can UNION them together  Let’s see how this works…

14 A Relation that Mirrors the XML Hierarchy  Output relation would look like: rLabelridrOrdclabelcidcOrdsLabelsubOrdstrva l ival tree content sub-content XYZ i-content

15 A Relation that Mirrors the XML Hierarchy  Output relation would look like: rLabelridrOrdclabelcidcOrdsLabelsubOrdstrva l ival tree content sub-content XYZ i-content

16 A Relation that Mirrors the XML Hierarchy  Output relation would look like: rLabelridrOrdclabelcidcOrdsLabelsubOrdstrva l ival tree content sub-content XYZ i-content Colors are representative of separate SQL queries…

17 SQL for Outputting XML  For each sub-portion we preserve the keys (target, ord) of the ancestors  Root: select E.label as rLabel, E.target AS rid, E.ord AS rOrd, null AS cLabel, null AS cOrd, null as subOrd, null as strval, null as ival from Edge E where parent IS NULL  First-level child: select null as rLabel, E.target AS rid, E.ord AS rOrd, E1.label AS cLabel, E1.target AS cid, E1.ord AS cOrd, null as … from Edge E, Edge E1 where E.parent IS NULL AND E.target = E1.parent

18 The Rest of the Queries  Grandchild: select null as rLabel, E.target AS rid, E.ord AS rOrd, null AS cLabel, E1.target AS cid, E1.ord AS cOrd, E2.label as sLabel, E2.target as sid, E2.ord AS sOrd, null as … from Edge E, Edge E1, Edge E2 where E.parent IS NULL AND E.target = E1.parent AND E1.target = E2.parent  Strings: select null as rLabel, E.target AS rid, E.ord AS rOrd, null AS cLabel, E1.target AS cid, E1.ord AS cOrd, null as sLabel, E2.target as sid, E2.ord AS sOrd, Vi.val AS strval, null as ival from Edge E, Edge E1, Edge E2, Vint Vi where E.parent IS NULL AND E.target = E1.parent AND E1.target = E2.parent AND Vi.vid = E2.target  How would we do integers?

19 Finally…  Union them all together: ( select E.label as rLabel, E.target AS rid, E.ord AS rOrd, … from Edge E where parent IS NULL) UNION ( select null as rLabel, E.target AS rid, E.ord AS rOrd, E1.label AS cLabel, E1.target AS cid, E1.ord AS cOrd, null as … from Edge E, Edge E1 where E.parent IS NULL AND E.target = E1.parent ) UNION (. : ) UNION (. : )  Then another module will add the XML tags, and we’re done!

20 “Inlining” Techniques  Folks at Wisconsin noted we can exploit the “structured” aspects of semi-structured XML  If we’re given a DTD, often the DTD has a lot of required (and often singleton) child elements  Book(title, author*, publisher)  Recall how normalization worked:  Decompose until we have everything in a relation determined by the keys  … But don’t decompose any further than that  Shanmugasundaram et al. try not to decompose XML beyond the point of singleton children

21 Inlining Techniques  Start with DTD, build a graph representing structure tree content sub-content i-content * * * The edges are annotated with ?, * indicating repetition, optionality of children They simplify the DTD to figure this ?

22 Building Schemas  Now, they tried several alternatives that differ in how they handle elements w/multiple ancestors  Can create a separate relation for each path  Can create a single relation for each element  Can try to inline these  For tree examples, these are basically the same  Combine non-set-valued things with parent  Add separate relation for set-valued child elements  Create new keys as needed name book author

23 Schemas for Our Example  TheRoot(rootID)  Content(parentID,  Sub-content(parentID, varchar)  I-content(parentID, int)  If we suddenly changed DTD to <!ELEMENT content(sub-content*, i-content?) what would happen?

24 XQuery to SQL  Inlining method needs a lot more external knowledge about the schema  Needs to supply the tags and info not stored in the tables  We can actually directly translate simple XQuery into SQL over the relations – not simply reconstruct the XML

25 An Example for $X in document(“mydoc”)/tree/content where $X/sub-content = “XYZ” return $X  The steps of the path expression are generally joins  … Except that some steps are eliminated by the fact we’ve inlined subelements  Let’s try it over the schema: TheRoot(rootID) Content(parentID, Sub-content(parentID, varchar) I-content(parentID, int)

26 Wrapping up…  We’ve seen that views are useful things  Allow us to store and refer to the results of a query  We’ve seen an example of a view that changes from XML to relations – and we’ve even seen how such a view can be posed in XQuery and “unfolded” into SQL  Next time: we’ll start reasoning about views, which involves the introduction of another query language!