structural joins on xml documents

75
Efficient Querying of XML Data Using Structural Joins

Upload: tess98

Post on 09-Dec-2014

1.156 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Structural joins on XML documents

Efficient Querying of XML Data Using Structural Joins

Efficient Querying of XML Data Using Structural Joins

Page 2: Structural joins on XML documents

ContentContent

A quick look at XML query languages

Lore - an example of a native XML database

DB2 - an example of RDBMS’s support for XML

On supporting containment queries in RDBMS

The Tree-Merge and Stack-Tree algorithms

The StackPath algorithm

Page 3: Structural joins on XML documents

XMLXML

Replacement for HTML– Focus is on storing and processing.

Electronic Data Interchange– Querying becomes desirable.

People with many XML documents actually have an XML database.

Page 4: Structural joins on XML documents

XML query languagesXML query languages

XML-QL– Influenced by SQL– Submitted to W3C (lost favor to XQuery)

XPath– used in XSLT– the basis for path expressions in XQuery

XQuery– A W3C working draft (version 1.0)– Based on Quilt (which in turn was mainly influenced

by XML-QL and Lorel)– No updates, limited IR features

Page 5: Structural joins on XML documents

XPathXPath

1. */para1. selects all para grandchildren of the context node

2. /doc/chapter[5]/section[2]1. selects the second section of the fifth chapter of the doc

3. chapter//para1. selects the para element descendants of the chapter element

children of the context node

4. para[@type="warning"]1. selects all para children of the context node that have a type

attribute with value warning

5. chapter[title="Introduction"]1. selects the chapter children of the context node that have one or

more title children with string-value equal to Introduction

Page 6: Structural joins on XML documents

XQueryXQuery

document("books.xml")//chapter/title– Finds all titles of chapters in document books.xml

document(bib.xml")//book[publisher = "Addison-Wesley”AND @year > "1991"]– Finds all books in document bib.xml published by Addison-

Wesley after 1991 <results> {

FOR $t IN distinct(document("prices.xml")/prices/book/title)

LET $p := avg(document("prices.xml")/prices/book[title=$t]/price)

WHERE (document("bib/xml")/book[title=$t]/publisher) = "Addison-Wesley"

RETURN

<result> { $t } <avg> { $p } </avg> </result>

} </results>

– Returns the title and average price of all books published by Addison-Wesley

Page 7: Structural joins on XML documents

XML documents as treesXML documents as trees

<book year=“2000”>

<title> XML </title>

<authors>

<author> Bill </author>

<author> Jake </author>

</authors>

<chapter>

<head> History </head>

<section>

<head> … </head>

<section> … </section>

</section>

<section> … </section>

</chapter>

<chapter> … </chapter>

</book> Order of nodes is important

book

year title authors chapter chapter

2000 XML author head section section

Bill Jake

author

History head section

...

...

......

Page 8: Structural joins on XML documents

XML documents as treesXML documents as trees

<book year=“2000”>

<title> XML </title id=“id1”>

<authors>

<author> Bill </author>

<author> Jake </author>

</authors>

<chapter>

<head> History </head>

<section>

<head> … </head>

<section> … </section idref=“id1”>

</section>

<section> … </section>

</chapter>

<chapter> … </chapter>

</book> Order of nodes is important

book

year authors chapter chapter

2000 xml author head section section

Bill Jake

author

History head

...

...

......

title

section

Page 9: Structural joins on XML documents

Executing queriesExecuting queries

How does one execute a complex query:– Parse the query (i.e. break it down to basic operations).– Let a query optimizer devise a corresponding physical query

plan.– Execute the required basic operations combining the

intermediate results as you go.

The most common basic operations are:– Finding nodes satisfying a given predicate on their value.– Finding nodes satisfying a given structural relationship.

Page 10: Structural joins on XML documents

XML databasesXML databases

XML is semi-structured; data items may have missing elements or multiple occurrences of the same element.It may even not have a DTD.

Native semi-structured databases– X-Hive, Lore

RDBMS– Oracle– SQL-Server– DB2

