29
TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs – Research Univ. of Michigan Work supported by NSF and NSERC.

TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Embed Size (px)

Citation preview

Page 1: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

TAX: A Tree Algebra for XML

H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia

Divesh Srivastava Keith Thompson AT&T Labs – Research Univ. of Michigan

Work supported by NSF and NSERC.

Page 2: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Overview

Why an algebra for XML? Main challenges Data model Patterns & Witnesses Tree Value Functions Some Example Operators Translation Example – XQuery

Page 3: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Overview (contd.)

Main Results Optimization Examples Implementation Summary & Future Work

Page 4: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Why an Algebra (for XML)? (aka Related Work)

Bulk algebra for tree manipulation – efficient implementation of XML queries

Algebra for manipulating trees (has been attempted before) Feature algebras – linguistics; efficient

implementation? Grammar-based algebra for trees [Tompa+ 87,

Gyssens+ 89] Aqua project [Zdonik+95]

Page 5: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Why XML algebra? [Related work] (contd.)

GraphLog, Hy+ [Consens+90], GOOD [Paradaens+92] – cannot exploit special properties of trees (e.g., support for arbitrary recursion vs. ancestors, order)

SS data – Lorel [Abiteboul+ 96], UnQL [Buneman+ 96].

XML algebras – [Beech+ 99], [Fernandez+ 00] (mainly type system issues), [Christofidis+ 00] (trees tuples), [Ludascher+ 00] (nodes, not trees), SAL [Beeri+ 99] (ordered lists of nodes)

Page 6: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Why? (contd.)

be close to relational model, but direct support for (collections of) trees express at least RA + aggregation capture substantial fragment of XQuery admit efficient implementation and

effective query optimization

Page 7: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Main Chellanges

Capture rich variety of manipulations in a simple algebra

Handle heterogeneity in tree collections structure “schema” of nodes of the same “type”

Handle order (documents are ordered) sometimes important (e.g., author list) sometimes not (e.g., publisher vs. authors)

Page 8: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Data Model Data tree = rooted ordered tree Data in node = set of attr-val pairs Special attribute: pedigree – where did I

come from? “doc id + offset in doc”. preserved for (copies of) original nodes thru

manipulations. play important role in grouping, sorting, etc. null for new nodes.

Collections (of trees) – unordered.

Page 9: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Patterns & Witnesses

first challenge: how do you get at nodes and/or attributes?

our solution: patterns – enable specification of parameters for most operations

only show parts of interest: Need not know/care about entire structure of

trees in collection

Page 10: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Patterns & Witnesses (contd.)

Example P1:$1

$2 $3

pc ad

$1.tag = book & $2.tag = year & $2.content < 2000 & $3.tag = author

Structural part

Condition partAdditional parameters possible: e.g., selection/projection lists, grouping, ordering, etc.

pc = directad = transitive

Page 11: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Patterns & Witnesses (contd.) What does a pattern do for you?

generate witnesses against i/p collection one for each matching of pattern against i/p conditions must be respected (sub)structure preserved in o/p

e.g., witness trees for pattern P1 – one tree for each author of each book published

before 2000, showing year & author book-author link may be transitive in i/p but is

necessarily direct in o/p source trees = trees witnesses “came from”

Page 12: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Tree Value Functions (TVF)

What are they? Primitive recursive functions on structure of source

trees Where are they used?

grouping, ordering, aggregation, etc. Here is an example:

f: T value of author, number of authors, tuple of authors, {author tuple, title}, etc.

Complete example coming up …

Page 13: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Example Database

bib

book book

author author

name

first lastmid

deg degname

titletitleyear

first last

1910PrincipiaMathematica

Alfred North Whitehead Bertrand Russel

Sc.D., FRS

M.A., FRS

author

name

Panini

Ashtadhyayi(First book on Sanskrit Grammar)

year

560 BC

Page 14: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Example Operators – Selection Input: collection; parameters: pattern, selection

list (pattern nodes) Example

pattern P1 and empty SL: same witness trees as before

pattern P1 with SL = {$1}: whole book subtrees (i.e. retain $1’s descendants)

One-zero/more op in general Could retain other “relatives” instead (e.g.,

siblings)

Page 15: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Selection with P1 (empty SL)

book book

authoryear

1910

authoryear

560 BC

book

year author

