Views and XML Views of Relations

Slides:



Advertisements
Similar presentations
XML: Extensible Markup Language
Advertisements

From the Calculus to the Structured Query Language Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 22, 2005.
Keys, Referential Integrity and PHP One to Many on the Web.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CSE 6331 © Leonidas Fegaras XML and Relational Databases 1 XML and Relational Databases Leonidas Fegaras.
Query Execution, Concluded Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 18, 2003 Some slide content may.
Advanced Views: XML-Relational Storage and Datalog Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 8, 2005.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
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.
XML Views & Reasoning about Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 3, 2005 Some slide content.
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 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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
4/20/2017.
XML-to-Relational Schema Mapping Algorithm ODTDMap Speaker: Artem Chebotko* Wayne State University Joint work with Mustafa Atay,
The Relational Model These slides are based on the slides of your text book.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
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.
Ohio State University Department of Computer Science and Engineering Automatic Data Virtualization - Supporting XML based abstractions on HDF5 Datasets.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
1 CS 430 Database Theory Winter 2005 Lecture 17: Objects, XML, and DBMSs.
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Identity Constraints.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
Querying XML – Concluded Introduction to Views Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 9, 2003 Some.
Recursive Functions Creating Hierarchical Reports Date: 9/30/2008 Dan McCreary President Dan McCreary & Associates (952) M.
Relational Calculus Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems September 17, 2007 Some slide content courtesy.
1 XQuery to SQL by XML Algebra Tree Brad Pielech, Brian Murphy Thanks: Xin.
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.
CSCI-383 Object-Oriented Programming & Design Lecture 18.
XML and Database.
Views and XML/Relational Mappings Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 21, 2003.
XML Data Management Zachary G. Ives University of Pennsylvania CIS 650 – Implementing Data Management Systems November 25, 2008.
Querying XML, Part II Zachary G. Ives University of Pennsylvania CIS 455 / 555 – Internet and Web Systems February 5, 2008.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Chapter 04 Semantic Web Application Architecture 23 November 2015 A Team 오혜성, 조형헌, 권윤, 신동준, 이인용.
Chapter 3 The Relational Model. Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy.
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.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Creating Databases for Web applications
eXtensible Markup Language
Databases: What they are and how they work
Fundamentals of DBMS Notes-1.
XML: Extensible Markup Language
SQL – Python and Databases
Module 11: File Structure
XML: Extensible Markup Language
Lecture 2 The Relational Model
Translation of ER-diagram into Relational Schema
From ER to Relational Model
Relational Calculus Zachary G. Ives November 15, 2018
Database.
The Relational Model Relational Data Model
Module 8 – Database Design Using the E-R Model
Teaching slides Chapter 8.
Instructor: Mohamed Eltabakh
XML Views & Reasoning about Views
XML Views & Reasoning about Views
Querying XML: XPath, XQuery, and XSLT
Unit I-2.
CMSC-461 Database Management Systems
XML Querying and Views Zachary G. Ives November 1, 2007
Querying XML: XQuery and XSLT
Chapter 6b: Database Design Using the E-R Model
Presentation transcript:

Views and XML Views of Relations Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems November 22, 2018 Some slide content courtesy of Susan Davidson, Dan Suciu, & Raghu Ramakrishnan

Administrivia Homework 4 due 11/4 Project teams due Monday (4 people) XQuery Project teams due Monday (4 people) Read the Shanmugasundaram paper (posted on the Web site) by (or before) Sunday 11/8 Post a 1-page summary to the newsgroup What problems did they address? Basic techniques? Strengths & weaknesses of their methods?

Recall XQuery “FLWOR” statement [note case sensitivity!]: for {iterators that bind variables} let {collections} where {conditions} order by {order-conditions} (older version was “SORTBY”) return {output constructor} XQuery is very SQL-like, but cleaner and more orthogonal It is based on paths and binding tuples, with collections and trees as its first-class objects See www.w3.org/TR/xquery/ for more details on the language

XQuery Works Well with Schema, and Validates Against It (Incl. Keys) <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name=“ThesisType"> <xsd:attribute name=“key" type="xsd:string"/> … <xsd:sequence> <xsd:element name=“author" type=“xsd:string"/> ... <xsd:element name=“school" type=“xsd:string”/> </xsd:sequence> </xsd:complexType> <xsd:element name=“mastersthesis" type=“ThesisType"> <xsd:key name=“mtId">       <xsd:selector xpath=“.”/>  <xsd:field xpath="@key"/> </xsd:key> <xsd:keyref name=“schoolRef” refer=“schoolId">       <xsd:selector xpath=“./school”/>  <xsd:field xpath=“./text()"/> </xsd:keyref> </xsd:element> </xsd:schema>

Alternate Data Representations XQuery enables us to go XML  XML … or XML  HTML, or XML  text … In SQL, we go relations  relations … What about relations  XML and XML  relations? Let’s start with XML  XML, relations  relations

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 <content>{$a, $b, $c}</content> } Using the views: 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

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

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

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)

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 R A B 1 2 S B C 2 4 3 R⋈S A B C 1 2 4 3 delete?

Views as a Bridge between Data Models A claim we’ve made several times: “XML can’t represent anything that can’t be expressed in in the relational model” If this is true, then we must be able to represent XML in relations Store a relational view of XML (or create an XML view of relations)

A View as a Translation between XML and Relations 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 v9 SQL Server has some XML support; Oracle is also doing some XML … Next time you’ll see how it works!

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

The Simplest Way to Encode a Tree Suppose we had: <tree id=“0”> <content id=“1”> <sub-content>XYZ </sub-content> <i-content>14 </i-content> </content> </tree> If we have no IDs, we CREATE values… BinaryLikeEdge(key, label, type, value, parent) key label type value parent tree ref - 1 content 2 sub-content 3 i-content 4 str XYZ 5 int 14 What are shortcomings here?

Florescu/Kossmann Improved Edge Approach Consider order, typing; separate the values Vint(vid, value) Vstring(vid, value) Edge(parent, ordinal, label, flag, target) vid value v3 14 parent ord label flag target - 1 tree ref content sub-content str v2 i-content int v3 vid value v2 XYZ

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…

A Relation that Mirrors the XML Hierarchy Output relation would look like: rLabel rid rOrd clabel cid cOrd sLabel sid sOrd str int tree 1 - content sub-content 2 XYZ i-content 3 14

A Relation that Mirrors the XML Hierarchy Output relation would look like: rLabel rid rOrd clabel cid cOrd sLabel sid sOrd str int tree 1 - content sub-content 2 XYZ i-content 3 14

A Relation that Mirrors the XML Hierarchy Output relation would look like: rLabel rid rOrd clabel cid cOrd sLabel sid sOrd str int tree 1 - content sub-content 2 XYZ i-content 3 14 Colors are representative of separate SQL queries…

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 cid, null AS cOrd, null AS subOrd, null AS sid, null AS str, null AS int from Edge E where parent IS NULL First-level children: 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

The Rest of the Queries Grandchild: Strings: How would we do integers? 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 str, null as int 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?

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!