All added support for XML

Page 11: Structural joins on XML documents

Semi-structured XML databasesSemi-structured XML databases

There aren’t many around

Store XML files plus indexes

Usually build (and store) most or all of the tree

Usually solve path expressions by pointer-chasing

Page 12: Structural joins on XML documents

LOREAn example of a native semi-structured

database

LOREAn example of a native semi-structured

database

Page 13: Structural joins on XML documents

Lore - sample databaseLore - sample database

Select x

From DBGroup.Member x

Where exists y in x.age: y<30

Page 14: Structural joins on XML documents

Lore - data modelLore - data model

Called the Object Exchange Model The data model is a graph (though the reference edges

are marked as such). Each vertex is an object with a unique object identifier. Atomic objects have no outgoing edges and contain

values (like strings, gifs, audio etc.) All other objects may have outgoing edges. Tag-Names (labels) are attached to the edges, not the

vertices. Objects may optionally have aliases (names).

As is obvious this is just another view of our XML tree

Page 15: Structural joins on XML documents

Lore - indexesLore - indexes

Vindex (value index) - implemented as a B+-tree– Supports finding all atomic objects with a given incoming edge

label satisfying a given predicate. Lindex (label index) - implemented using extendible hashing

– Supports finding all parents of a given object via an edge with a given label.

Bindex (edge index)– Supports finding all parent-child pairs connected via a given

label. This is useful for locating edges with rare labels.

In addition there are some other indexes (not important to us).

Note that we need more indexes than in a relational database

Page 16: Structural joins on XML documents

Lore - statistics (partial list)Lore - statistics (partial list)

For each labeled path p of length <= k (usually k=1):

– The total number of instances of p, denoted |p|

– The total number of distinct objects reachable via p,denoted |p|d

– The total number of l-labeled edges going out of p,denoted |p l|

– The total number of l-labeled edges coming into p,denoted |p l|

Page 17: Structural joins on XML documents

Lore - path expressions (simplified)Lore - path expressions (simplified)

Simple path expressions– x.l y

Path expressions– an ordered list of simple path expressions

– x.l y, y.l2 z

Path expressions logical plan:

x.B y, y.C z, z.D v

Page 18: Structural joins on XML documents

Lore - basic physical operators (slightly edited)Lore - basic physical operators (slightly edited)

Scan(father, label, son)– Finds all the sons of a given father (through a given label).Does pointer-chasing

Lindex(father, label, son)– Finds all the fathers of a given son (through a given label).Uses the Lindex

Bindex(label, father, son)– Finds all the father-son pairs connected by a given label.Uses the Bindex

Vindex(label, operator, value, atomic-object)– Finds all the the atomic objects with a given label incoming label

satisfying the given predicate.Uses the Vindex

Name(alias, node)– Verifies that the specified node has the given alias.

Page 19: Structural joins on XML documents

Lore - physical path subplansLore - physical path subplans

x and y are unbound y is bound x and y are unbound

The estimated hit-rate (per x) of scan(x, “C”, y) is: (|B C| / |B|d)

The estimated hit-rate (per y) of Lindex(x, “C”, y) is: (|C B| / |C|d)

Page 20: Structural joins on XML documents

Lore - sample logical planLore - sample logical plan

Select x From DBGroup.Member x Where exists y in x.age: y<30

– Glue nodes are pivot points, they recursively evaluate the cost of evaluating their sons in left-right or right-left order.

Page 21: Structural joins on XML documents

Lore - sample physical subplansLore - sample physical subplans

(a) corresponds to a possible left-right plan of the top “glue” (b) corresponds to a possible left-right plan of the right “glue” (c) corresponds to a possible right-left plan of the right “glue” (d) corresponds to a possible right-left plan of the top “glue”, using (c)

Page 22: Structural joins on XML documents

Lore - path expressions strategiesLore - path expressions strategies

A higher level view of path expressions solving

Top-Down– Look for all Member objects in DBGroup and for each one look for

Age subobjects with a value < 30.uses scan

