51
ADT 2008 ADT 2008 Lecture 3 Lecture 3 XML/XQuery Data Management XML/XQuery Data Management Beyond Chapter 10 of Beyond Chapter 10 of Silberschatz, Korth, Sudarshan Silberschatz, Korth, Sudarshan “Database System Concepts” “Database System Concepts” Stefan Manegold [email protected] http://www.cwi.nl/~manegold/

ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

ADT 2008ADT 2008Lecture 3Lecture 3

XML/XQuery Data ManagementXML/XQuery Data Management

Beyond Chapter 10 ofBeyond Chapter 10 ofSilberschatz, Korth, SudarshanSilberschatz, Korth, Sudarshan“Database System Concepts”“Database System Concepts”

Stefan [email protected]

http://www.cwi.nl/~manegold/

Page 2: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

2

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

why• Motivation & The Big Picture

what• Crash Course XQuery

WHO   • XML files   Saxon, Galax, GNU Qexo• XML DBMS   eXist, BerkeleyDB, MonetDB, X­Hive, Tamino, Xyleme• XML EAI   BEA Liquid Data, Data Direct, Mark Logic, Mono, Ipedo• XML RDBMS Oracle10g, SQLserver 2005, DB2

how• Under The Hood of MonetDB/XQuery• Some Benchmarks

XML DatabasesXML Databases

Page 3: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

3

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML Data Management SystemsXML Data Management Systems

XML File Processors Used as part of a document processing pipeline Small documents (messages)

XQuery Processor

XML

input

XML

output

Page 4: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

4

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML File ProcessorsXML File Processors Used as part of a document processing pipelineUsed as part of a document processing pipeline Small documents (messages)Small documents (messages)

XML Databases Manage large collections of XML documents Text Keyword Search Support (XML contains text..) Integration with Web Servers/Platforms

web server

application logic

web browser

the internet

XML DBMS

requestHTML

XMLXQuery

XML Data Management SystemsXML Data Management Systems

Page 5: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

5

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML File ProcessorsXML File Processors Used as part of a document processing pipelineUsed as part of a document processing pipeline Small documents (messages)Small documents (messages)

XML Databases Manage large collections of XML documents Text Keyword Search Support (XML contains text..) Integration with Web Servers/Platforms

web server

xslt rendering

web browser

the internet

XML DBMS

requestXHTML

XMLXQuery

=

XML Data Management SystemsXML Data Management Systems

Page 6: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

6

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML File ProcessorsXML File Processors Used as part of a document processing pipelineUsed as part of a document processing pipeline Small documents (messages)Small documents (messages)

XML DatabasesXML Databases Manage large collections of XML documentsManage large collections of XML documents Text Keyword Search Support (XML contains text..)Text Keyword Search Support (XML contains text..) Integration with Web Servers/PlatformsIntegration with Web Servers/Platforms

XML Integration Platforms XML as lingua franca to integrate data XML data:  intergrate data sources in XML; real­time access XML messaging: SOA frameworks (SOAP/WSDL,UDDI,BCEL) XQuery/XSLT for querying/transforming XML Integrated in J2EE/.NET application server (XQJ, XLinq)

WSDL

AppX AppX

WSDL

AppX

Unified XML Data Layer

XML messagetransformation

integrated virtualXML data model

XML DBMS

XML DBMS

RDBMSsotherdata

sources

Application server framework

SOA Framework

data caching

mediator mediatormediator

SOAP

XML Data Management SystemsXML Data Management Systems

Page 7: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

7

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML File ProcessorsXML File Processors Used as part of a document processing pipelineUsed as part of a document processing pipeline Small documents (messages)Small documents (messages)

XML DatabasesXML Databases Manage large collections of XML documentsManage large collections of XML documents Text Keyword Search Support (XML contains text..)Text Keyword Search Support (XML contains text..) Integration with Web Servers/PlatformsIntegration with Web Servers/Platforms

