Introduction To XML Algebra Wan Liu Bintou Kane
Introduction To XML Algebra Wan Liu Bintou Kane Advanced Database Instructor: Elka 1 2/11/2002 1
Outline Reasons for XML algebra n Niagara algebra n AT&T Algebra n 2
Data Model and Design n We need a clear framework to design a database A data model is like creating different data structures for appropriate programming usage. It is a type system, it is abstract. Relational database is implemented by tables, XML format is a new one method for information integration. 3
Why XML Algebra? It is common to translate a query language into the algebra. n First, the algebra is used to give a semantics for the query language. n Second, the algebra is used to support query optimization. n 4
XML Algebra History Lore Algebra (August 1999) -- Stanford University IBM Algebra (September 1999) --Oracle; IBM; Microsoft Corp YAT Algebra (May 2000) AT&T Algebra (June 2000) --AT&T; Bell Labs Niagara Algebra (2001) -- University of Wisconsin -Madison 5
NIAGARA n Title : Following the paths of XML Data: An algebraic framework for XML query evaluation By : Leonidas Galanis, Efstratios Viglas, David J. De. Witt, Jeffrey. F. Naughton, and David Maier. 6
Out. Line n Concepts of Niagara Algebra n Operations n Optimization 7
Goals of Niagara Algebra Be independent of schema information n Query on both structure and content n Generate simple, flexible, yet powerful algebraic expressions n Allow re-use of traditional optimization techniques n 8
Example: XML Source Documents Invoice. xml Customer. xml <Invoice_Document> <invoice No = 1> <account_number>2 </account_number> <Customer_Document> <customer> <carrier>AT&T</carrier> <account>1 </account> <total>$0. 25</total> <name>Tom </name> </invoice> </customer > <customer> <account_number>1 </account_number> <account>2 </account> <carrier>Sprint</carrier> <name>George </name> <total>$1. 20</total> </invoice> </customer > </Customer _Document> <invoice> <account_number>1 </account_number> <carrier>AT&T</carrier> <total>$0. 75</total> </invoice> </Invoice_Document> 9
XML Data Model and Tree Graph Example: Invoice_Document Invoice number 2 Invoice … carrier total number total carrier <Invoice_Document> <invoice> <number>2</number> <carrier>Sprint</carrier> <total>$0. 25</total> </invoice> Ordered Tree Graph, <invoice> <number>1</number> <carrier>Sprint</carrier> <total>$1. 20</total> </invoice> Semi structured Data </Invoice_Document> AT&T $0. 25 1 Sprint $1. 20 10
XML Data Model [GVDNM 01] Collection of bags of vertices. n Vertices in a bag have no order. n Example: n Root invoice. xml invoice <invoice> Invoice-element-content </invoice> invoice. account_number < account_number > element-content </ account_number > [Root“invoice. xml”, invoice. account_number ] 11
Data Model Bag elements are reachable by path expressions. n The path expression consists of two parts : n An entry point n A relative forward part n n Example: account_number: invoice 12
Operators n Source S , Follow , Select , Join , Rename , Expose , Vertex , Group , Union , Intersection , Difference - , Cartesian Product . 13
Source Operator S n n n Input : a list of documents Output : a collection of singleton bags Examples : S (*) All Known XML documents S (invoice*. xml) All XML documents whose filename matches “invoice*. xml S (*, schema. dtd) All known XML documents that conform to schema. dtd 14
Follow operator Input : a path expression in entry point notation n Functionality : extracts vertices reachable by path expression n Output : a new bag that consist of the extracted vertex + all the contents of the original bag (in care of n unnesting follow) 15
Follow operator (Example*) {[Root invoice. xml , invoice, invoice. carrier]} invoice. xml invoice. carrier <carrier> carrier -element-content </carrier > <invoice> Invoice-element-content </invoice> (carrier: invoice) Root *Unnesting Follow invoice. xml <invoice> Invoice-element-content </invoice> {[Root invoice. xml , invoice]} 16
Select operator Input : a set of bags n Functionality : filters the bags of a collection using a predicate n Output : a set of bags that conform to the predicate n Predicate : Logical operator ( , , ), or n simple qualifications ( , , , ) 17
Select operator (Example) {[Root invoice. xml , invoice. xml invoice], … } invoice <invoice> Invoice-element-content </invoice> invoice. carrier =Sprint Root invoice. xml invoice Root <invoice> Invoice-element-content </invoice> {[Root invoice. xml , invoice], [Root invoice. xml invoice <invoice> Invoice-element-content </invoice> invoice. xml , invoice], ……………} 18
Join operator Input: two collections of bags n Functionality: Joins the two collections based on a predicate n Output: the concatenation of pairs of pages that satisfy the predicate n 19
Join operator (Example) {[Root invoice. xml , invoice, Root invoice. xml Root customer. xml , customer]} customer. xml <invoice> Invoice-element-content </invoice> <customer> customer-element-content </customer> account_number: invoice =number: customer Root invoice. xml invoice Root customer. xml <invoice> Invoice-element-content </invoice> {[Root invoice. xml , invoice]} customer <customer> customer-element-content </customer> {[Root customer. xml , customer]} 20
Expose operator Input: a list of path expressions of vertices to be exposed n Output: a set of bags that contains vertices in the parameter list with the same order n 21
Expose operator (Example) {[Root invoice. xml , invoice. bill_period, invoice. carrier]} invoice. bill_period <carrier> bill_period -element-content </carrier > invoice. carrier <invoice> carrier-element-content </invoice> (bill_period, carrier) Root invoice. xml invoice. carrier <invoice> Invoice-element-content </invoice> {[Root invoice. xml , <invoice> carrier-element-content </invoice> invoice. bill_period <carrier> bill_period -element-content </carrier > invoice, invoice. carrier, invoice. bill_period]} 22
Vertex operator Creates the actual XML vertex that will encompass everything created by an expose operator n Example : n (Customer_invoice)[ ( (account)[invoice. account_number], (inv_total)[invoice. total])] 23
Other operators n Group : is used for arbitrary grouping of elements based on their values n n Aggregate functions can be used with the group operator (i. e. average) Rename : Changes the entry point annotation of the elements of a bag. n Example: (invoice. bill_period, date) 24
Example: XML Source Documents Invoice. xml Customer. xml <Invoice_Document> <invoice> <account_number>2 </account_number> <Customer_Document> <customer> <carrier>AT&T</carrier> <account>1 </account> <total>$0. 25</total> <name>Tom </name> </invoice> </customer > <customer> <account_number>1 </account_number> <account>2 </account> <carrier>Sprint</carrier> <name>George </name> <total>$1. 20</total> </invoice> </customer > </Customer _Document> <invoice> <account_number>1 </account_number> <total>$0. 75</total> </invoice> <auditor> maria </auditor> </Invoice_Document> 25
Xquery Example List account number, customer name, and invoice total for all invoices that has carrier = “Sprint”. FOR $i in (invoices. xml)//invoice, $c in (customers. xml)//customer WHERE $i/carrier = “Sprint” and $i/account_number= $c/account RETURN <Sprint_invoices> $i/account_number, $c/name, $i/total </Sprint_invoices> 26
Example: Xquery output <Sprint_Invoice> <account_number>1 </account_number> <name>Tom </name> <total>$1. 20</total> </Sprint_Invoice > 27
Algebra Tree Execution Account_number name total Expose (*. account_number , *. name, *. total ) invoice(2) customer(1) Join (*. invoice. account_number=*. customer. account) invoice (2) Select (carrier= “Sprint” ) Invoice (1) invoice (2) invoice (3) Follow (*. invoice) Source (Invoices. xml) customer(1) customer (2) Follow (*. customer) Source (cutomers. xml) 28
Optimization with Niagara Optimizer based on the Niagara algebra n Use the operation more efficiently n Produce simpler expression by combining operations 29
Language Convention A and B are path expressions n A< B -- Path Expression A is prefix of B n An. B --- Common prefix of path A and B n AńB --- Greatest common of path A and B n┴ --- Null path Expression n 30
Use of Rule 8. 5 Make profit of rule 8. 5 Allows optimization based on path selectivity When applying un-nesting follow operation Φμ 31
Φμ(A) [Φμ(B)]=Φμ (B)[Φμ (A)] True When Exist C / C <A && C < B C = AńB Or An. B = ┴ Interchangeability of Follow operation 32
Application of 8. 5 With Invoice Φμ(acc_Num: invoice)[Φμ(carrier: invoice)] * ? = Φμ(carrier: invoice)[Φμ(acc_Num: invoice)] ** Both Share the common prefix invoice Case AńB = invoice 33
Benefit of Rule Application Note if: acc_Num required for each invoice Element carrier is not required for invoice Element Then using * Φμ(acc_Num: invoice)[Φμ(acc_Num: customer)] make more sense than ** Why? 34
Reduction of Input Size on the first Sub-operation Φμ(carrier: invoice) Should we or can we apply the 8. 5 below? Φμ(acc_Num: invoice)[Φμ(acc_Num: Customer)] Why? 35
acc_Num: invoice and acc_Num: Customer are totally different path Case is: An. B = ┴ Then yes 36
Rule 8. 7 , 8. 9 , 8. 11 Interesting Helps identify When and where to use selection to decrease size of input operation to subsequent operation Example Algebra tree slide 28 Selected before join. 37
Addition would be Give computation for finding when rule can be applied automatically in a case and then apply it. 38
AT&T Algebra 39
40
AT&T Algebra Introduction n The algebra is derived from the nested relational algebra. AT&T algebra makes heavy use of list comprehensions, a standard notation in the function programming community. AT&T algebra uses the functional programming language Haskell as a notation from presenting the algebra. 41
AT&T data model The data model merges attribute and element nodes, and eliminates comments. n Declare Basic Type: Node. Text : : String ->node elem : : Tag -> [Node] ->node ref : : Node ->Node n elem “bib” [ <bib> elem “book”[ <book year=“ 1999”> <title> Data on the Web</title> <year> 1999</year> </book> </bib> elem “@year” [ text “ 1999” ], elem “title” web” ] ]] [text “Data on the 42
Basic Type Declarations n n To find the type of a node, is. Text : : Node -> Bool is. Elem : : Node -> Bool is. Ref : : Node -> Bool For a text node, string : : Node -> String For an element node, 1)tag : : Node -> Tag 2)children : : Node -> [Node] For a reference node, dereference : : Node -> Node 43
Nested relational algebra… n n In the nested relational approach, data is composed of tuples and lists. Tuple values and tuple types are written in round brackets. (1999, "Data on the. Web", ["Abiteboul"]) : : (Int, String, [String]) Decompose values: year : : (Int, String, [String]) year (x, y, l) = x 44
Nested relational algebra… n n n Comprehensions: List comprehensions can be used to express fundamental query operations, navigation, cartesian product, nesting, joins. Example: [ value x | x <- children book 0, is "author" x ] ==> [ "Abiteboul" ] Normal expression: [ exp | qual 1, . . . , qualn ] bool-exp pat <- list-exp 45
Nested relational algebra… n Using comprehensions to write queries. Navigate follow : : Tag -> Node -> [Node] follow t x = [ y | y <- children x, is t y ] Cartesian product [ (value y, value z) | x <- follow "book" bib 0, y <- follow "title" x, z <- follow "author" x ] ==> [ ("Data on the Web", "Abiteboul")] 46
Nested relational algebra… Joins. elem "reviews" [ n elem "reviews" [ elem "book" [ elem "title" [ text"Data on the Web" ], elem "review" [ text "This is great!" ]] [ (value y, int (value z), value w) | x <- follow "book" bib 0, y <- follow "title" x, z <- follow "@year" x, u <- follow "book" reviews 0, elem “bib” [ v <- follow "title" u, elem “book”[ w <- follow “@year" u, elem “@year” [ text “ 1999” ], elem “title” [text “Data on the web” ] ]] y == v ] ==> [("Data on the Web", 1999, "This is great!")] 47
Nested relational algebra… n Regular expression matching ( [ (x, y, u) | x <- item "@year", y <- item "title", u <- rep (item "author") ] ) : : Reg (Node, [Node] ) Match : : Reg a -> Node-> [a] Result match reg 0 book 0 ==> [(elem "@year" [text "1999"], elem "title" [text "Data on the Web"], [elem "author" [text "Abiteboul"], elem "author" [text "Buneman"], elem "author" [text "Suciu"] ] ) ] 48
Nested relational algebra… n Sorting. sort. By : : (a -> Bool) -> [a] sort. By (<=) [3, 1, 2, 1] ==> [1, 1, 2, 3] n Grouping group. By : : (a -> Bool) -> [a] -> [[a]] group. By (==) [3, 1, 2, 1] == [[2], [1, 1], [3]] 49
Cross Comparisons of Algebra Niagara and AT&T standalone XML algebras Niagara proposed after W 3 C had selected proposed standard and has operators which operate on sets of bags At&T algebra chosen as proposed standard by W 3 C -- expressions resemble high level query language -- latest version of document referred to as “Semantics of XML Query Language XQuery” 50
Future Work Need more different evaluation strategies which would allow for flexible query plans Develop physical operators that take advantage of physical storage structures and generate mapping from query tree to a physical query plan 51
- Slides: 51