Bottom-up– Look for all atomic objects with value < 30 and for each one walk up

the tree using only Age-labeled followed by Member-labeled edges.uses Vindex and then Lindex

Hybrid– Do Top-Down part of the way and Bottom-Up part of the way.

Select x From DBGroup.Member x Where exists y in x.age: y<30

Page 23: Structural joins on XML documents

Lore - path strategies (continued)Lore - path strategies (continued)

Top-Down is better when there are few paths satisfying the required structure, but many objects satisfying the predicate.

Bottom-Up is better when there are a few objects satisfying the predicate but many paths satisfying the required structure.

Hybrid is better when the fan-out degree (going down), increases at the same time the fan-in degree (going up) does.

Page 24: Structural joins on XML documents

DB2An example of a RDBMS support of

XML

DB2An example of a RDBMS support of

XML

Page 25: Structural joins on XML documents

DB2 - XML support DB2 - XML support

XML column– An entire XML document is stored as a column in a table.– may be XMLCLOB, XMLVARCHAR or XMLFile.– You define which XML elements or attributes should be

extracted to indexed columns in side tables.

– UDF’s are provided for inserting, updating and selecting fragments of a document.

XML collection– Compose an XML document from existing DB2 tables.– Decompose an XML document and retrieve some of it into a set

of DB2 tables.– Basically a conversion mechanism.

– Stored procedures automate most of the work.

Page 26: Structural joins on XML documents

DB2 - a nice diagram...DB2 - a nice diagram...

Page 27: Structural joins on XML documents

DB2 - example Data Access DefinitionDB2 - example Data Access Definition

Page 28: Structural joins on XML documents

DB2 - example DAD (continued)DB2 - example DAD (continued)

Page 29: Structural joins on XML documents

DB2 - searching XML documentsDB2 - searching XML documents

Well, whatever is in the side tables is queried using SQL.

What about things not in any side table?

– A loosely coupled IR engine (part of the DB2 Text Extender) is called using a UDF to take care of this.

– The UDF’s use a syntax compatible with XPath.

Page 30: Structural joins on XML documents

DB2 - conclusions (in a nutshell)DB2 - conclusions (in a nutshell)

Pros– Integrated solution which automates a lot of work.– We can ask queries that mix data from XML and the regular

database tables (aka “web-supported database queries” and “database-supported web queries”).

Cons– One has to manually define the mappings between the XML

documents and the tables.– Is it fast enough?

Page 31: Structural joins on XML documents

On Supporting Containment Queries in RDBMS

On Supporting Containment Queries in RDBMS

Zhang, Naughton, DeWitt, Luo, Lohman

ACM SIGMOD 2001

Page 32: Structural joins on XML documents

Article goalsArticle goals

Given that a lot of XML data is (and will probably be) stored in RDBMS which is the best way to support containment queries?

– Using a loosely coupled IR engine?

OR

– Using the native tables and query mechanisms of the RDBMS?

Page 33: Structural joins on XML documents

Structural relationships in treesStructural relationships in trees

1

2

3

4

5

6

7 9

11

12 14

8 10 13 15

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15book

year title authors chapter

2000 XML author head section

Bill Jake

author

History head

pre-order book

year title authors chapter

2000 XML author head section

Bill Jake

author

History head

post-order

Note that x is a descendant of y if and only if:preorder(x) > preorder(y) and postorder(x) < postorder(y)

y is the father of x if in addition: level(x) = level(y) + 1

Page 34: Structural joins on XML documents

Structural relationships in XMLStructural relationships in XML

The previous observations are true even if we look at any monotone functions of the preorder and the postorder numbers.

The start and end position of an element in an XML document are exactly such monotone functions.

In other words we can use a small extension of the regular

IR inverted-index to also solve structural relationships!

Note that we have a problem of adapting the numbers if the document changes.

Page 35: Structural joins on XML documents

The inverted indexesThe inverted indexes

An Elements index (E-Index): Holds for each XML element, the docno, begin, end and level of every occurrence of that element.