XML Integration PlatformsXML Integration Platforms XML as lingua franca to integrate dataXML as lingua franca to integrate data XML data:  intergrate data sources in XML; real­time accessXML data:  intergrate data sources in XML; real­time access XML messaging: SOA frameworks (SOAP/WSDL,UDDI,BCEL)XML messaging: SOA frameworks (SOAP/WSDL,UDDI,BCEL) XQuery/XSLT for querying/transforming XMLXQuery/XSLT for querying/transforming XML Integrated in J2EE/.NET application server (JXQ, XLinq)Integrated in J2EE/.NET application server (JXQ, XLinq)

RDBMS with XML Functionality Easily mix relational and XML, can be very useful for that .ini/properties file Query the XML VARCHAR with SQL/XML  ugly but works

web server

application logic

web browser

the internet

RDBMS

request

XMLSQL/XML

xml

HTML

XML Data Management SystemsXML Data Management Systems

Page 8: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

8

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Google HitsGoogle Hits

market share analysis

(poor-man‘s)EAI458KBEA Liquid Data xquery

xmldb18KNeoCore XMS xquery

xmldb24KXyleme xquery

EAI22KIpedo xquery

xmldb1440KeXist xquery

file17KGalax xquery

EAI24KOpenlink Virtuoso xquery

file41KQexo xquery

xmldb56KTamino xquery

xmldb65KX-Hive xquery

xmldb87KMonetDB xquery

EAI88KSonic XML xquery

Xmldb142KBerkeleyDB XML xquery

Xmldb225KXindice xquery

EAI419KMono xquery

EAI438KMark Logic xquery

File743KSaxon xquery

rdbms1220KSQLServer xquery

rdbms1470KOracle xquery

EAI2170KDataDirect xquery

Page 9: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

9

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML Data Management SystemsXML Data Management Systems

XML File Processors

XML Databases

XML Integration Platforms (EAI)

RDBMS with SQL/XML Functionality

#317KGalax xquery

#241KQexo xquery

#1743KSaxon xquery

#2438KMark Logic xquery

#11440KeXist xquery

#656KTamino xquery

#565KX-Hive xquery

#487KMonetDB xquery

#3142KBerkeleyDB XML xquery

#2225KXindice xquery

#2458KBEA Liquid Data xquery

#622KIpedo xquery

#524KOpenlink Virtuoso xquery

#488KSonic XML xquery

#3419KMono xquery

#12170KDataDirect xquery

#21220KSQLServer xquery

#11470KOracle xquery

Page 10: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

10

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML DatabasesXML DatabasesQueryingHow well is XPath/XQuery implemented?

All Axes? Collations? XMLSchema? Dynamic Typing? Modules? Recursive UDF?UpdatesWhat update dialect is used? (XUpdate / updateX / WebDAV / other)

W3C Update Facility Proposal (since jan 2006!)DB propertiesQuery performance/throughput (benchmarks published?)Update consistency model (fully serializable / snapshot consistency / s.th. less)Replication, Failover, Backup facilities APIsSOAP / WSDL

Call a query from outside <=> Calling out from a queryWeb Support

Cocoon/apache modules (web sessions, low overhead web queries)XML Beans (J2EE served from XMLDB)WebDAV

Language bindingsXQJ =>Java Binding     /    Xlinq => C# Binding

Page 11: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

11

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML DBMS comparisonXML DBMS comparison

+

+

-

+

-

++

+

fulltext

++++++Mark Logic

+++++++Tamino

+++++++++++X-Hive

+-+++++++MonetDB/XQuery

++++++++BerkeleyDB XML

+--+-Apache Xindice

+++-+++eXist

APIsreplicationscalabilityupdatesxquery

Page 12: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

12

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML Data Integration (EII)XML Data Integration (EII)• Virtual XML View Functionality

• Can you define (and query/update) a virtual XML view instead of the explicit sources

• Note: no W3C standard for XML views yet• Supported Backends 

• What data sources can be back­ends ODBC, JDBC, excel, word, xml

• Which (kind of queries can be pushed down)• SOA Framework Integration

• SOAP, WSDL, UDDI, BCEL• Application Framework (J2EE/.NET) integration

