xquery with user-defined functions

22
XQuery with User-defined Functions David Bednárek [email protected] ulita.ms.mff.cuni.cz/~bednarek Department of Software Engineering Faculty of Mathematics and Physics Charles University Prague

Upload: nia

Post on 29-Jan-2016

66 views

Category:

Documents


0 download

DESCRIPTION

XQuery with User-defined Functions. David Bedn árek [email protected] ulita.ms.mff.cuni.cz/~bednarek Department of Software Engineering Faculty of Mathematics and Physics Charles University Prague. XQuery program with user-defined functions. declare function local:toc($P) { - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: XQuery with User-defined Functions

XQuery with User-defined Functions

David Bednárek

[email protected]/~bednarek

Department of Software EngineeringFaculty of Mathematics and Physics

Charles University Prague

Page 2: XQuery with User-defined Functions

XQuery program with user-defined functions

declare function local:toc($P) { for $X in $P/section return <section> { $X/@* , $X/title , local:toc($X) } </section>};

<toc> { for $S in $I/book return local:toc($S)} </toc>

Page 3: XQuery with User-defined Functions

XQuery with user-defined functions

Turing-complete language Identification of patterns of "strong" computation

Relational algebra representation Identifier handling

Bulk-evaluation R-programs

Temporary structures Static analysis

Generation of the output document Reversed evaluation

Page 4: XQuery with User-defined Functions

Turing-completeness of XQuery

Identification of patterns of "strong" computation

Page 5: XQuery with User-defined Functions

The simplest XQuery application

XML document tree

1 23

4

A

B

C

D

XQuery evaluation tree

Page 6: XQuery with User-defined Functions

The simplest XQuery application

Cartesian product

1 23

4

A

B

C

D

Page 7: XQuery with User-defined Functions

The simplest XQuery application

Two-dimensional attribute grammar Dependence analysis

Page 8: XQuery with User-defined Functions

The simplest XQuery application

Turing-strong patterns Mesh Tape

Page 9: XQuery with User-defined Functions

Relational algebra representation

Identifier handling

Page 10: XQuery with User-defined Functions

Example – input document and its Dewey encoding

section

9

8

book

sectiontitle title

7 4

title

7

section

5

@id

6

/

1

p

8

p

9

section

((1)(1.9))

(3(1.5.8))

toc

sectiontitle title

(2(1.5.7)) (2(1.9.4))

title

(2(1.5.8.9))

section

((1)(1.5))

@id

(1(1.5.8.6))

/

()

/1 book1.5 section1.5.7 title1.5.8 section1.5.8.6 @id1.5.8.7 title1.5.8.9 p1.9 section1.9.4 title1.9.8 p

Page 11: XQuery with User-defined Functions

XQuery program and its effect on encoded documents

/1 book1.5 section1.5.7 title1.5.8 section1.5.8.6 @id1.5.8.7 title1.5.8.9 p1.9 section1.9.4 title1.9.8 p

/

() toc

()((1)(1.5)) section

()((1)(1.5))(2(1.5.7)) title

()((1)(1.5))(3(1.5.8)) section

()((1)(1.5))(2(1.5.7))(1(1.5.8.6)) @id

()((1)(1.5))(2(1.5.7))(2(1.5.8.9)) title

()((1)(1.9)) section

()((1)(1.9))(2(1.9.4)) title

declare function local:toc($P) { for $X in $P/section return <section> { $X/@* , $X/title , local:toc($X) } </section>};

<toc> { for $S in $I/book return local:toc($S)} </toc>

Page 12: XQuery with User-defined Functions

Example – decoded output document

section

9

8

book

sectiontitle title

7 4

title

7

section

5

@id

6

/

1

p

8

p

9

section

((1)(1.9))

(3(1.5.8))

toc

sectiontitle title

(2(1.5.7)) (2(1.9.4))

title

(2(1.5.8.9))

section

((1)(1.5))

@id

(1(1.5.8.6))

/

()

/() toc()((1)(1.5)) section()((1)(1.5)) (2(1.5.7)) title()((1)(1.5)) (3(1.5.8)) section()((1)(1.5)) (2(1.5.7))(1(1.5.8.6)) @id()((1)(1.5)) (2(1.5.7))(2(1.5.8.9)) title()((1)(1.9)) section()((1)(1.9)) (2(1.9.4)) title

Page 13: XQuery with User-defined Functions

Life cycle of identifiers

Page 14: XQuery with User-defined Functions

Bulk-evaluation

R-programs

Page 15: XQuery with User-defined Functions

R-programs

Handling recursion by expansion Bulk-evaluation by relational algebra

R-program

pipelinedinterpreter

expanderexpandedR-program triggers

dynamicrewriting

XMLDB

XMLDB

physicalR-program

global planselection

statistics

Page 16: XQuery with User-defined Functions

R-programs

DAG of relational algebra operators

Gradual expansion driven by triggers

trigger(t 1t2t2)

empty

trigger(t 1t2)

empty

m

initial(main)

final(main)

m

initial(main)

final(main)

trigger(t 1)

empty

m

initial(main)

final(main)

Page 17: XQuery with User-defined Functions

Temporary structures

Static analysis

Published in: "Reducing Temporary Trees in XQuery" ADBIS 2008, Pori, Finland, LNCS

Page 18: XQuery with User-defined Functions

Static analysis algorithm

Input: a XQuery program Output: a set of modes assigned to each sub-

expression and each variable Mode determines a particular way of

representation required Reversed evaluation is one of the modes

Time O(n2), space O(n)

Page 19: XQuery with User-defined Functions

Generation of the output document

Reversed evaluation

Published in: "Output-driven evaluation of XQuery" IDC 2008, Catania, Italy, Springer Verlag

Page 20: XQuery with User-defined Functions

Standard data flow

<section>

for $X

returnin

$P/section

toc($X)

,

$X/@*

function toc($P)

$X/title

<toc>

for $S

in

$I/book

toc($S)

$P$I

$S

$X

$P

return

main

$P

declare function local:toc($P) { for $X in $P/section return <section> { $X/@* , $X/title , local:toc($X) } </section>};

<toc> { for $S in $I/book return local:toc($S)} </toc>

Page 21: XQuery with User-defined Functions

Reversed data flow

<section>

for $X

returnin

$P/section

toc($X)

,

$X/@*

function toc($P)

$X/title

<toc>

for $S

in

$I/book

toc($S)

$P$I

$S

$X

$P

return

main

$P

Page 22: XQuery with User-defined Functions

Future work

Cost-based optimization in R-programs

Distributed/parallel XQuery engine