A Text index (T-Index): Holds for each text word, the docno, wordno and level of every occurrence of the word.

Page 36: Structural joins on XML documents

Experiment planExperiment plan

Compare the following two systems:

An inverted list engine supporting containment queries on XML data.– The engine was built (due to lack of a commercial one).– The code was written in C++ and the inverted-indexes were

stored in a B+-tree with each list stored as a record.– Each list is in ascending order of docno, begin (or wordno).– An in-house algorithm was developed for evaluating simple

containment queries. A full RDBMS approach (tried DB2 7.1 and SQL-Server 7.0)

– The E-index and T-index are stored as the following tables: ELEMENTS(term, docno, begin, end, level)TEXTS(term, docno, wordno, level)

Note that we do not use the IR engine of the RDBMS.

Page 37: Structural joins on XML documents

Using the inverted indexes tablesUsing the inverted indexes tables

E//"T”

select * from ELEMENTS e, TEXTS t

where e.term = ’E’ and t.term = ’T’

and e.docno = t.docno

and e.begin < t.wordno and t.wordno < e.end

E="T"

select * from ELEMENTS e, TEXTS t

where e.term = ’E’ and t.term = ’T’

and e.docno = t.docno

and e.begin + 1 = t.wordno and t.wordno + 1 = e.end

In a similar fashion we solve Elements only queries, father-son, and words distance queries.