• Business logic in a 3GPL• XML beans or XML object binding• XQJ / Xlinq Java/C# Xquery interface

• Scalability• Load Balancing, Replication, Data Caching (!)

Page 13: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

13

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML Data Integration (EII)XML Data Integration (EII)

+++++Ipedo

+++++OpenLink Virtuoso

+-++++Sonic XML

++-++Mono

++++++++BEA Liquid Data

--++-DataDirect

J2EE/.NETxml viewmediatorsSOA

Page 14: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

14

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML in a Relational DBMSXML in a Relational DBMS

• Store XML as a BLOB in relational database • index by materializing indexed expressions in separate columns• Plus: store XML in parsed and validated form• Minus: proprietary solution (blob is a black box)• Minus: replicate data for indexing

• Schema­based Shredding• Map XML Schema / DTD to SQL DDL• Plus: integrates well with relational data• Minus:  missing tools, complicated 

•  SQL / XML• Extend SQL with XML data type• Plus: integrates well with relational data• Minus: not clear how it integrates with application, odd „marriage“

Page 15: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

15

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

History of SQL / XMLHistory of SQL / XML

• First edition part of SQL:2003• Part 14 of the SQL standard• Pre­dates XQuery standard!!!• Limited functionality ­ storage and publishing

• Second edition• More complete integration of XQuery + XQuery Data Model• Advanced Query capabilities• Published in 2006

Page 16: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

16

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

<Phantasy­People>

<row>

<Id>4711</Id>

<Name>Wutz</Name>

</row>

<row>

<Id>911</Id>

<Name>Potter</Name>

</row>

</Phantasy­People>

Potter911

Wutz4711

NameId

Phantasy-People

Publishing Rel. Data as XML (1/2)Publishing Rel. Data as XML (1/2)

Page 17: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

17

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Publishing Rel. Data as XML (2/2)Publishing Rel. Data as XML (2/2)

Page 18: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

18

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Publishing XML as Rel. TablePublishing XML as Rel. Table