Whole author subtree included when SL = {$3}.

1910

Page 16: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Example operators – Projection Input: collection; parameters: pattern, projection

list Example

Pattern P1 w/ PL = {$1, $2, $3}: one tree for each book published before 2000, showing year and author(s)

Pattern P1 w/ PL = {$3}: one tree for each author of aforementioned books

`*’ in PL causes descendants to be retained One-zero/more op (for reasons diff. from select)

Page 17: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Projection: P1 w/ PL = {$1,$2,$3}

book book

author authoryear

1910

authoryear

560 BC

With $3*, can include whole author subtrees.

Page 18: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Selection vs. Projection Example

FOR $b IN document(“doc.xml”)//book FOR $y IN $b/year[data() < 2000]

FOR $a IN $b//author RETURN

<book> $y $a</book>

versus FOR $b IN document(“doc.xml”)//book[/year/data() < 2000]

RETURN <book> $b/year $b/author

</book>

selection

projection

Page 19: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Example operators – grouping Input: collection; parameters: pattern,

grouping TVF, ordering TVF. Example

input: collection of books

pattern: $1

$2 $3

$4$1.tag = book & $2.tag = title & $3.tag = author & $4.tag = name

f_g(T) = “$4.content”f_o(T) = “$2.content”pc ad

pc

Page 20: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Grouping (contd.)

Here is what the o/p looks like:

-- books ordered by title in each group

…tax_group_root

tax_group_basis tax_group_subroot

authorbook book

Page 21: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Other operators

Derived operators – various joins. Set operations:

When are two data trees the “same”? Equality (shallow/deep) vs. isomorphism

(include pedigree or not?) Multiset versions of operators

Aggregation, Reordering, Renaming.

Page 22: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Translation Examples – XQuery

FOR $b IN

document(“doc.xml)//book[//author@hobby=tennis] RETURN <sportydiveshbook>

$b/title IF SOME $a IN $b//author SATISFIES $a/data() = “divesh” THEN $b/author

</sportydiveshbook>

Page 23: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

XQuery Translation (contd.)

Pre-IF part E: select w/

then project w/

$1

$2

$1.tag=book & $2.tag=author & $2.hobby=tennisSL = $1*

$3

$4$3.tag=book & $4.tag=titlePL = $3, $4

$3

$4$3.tag=book & $4.tag=titlePL = $3, $4

Page 24: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

XQuery Translation (contd.)

IF part F: select w/

then project w/

$5

$6$5.tag=book & $6.tag=author & $6.content = divesh

SL = $5*

$7

$8$7.tag=book & $8.tag=author PL = $7, $8

Page 25: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

XQuery Translation (contd.)

Do a left outerjoin of E with F w/ the condition $3 = $7

Project w/

Rename tax_prod_root sportydiveshbook.

tax_prod_root

/ \

book book . . .

| / ... \

title author author

PL = $9 $9.tag != book$9

Page 26: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Main Results

Duplicate elimination by value can be expressed in TAX.

The operators in TAX are independent. TAX is complete for relational algebra w/

aggregation. TAX can capture the fragment of XQuery FLWR

expressions w/o function calls, recursion, w/ all path expressions using only constants, wildcards, and / & //, when no new ancestor-descendant relationships are created.

Page 27: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Optimization Examples

Revisit translation example: E can be simplified to – project w/

Similar simplification applies to F

Self-join can sometimes be eliminated Associativity, commutativity issues

$1

$2 $3$1.tag=book & $2.tag=author & $2.hobby=tennis & $3.tag=title

PL= $1,$3

Page 28: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Implementation

TIMBER system at Univ. of Michigan Find pattern tree matches via

Index scans Full scans Twig joins

Joins implemented on streams Pedigree – implemented as position of

element within document Pedigrees similar to RID at impl. level

Page 29: TAX: A Tree Algebra for XML H.V. Jagadish Laks V.S. Lakshmanan Univ. of Michigan Univ. of British Columbia Divesh Srivastava Keith Thompson AT&T Labs –

Summary & Future Work TAX – extension of RA for handling

heterogeneous collections of ordered labeled trees

Simplicity; few more operators Recognize selective importance of order and

handle elegantly Bulk algebra for efficient implementation of XML

querying Stay tuned for TIMBER release(s) Future

Arbitrary restructuring: copy-and-paste Updates: principled via operators