(how will this look for E//E ?)xy

xy x

y

Page 38: Structural joins on XML documents

Experiment setupExperiment setup

The data sets:

Page 39: Structural joins on XML documents

Experiment setup (continued)Experiment setup (continued)

The queries are all simple queries of the form: E//T, E//E, E/T or E/E

Page 40: Structural joins on XML documents

Experiment resultsExperiment results

Page 41: Structural joins on XML documents

Results analysisResults analysis

Why did DB2 perform better in QS4, QD4 and QG5?

Remember that each list in the inverted engine is stored as one record!

Why did DB2 perform worse in all the other queries?– Bad optimizer decisions?– Is I/O more expensive (locking, security, etc.)?– Other factors?– It turns out that the queries are CPU-bound!

Further investigation found out that it was the merge algorithm.

Page 42: Structural joins on XML documents

DB2 merge algorithmsDB2 merge algorithms

When joining on:

a.docno = d.docno and a.begin < d.wordno and d.wordno < a.end

Standard Merge-Join only uses the a.docno = d.docno predicate (since it does one comparison, using one index per table), and applies the rest of the condition on each matching couple.

Hash-Join only uses the a.docno = d.docno predicate (since it can not handle inequalities anyway), and thus performs similarly to the classical merge join.

Index nested-loop join looks, for each row in the outer table, for all rows in the inner table index that lie between a start-key and astop-key.

Assuming the outer table is ELEMENTS and the inner table is TEXTS:

– start-key: term = value and docno = outer.docno and wordno > outer.begin

– end-key: term = value and docno = outer.docno and wordno < outer.end

Page 43: Structural joins on XML documents

The Multi-Predicate Merge JoinThe Multi-Predicate Merge Join

begin-desc = Dlist->first node; OutputList = NULL;

for (a = Alist->firstNode; ; a = a->nextNode) {

d = begin_desc;

while (d.docno < a.docno) d = d->nextNode;

if (a.docno < b.docno) continue;

while (d.begin <= a.begin) d = d->nextNode;

begin_desc = d;while (d.begin < a.end) { // implies d.end < a.end

if (a.docno < b.docno) break;

append (a,d) to OutputList;

d = d->nextNode;

}

}

doc begin end

5 7 20

5 14 19

5 21 28

5 22 27

5 29 31

5 32 40

doc begin

5 2

5 23

5 24

5 33

5 37

5 42

Alist Dlist

Page 44: Structural joins on XML documents

Comparison of the merge algorithmsComparison of the merge algorithms

It seems like the NLJ algorithm will usually compare less items, BUT It has to spend time on index seeks! It uses random access so cache utilization is poor.

Page 45: Structural joins on XML documents

MPMGJN & traditional joins - statisticsMPMGJN & traditional joins - statistics

Note: DB2 did not choose NLJ for QG4

Page 46: Structural joins on XML documents

Structural Joins: A Primitive for Efficient XML Query

Pattern Matching

Structural Joins: A Primitive for Efficient XML Query

Pattern Matching

Al-Khalifa, Jagadish, Koudas, Patel, Srivastava, Wu

ICDE 2002

Page 47: Structural joins on XML documents

Structural-Join algorithmsStructural-Join algorithms

Tree-Merge-Anc (aka MPMGJN) Tree-Merge-Desc Stack-Tree-Desc Stack-Tree-Anc

The ?-?-Anc algorithms produce the output sorted by the ancestors.

The ?-?-Desc algorithms produce the output sorted by the descendants.

The sorting variant to use depends on the way an optimizer chooses to compose a complex query.

Based on the (docId, startPos, endPos, level) information of XML elements and attributes.

Given two lists of potential ancestors and potential descendants, both in ascending order of docId+startPos, the following structural join algorithms are presented:

Page 48: Structural joins on XML documents

Tree-Merge-AncTree-Merge-Anc

begin-desc = Dlist->first node; OutputList = NULL;

for (a = Alist->firstNode; ; a = a->nextNode) {

d = begin_desc;

while (d.startPos <= a.startPos) d = d->nextNode;

begin_desc = d;

while (d.startPos < a.endPos) { // implies d.endPos < a.endPos

if (a.level +1 != d.level) continue; // father-son

append (a,d) to OutputList;

d = d->nextNode;

}

}

Note: For ease of exposition, we assume that Alist and Dlist have the same docId.

Page 49: Structural joins on XML documents

Analysis of Tree-Merge-AncAnalysis of Tree-Merge-Anc

Ancestor-Descendant structural relationships:– O(|Alist| + |Dlist| + |OutputList|)– Since first while loop increases d, and second while loop increases output or a.

Father-Son structural relationships: – O(|Alist| * |Dlist|)

...

...

a1

a2

a3

an

d3d1 d2 dn

begin end

a1 1 4n

a2 2 4n-1

a3 3 4n-2

.

.

an n 3n+1

begin

d1 n+1

d2 n+3

d3 n+5

.

.

dn 3n-1

Alist Dlist

Can sub-sorting on levelNum help ?

Page 50: Structural joins on XML documents

Tree-Merge-DescTree-Merge-Desc

begin-anc = Alist->first node; OutputList = NULL;

for (d = Dlist->firstNode; ; d = d->nextNode) {

a = begin_anc;

while (a.endPos <= d.startPos) a = a->nextNode;

begin_anc = a;

while (a.startPos < d.startPos) {

if (a.level +1 != d.level) continue; // father-son

if (d.endPos < a.endPos) append (a,d) to OutputList;

a = a->nextNode;

}

}

Note: For ease of exposition, we assume that Alist and Dlist have the same docId.

Page 51: Structural joins on XML documents

Analysis of Tree-Merge-DescAnalysis of Tree-Merge-Desc

Ancestor-Descendant and Father-Son structural relationships: – O(|Alist| * |Dlist|).– Works in linear time on most real data.

...

begin end

a0 1 4n+2

a1 2 5

a2 6 9

a3 10 13

.

.

an 4n-2 4n+1

begin

d1 3

d2 7

d3 11

.

.

dn 4n-1

Dlist Alist

a0

a3a1 a2 an

d1 d2 d3 dn...

Page 52: Structural joins on XML documents

Stack-Tree algorithmsStack-Tree algorithms

Motivation

– A depth-first traversal of a tree can be performed in linear time, using a stack as large as the height of the tree.

– An ancestor-descendant structural relationship is manifested as the ancestor appearing higher on the stack than the descendant.

– Unfortunately, a depth-first traversal requires going over all the tree.

Page 53: Structural joins on XML documents

Stack-Tree-DescStack-Tree-Desc

a = Alist->first node; d = Dlist->first node; OutputList = NULL;

while (lists are not empty) {

e = (a.startPos < d.startPos) ? a : d;

while (e.startPos > stack->top.endPos) stack->pop();if (e == a) { // remember that e.startPos > stack->top.startPos

stack->push(a);

a = a->nextNode;} else // e == d

for each a’ in stack { // Father-Son: If (stack->top.level + 1 = d.level) append(stack->top, d)

append (a’, d) to OutputList;

}

d = d->nextNode;

}

}