('$MyDB//customer'

Page 19: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

19

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XML Type in SQLXML Type in SQL

• A new type (like varchar, date, numeric)• SQL:2003 ­ XML type restricted to

• XML document or• XML element or• Sequence of XML elements

• SQL / XML, 2nd edition• Full support of XQuery Data Model• XML(SEQUENCE), XML(ANY CONTENT), ...

Page 20: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

20

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Example (SQL:2003)Example (SQL:2003)create table books(title   varchar(20),authors  XML);

„P. Boncz“MonetDB

<author>D. Chamberlin </author>

<author>D. Florescu</author>

<author>et al.</author>

XQuery 1.0

AuthorsTitle

No schema validation, no typing!

• SQL:2006 => explicit validation with XMLVALIDATE()

Page 21: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

21

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XMLQueryXMLQuery

XMLQuery(

XQuery­expression

PASSING { BY REF | BY VALUE}

(value­expression AS identifier [BY REF | BY VALUE])*

RETURNING { CONTENT|SEQUENCE } { BY REF|BY VALUE}

)

• If PASSING value has no identifier, then that is context node• BY REF ­ preserves Id (of an XML type)• BY VALUE ­ creates a copy of the data

Page 22: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

22

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Oracle10g/11g: XQuery SupportOracle10g/11g: XQuery Support

1. XMLDB integrated database engine• SQL / XML standard support• Optimized queries – rewrite to relational 

2. Standalone Java query engine• 100% Java• Integrated into Oracle App Server ­XDS• Interoperates with XSLT/XPath

First relational database to ship an XQuery implementation !

Page 23: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

23

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Oracle 10g/11g: XQuery database supportOracle 10g/11g: XQuery database support

• Production in Oracle Database 10gr2• Supports XMLQuery and XMLTable construct• Native compilation into SQL /XML structures• Returns XMLType(Content)• Can query over relational, O­R, XMLType data• fn:doc ­ Maps to XDB Repository on server• SQLPlus provides xquery command to execute XQuery• XSL­T will also get compiled to XQuery 

Page 24: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

24

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Microsoft SQL Server 2005: OverviewMicrosoft SQL Server 2005: Overview

XML ParserXML ParserXMLXML

ValidationValidation

XML datatypeXML datatype

(binary XML)(binary XML)

SchemaSchemaCollectionCollection

XML SchemataXML Schemata

query()query()

modify()modify()Node Node TableTable

PATH PATH Index Index

PROP PROP Index Index

VALUE VALUE Index Index

PRIMARYPRIMARYXML INDEXXML INDEX

query()query()

Page 25: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

25

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

• Create XML index on XML columnCREATE PRIMARY XML INDEX idx_1 ON docs (xDoc)

• Creates secondary indexes on tags, values, paths• Speeds up queries

• Results can be served directly from index• Entire query is optimized

Same award winning cost based optimizer

• Indexes are used as available

Microsoft SQL Server 2005: IndexingMicrosoft SQL Server 2005: Indexing

Page 26: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

26

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

IBM DB2 v9: OverviewIBM DB2 v9: Overview

Page 27: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

27

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

IBM DB2 v9: StorageIBM DB2 v9: Storage

Page 28: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

28

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

IBM DB2 v9: SQL in XQueryIBM DB2 v9: SQL in XQuery

Page 29: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

29

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

IBM DB2 v9: XQuery in SQLIBM DB2 v9: XQuery in SQL

Page 30: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

30

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

IBM DB2 v9: IndexingIBM DB2 v9: Indexing

Page 31: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

31

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

why• Motivation & The Big Picture

what• Crash Course XQuery

who• XML files   Saxon, Galax, GNU Qexo• XML DBMS   eXist, BerkeleyDB, MonetDB, X­Hive, Tamino, Xyleme• XML EAI   BEA Liquid Data, Data Direct, Mark Logic, Mono, Ipedo• XML RDBMS Oracle10g, SQLserver 2005, DB2

HOW   • Under The Hood of MonetDB/XQuery• Some Benchmarks

XML DatabasesXML Databases

Page 32: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

32

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XQuery Systems: 2 ApproachesXQuery Systems: 2 Approaches

Native

Tree is basic data structure• tree­storage manager • tree­query processing (algebra)• tree­query optimization

Re­inventing the wheel?

Relational

Leverage RDBMS storage, query processing & optimization

• XML shredded into tables

• XQuery translated into SQL

Let’s use the old rim, 

but make a new tyre!

X-Hive TimberDB2BDB-XML

GalaxMicrosoftOracle

MonetDB/XQuery

Page 33: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

33

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

The IdeaThe Idea

Steel

Rim

Aluminium

Tyre

The IdeaThe Idea

Page 34: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

34

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Storing XML in Relations: Schema-Based ApproachStoring XML in Relations: Schema-Based Approach

Page 35: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

35

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Schema-Based Approach: Benefits & DrawbacksSchema-Based Approach: Benefits & Drawbacks

Page 36: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

36

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Peter Boncz, Stefan Manegold (CWI Amsterdam)

Torsten Grust, Jens Teubner, Jan Rittinger (Technische Universität München)

Maurice van Keulen (Technische Universiteit Twente)

MonetDB/XQueryA Fast XQuery Processor Powered by a Relational Engine

[ACM/SIGMOD 2006]

Page 37: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

37

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

MonetDBMonetDB

open-source Mozilla license => download at monetdb-xquery.org

Page 38: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

38

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Pathfinder Project

Torsten Grust, Jens Teubner, Jan Rittinger

Maurice van Keulen

MonetDB/XQueryMonetDB/XQuery

open-source Mozilla license => download at monetdb-xquery.org

Page 39: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

39

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Schema-Oblivious Storage: XPath AcceleratorSchema-Oblivious Storage: XPath Accelerator

Page 40: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

40

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

<a> <b> <c/> </b> <d/> <e> <f> <g/> <h/> </f> <i> <j/> </i> </e> </a>

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Node-based relational encoding of XQuery's data model

Page 41: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

41

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

0<a> 1<b> 2<c/> </b> 3<d/> 4<e> 5<f> 6<g/> 7<h/> </f> 8<i> 9<j/> </i> </e> </a>

Node-based relational encoding of XQuery's data model

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 42: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

42

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

Node-based relational encoding of XQuery's data model

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 43: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

43

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

Node-based relational encoding of XQuery's data model

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 44: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

44

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

Node-based relational encoding of XQuery's data model

① f/following: SELECT * FROM pre_post WHERE pre > f.pre AND post > f.post

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 45: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

45

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

Node-based relational encoding of XQuery's data model

① f/following: SELECT * FROM pre_post WHERE pre > f.pre AND post > f.post f/descendant: SELECT * FROM pre_post WHERE pre > f.pre AND post < f.post

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 46: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

46

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

Node-based relational encoding of XQuery's data model

① f/following: SELECT * FROM pre_post WHERE pre > f.pre AND post > f.post f/descendant: SELECT * FROM pre_post WHERE pre > f.pre AND post < f.post f/preceeding: SELECT * FROM pre_post WHERE pre < f.pre AND post < f.post

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 47: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

47

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Node-based relational encoding of XQuery's data model0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

① f/following: SELECT * FROM pre_post WHERE pre > f.pre AND post > f.post f/descendant: SELECT * FROM pre_post WHERE pre > f.pre AND post < f.post f/preceeding: SELECT * FROM pre_post WHERE pre < f.pre AND post < f.post f/ancester: SELECT * FROM pre_post WHERE pre < f.pre AND post > f.post

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 48: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

48

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Node-based relational encoding of XQuery's data model

① f/following: SELECT * FROM pre_post WHERE pre > f.pre AND post > f.post f/descendant: SELECT * FROM pre_post WHERE pre > f.pre AND post < f.post f/preceeding: SELECT * FROM pre_post WHERE pre < f.pre AND post < f.post f/ancester: SELECT * FROM pre_post WHERE pre < f.pre AND post > f.post

Similar queries for other XPath axes

0<a> 1<b> 2<c/>0 </b>1 3<d/>2 4<e> 5<f> 6<g/>3 7<h/>4 </f>5 8<i> 9<j/>6 </i>7 </e>8 </a>9

XPath Accelerator: XPath Accelerator: pre/postpre/post plane plane

Page 49: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

49

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

pre/postpre/post Table &  Table & pre/size/levelpre/size/level Table Table

<a> <b> <c/> </b> <d/> <e> <f> <g/> <h/> </f> <i> <j/> </i> </e> </a>

Pre Posta 0 9b 1 1c 2 0d 3 2e 4 8f 5 5g 6 3h 7 4i 8 7j 9 6

Pre Size Level0 9 01 1 12 0 23 0 14 5 15 2 26 0 37 0 38 1 29 0 3

Post = pre + size - level

Page 50: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

50

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

Complete XML Storage SchemaComplete XML Storage Schema

Page 51: ADT 2006 Lecture 3 XML/XQuery Data Management …homepages.cwi.nl/.../lectures/ADT2008_03_XML_XQuery_2.pdfADT 2008 Lecture 3 XML/XQuery Data Management Beyond Chapter 10 of Silberschatz,

51

[email protected] Lecture 3: XML/XQuery Data Management ADT 2008

XPath evaluation (SQL)XPath evaluation (SQL)

Example query: /descendant::open_auction[./bidder]/annotation

SELECT DISTINCT a.pre FROM doc r, doc oa, doc b, doc a WHERE r.pre=0 AND oa.pre > r.pre AND oa.post < r.post AND oa.name = “open_auction” AND oa.kind = “elem” AND b.pre > oa.pre AND b.post < oa.post AND b.level = oa.level + 1 AND b.name = “bidder” AND b.kind < “elem” AND a.pre > oa.pre AND a.post < oa.post AND a.level = oa.level + 1 AND a.name = “annotation” AND a.kind = “elem” ORDER BY a.pre

<- descendant

} child

} child