160 likes | 351 Views
XML Algebra. By Sailaja P. KReSIT IIT Bombay. Algebra and the World of DB. Why Algebra Gives semantics for a query language For efficient query processing Few algebrae Relational Algebra: For relational data Nested Relational Algebra: For nested relational model
E N D
XML Algebra By Sailaja P. KReSIT IIT Bombay
Algebra and the World of DB • Why Algebra • Gives semantics for a query language • For efficient query processing • Few algebrae • Relational Algebra: For relational data • Nested Relational Algebra: For nested relational model • Schema Algebra: For MultiDB interoperability Sailaja P., KReSIT XML Workshop, IITBombay
Why Algebra for XML • Structure of data • Deeply structured • Exact structure not specific • Recursion • Structurally recursive Sailaja P., KReSIT XML Workshop, IITBombay
XML Algebra • Sample Data <bib> <book> <title>Data on the Web</title> <year>1999</year> <author>Abiteboul</author> <author>Buneman</author> </book> <book> <title> XML Query</title> <year>2000</year> <author>Mary</author> </book> </bib> Sailaja P., KReSIT XML Workshop, IITBombay
XML Algebra type Bib = bib [ Book{0,*}] type Book = book [ title [String ], year [Integer], author[ String]{1,*} ] let bib0: Bib = bib [ book [ title [“Data on the Web”], year [1999], author[“Abiteboul”], author[“Buneman”] ] book[ title[“XML Query”],year[2000], author[“Mary”] ] ] Sailaja P., KReSIT XML Workshop, IITBombay
Projection Eg:project book( children (bib0) ) • Allows a more convenient notation as well (similar to Xpath notation) • Eg. bib0/book/author ==> author [“Abiteboul”] author [“Buneman”] author [“Mary”] :author [ String ] {0,*} Sailaja P., KReSIT XML Workshop, IITBombay
Projection Provides for an iterator • bib0/book/author • Equivalent : for b project book(children(bib0)) inproject author(children(b)) Sailaja P., KReSIT XML Workshop, IITBombay
Selection Eg: for b bib0/book in where value(b/year) <= 2000 then b ==> book [ title [ “Data on the web”], year [“1999”], author[“Abiteboul”], author[“Buneman”] ] : Book{0,*} Sailaja P., KReSIT XML Workshop, IITBombay
Join type Reviews = reviews [ book [ title [String], review [ String] ]{0,*} ] let review0: Reviews = reviews[ book [ title[“XMLQuery”], review[“A fine book”] ], book [ title[“Data on Web”], review[“This is great”] ] ] Sailaja P., KReSIT XML Workshop, IITBombay
Join • Expression for b bib0/book in for r review0/book in where value(b/title) = value(r/title) then book [ b/title, b/author, r/review] ==> book [ title [“Data on the web”], author[“Abiteboul”], author[“Buneman”] review[“A fine book”] ], Sailaja P., KReSIT XML Workshop, IITBombay
Join book[ title[“XML Query”], author[“Mary”], review[“This is great”] ] : book[ title[String ], author[String]{1,*}, review[String] ]{0,*} Sailaja P., KReSIT XML Workshop, IITBombay
Querying Order • Index function pairs an integer index with each element in a forest • Eg: index(book0/author) ==> pair[fst[1],snd[author[“Abiteboul”]]], pair[fst[2],snd [author[“Buneman”]]], pair[fst[3],snd [author[“Suciu”]]] :pair[fst[Integer],snd[author[String]]]{1,*} Sailaja P., KReSIT XML Workshop, IITBombay
Aggregation • Has five built-in aggregation functions: avg,count, max, min and sum • Eg: for b bib0/book in where count(b/author) >= 2 then b/title ==> title[“Data on the web”] : title{0,*} Sailaja P., KReSIT XML Workshop, IITBombay
Additional Features • Structural Recursion • To define documents with recursive structure, recursive types are used • Sorting • sort(pairs) • Grouping • Group(pairs) Sailaja P., KReSIT XML Workshop, IITBombay
Conclusions • Important contributions • Operators are orthogonal, strongly typed • Operators do obey laws of equivalence and optimization • Issues to be resolved • Querying over global order is not defined • Equality and relational operators on element and scalar types are not defined. Sailaja P., KReSIT XML Workshop, IITBombay
Resources • http://www.cs.bell-labs.com/~wadler/topics/xml.html#algebra • For an implementation of the algebra: http://www-db.research.bell-labs.com/user/simeon/xa.html • http://www.w3.org/TR/query-datamodel • This presentation will be put up: • http://www.it.iitb.ernet.in/~sailu/Algebra.html Sailaja P., KReSIT XML Workshop, IITBombay