Note: For ease of exposition, we assume that Alist and Dlist have the same docId.

Page 54: Structural joins on XML documents

Stack-Tree-Desc (father-son example)Stack-Tree-Desc (father-son example)

a1

d1

a2

d2

. .

. .

an

dn

dn+1

dn+2

.

.

d2n

d1 d2n

d2 d2n-1

d3 d2n-2

dn dn+1

a1

a2

a3

an

a1

(a1,d1)

a2

(a2,d2) ...

.

.

.

(an-1,dn-1)

an

(an,dn)(an,dn+1) (an-1,dn+2)

... (a3,d2n-2)(a2,d2n-1)(a1,d2n)

? e.startPos > stack->top.endPos

...

Page 55: Structural joins on XML documents

Analysis of Stack-Tree-DecAnalysis of Stack-Tree-Dec

O(|Alist| + |Dlist| + |OutputList|) for ancestor-descendant as well as father-son structural relationships.

– Each Alist element is pushed once and popped once, so stack operations take O(|Alist|).

– The inner “for loop” outputs a new pair each time, so its total time is O(|OutputList|).

– When doing father-son structural joins, we do not even have a “for loop”.

The algorithm is non-blocking.

IO complexity is O(|Alist|/P + |Dlist|/P + |OutputList|/P) where P is the page size.

– Each input page is read just once (and output sent as soon as it is computed).– The stack is as large as the tree height, so it is very reasonable to assume that it

fits in RAM.

Page 56: Structural joins on XML documents

Stack-Tree-AncStack-Tree-Anca = Alist->first node; d = Dlist->first node; OutputList = NULL;

while (lists are not empty) {

e = (a.startPos < d.startPos) ? a : d;

while (e.startPos > stack->top.endPos) {

temp = stack->pop();

if (stack->isEmpty()) {

append temp->selfList to OutputList; append temp->inheritList to OutputList;

} else {

append temp->inheritList to temp->selfList; append temp->selfList to stack->top->inheritList;

}

}

if (e == a) { // remember that e.startPos > stack->top.startPos

stack->push(a); a = a->nextNode;

} else { // e == d

for each a’ in stack {

if(a’ == stack->bottom) append (a’, d) to OutputList;

else append (a’, d) to selfList associated with a’

}

d = d->nextNode;

}

} if (!stack->isEmpty()) flush the stack held lists to the outputNote: For ease of exposition, we assume that Alist and Dlist have the same docId.

Page 57: Structural joins on XML documents

Stack-Tree-Anc (father-son example)Stack-Tree-Anc (father-son example)

a1

d1

a2

d2

. .

. .

an

dn

dn+1

dn+2

.

.

d2na1(a1,d1)

a2(a2,d2)

.

.

.

(an-1,dn-1)

an(an,dn) (an,dn+1)

(a3,d3),(a3,d2n-2)...(an,dn),(an,dn+1) (a2,d2n-1)

(a1,d2n)

d1 d2n

d2 d2n-1

d3 d2n-2

dn dn+1

a1

a2

a3

an

...

(an,dn), (an,dn+1)

(a2,d2),(a2,d2n-1)...(an,dn),(an,dn+1)

.

.

.

? e.startPos > stack->top.endPos

Page 58: Structural joins on XML documents

Analysis of Stack-Tree-AncAnalysis of Stack-Tree-Anc

O(|Alist| + |Dlist| + |OutputList|) For ancestor-descendant as well as father-son structural relationships.

– Assuming the lists are maintained as linked lists with head and tail pointers.

The algorithm is blocking (but only partially).

IO complexity is O(|Alist|/P + |Dlist|/P + |OutputList|/P) where P is the page size.

– We cannot assume that all the lists fit in RAM.– All that we do with lists (except output) is appending.– We can page out a list and we need only keep its tail in RAM. So we need two

extra pages in memory per stack entry - still a reasonable assumption.– We only need to know the address of the head of a list.– Each list page is thus paged out at most once, and paged back in only for output.

Page 59: Structural joins on XML documents

Experiment workloadExperiment workload

Experimented with real XML data as well as synthetic data generated by IBM XML data generator (with similar results).

Presented the results for the largest data set: 6.3 million elements (800Mb of data).

Page 60: Structural joins on XML documents

Experiment resultsExperiment results

Implemented the structural join algorithms, as well as bottom-up and top-down, on the TIMBER native XML query engine (built on top of SHORE).

Bottom-up and top-down performed poorly:– Even on 10% of the data it took bottom-up 283.5 seconds to run

QS1, and 717.8 seconds for top-down to do it.– It took less than 15 seconds for any of the join algorithms to

complete QS1 on the full data set!

Page 61: Structural joins on XML documents

Experiment results (continued)Experiment results (continued)

Implemented the STJ-D as an application program interfacing to a commercial RDBMS through a set of cursors.

Also ran the queries using the RDBMS join mechanisms.

QS1:

Combined: an index on startPos, endPos

Small: up to 10% selectivity, Medium: up to 25%

Page 62: Structural joins on XML documents

Experiment results (continued)Experiment results (continued)

Page 63: Structural joins on XML documents

Holistic Twig Joins:Optimal XML Pattern Matching

Holistic Twig Joins:Optimal XML Pattern Matching

Bruno, Koudas, Srivastava

ACM SIGMOD 2002

Page 64: Structural joins on XML documents

Twig patternsTwig patterns book[title = “XML” AND year = 2000] book[title = “XML”]//author[Fn = “jane” AND Ln = “doe”]

book

year title authors chapter chapter

2000 XML author head section section

Ln title section

...

...

...

Fn

jane doe

author

LnFn

john moe

author

LnFn

john doe

...

XML

...

title

XML

year

2000

book

title

XML

author

Ln

book

jane doe

Fn

Twig patterns

Page 65: Structural joins on XML documents

Twig pattern matchingTwig pattern matching

Given a twig pattern Q and an XML database D, a match is a mapping from nodes in Q to nodes in D, satisfying:

– Query node predicates are satisfied by their images.

– The structural relationships between the query nodes are satisfied by their images.

If Q has k nodes, the result may be represented by a relation with k columns.

Page 66: Structural joins on XML documents

Twig pattern matching approachesTwig pattern matching approaches

Decompose the twig into a series of binary structural joins, compute each (using STJ-D for example) and join the results.– Note that one may have intermediate results that are very big.

Consider for example: book[title = “XML”]

Decompose the twig into a series of rooted path-expressions, compute each one independently and merge-join the results.– Note that one may have intermediate results that are very big

(but only in different branches).Consider for example: book//author[Fn = “jane” AND Ln = “doe”]

Decompose the twig into a series of rooted path-expressions, compute them simultaneously taking interdependencies into account, and merge-join the results.

Page 67: Structural joins on XML documents

PathStack-DescPathStack-Desc

go to start of all lists; OutputList = NULL;

while (lists are not empty) {e = element with minimum startPos in all lists;

i = the list e was taken from; advance list i;

for(int j=1; j < numLists; j++) {

while (e.startPos > stackj->top.endPos) stackj->pop();

}if (e is not from the leaf list) { // remember that for every stack e.startPos > stack->top.startPos

stacki->push(a, &stacki-1->top); // if the I-1 stack is not empty of course

} else { // e is the path query leaf

let (x1, x2, … xnumLists-1) be the linked list whose head is the top of the numLists-1 stack.

For each (y1, y2, … ynumLists-1, e) such that for all j yj is below xj do:

append (y1, y2, … ynumLists-1, e) to OutputList;

}

} Note: For ease of exposition, we assume that all lists have the same docId.

Page 68: Structural joins on XML documents

PathStack-Desc (example)PathStack-Desc (example)

a1

b1

a2

b2

c1

b3

c2? e.startPos > stack->top.endPos

a1

b1

a2

b2

c1

b3

c2

b

c

a

a1b1

a2b2

(a2,b2,c1) (a1,b2,c1) (a1,b1,c1) (a1,b3,c2)

b3

Page 69: Structural joins on XML documents

PathStack-Desc experimental resultsPathStack-Desc experimental results

Implemented the binary join algorithms, as well as the StackPath, in C++ using the file-system as the storage engine.

Used a synthetic data set made of 1 million nodes with 6 different labels (A1, A2, …A6) uniformly distributed (no information regarding other parameters).

Page 70: Structural joins on XML documents

Final remarksFinal remarks

What we did not do (partial list):– Look at using B+-Trees with the stack algorithms.– Look at the TwigStack algorithm.– Look at Kleen-closure evaluation.

Conclusions:

– There is a lot more work to be done by everybody.

Page 71: Structural joins on XML documents

Appendix: TwigStack (in a nutshell)Appendix: TwigStack (in a nutshell)

getNext(q) returns a query node such that the head of its list satisfies:– It has the smallest startPos (L) of all the heads of its descendant and sibling lists.– It participates in a solution to the sub-query rooted at that query node.– If it is part of a solution involving its ancestors they were already read.

Page 72: Structural joins on XML documents

Appendix (continued)Appendix (continued)

Note that as long as 09 succeeds we return the node whose head has the smallest startPos (L) of all the heads of lists in the sub-tree of q.When 09 fails we “float up” a node whose list head has the the smallest startPos (L) of all the heads of lists in its descendant or sibling lists.

Once a node floats up, its father node’s list does not contain any more ancestors of its list head (otherwise 09 would not fail). Applying the same logic to the father and grandfather etc. leads us by induction to the conclusion that if it this node’s list head is part of a solution involving its ancestors, these ancestors are already out of their lists.

Page 73: Structural joins on XML documents

Appendix (continued)Appendix (continued)

Both used ternary trees.– Left sub-tree in (a) has only A1=A2=A3=A4 paths.– Middle sub-tree in (a) has only A1=A5=A6=A7 paths.– Right sub-tree in (a) has solutions. Its size varies (8% to 24% of the tree).– (b): left has no A2 or A3, middle has no A4 or A5, right has no A6 or A7.

Page 74: Structural joins on XML documents

BibliographyBibliography Shu-Yao Chien, Zografoula Vagena, Donghui Zhang, Vassilis J. Tsotras, Carlo

Zaniolo, “Efficient Structural Joins on Indexed XML Documents” Proc.of VLDB 2002

Shurug Al-Khalifa, H. V. Jagadish, Nick Koudas, Jingesh M. Patel, Divesh Srivastava, Yuqing Wu, “Structural Joins: A Primitive for Efficient XML Query Pattern Matching”, ICDE 2002

Nicolas Bruno, Nick Koudas, Divesh Srivastava, “Holistic Twig Joins: Optimal XML Pattern Matching”, ACM SIGMOD 2002

Shu-Yao Chien, Vassilis J. Tsotras, Carlo Zaniolo, Donghui Zhang, “Efficient Complex Query Support for Multiversion XML Documents”, Proc. of VLDB 2001

Jason McHugh, Jennifer Widom, “Query Optimization for XML”, Proc. of VLDB 1999

Chun Zhang, Jeffrey Naughton, David DeWitt, Qiong Luo, Guy Lohman, “On Supporting Containment Queries in Relational Database Management Systems”, ACM SIGMOD 2001

Quanzhong Li, Bongki Moon, “Indexing and Querying XML Data for Regular Path Expressions”, Proc. of VLDB 2001

IBM DB2 web site: http://www-3.ibm.com/software/data/db2/

www.w3.org site (on XPath and XQuery)

Page 75: Structural joins on XML documents