xquery with user-defined functions david bednárek david.bednarek@mff.cuni.cz...

Post on 31-Dec-2015

215 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

XQuery with User-defined Functions

David Bednárek

david.bednarek@mff.cuni.czulita.ms.mff.cuni.cz/~bednarek

Department of Software EngineeringFaculty of Mathematics and Physics

Charles University Prague

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>

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

Turing-completeness of XQuery

Identification of patterns of "strong" computation

The simplest XQuery application

XML document tree

1 23

4

A

B

C

D

XQuery evaluation tree

The simplest XQuery application

Cartesian product

1 23

4

A

B

C

D

The simplest XQuery application

Two-dimensional attribute grammar Dependence analysis

The simplest XQuery application

Turing-strong patterns Mesh Tape

Relational algebra representation

Identifier handling

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

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>

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

Life cycle of identifiers

Bulk-evaluation

R-programs

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

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)

Temporary structures

Static analysis

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

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)

Generation of the output document

Reversed evaluation

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

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>

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

Future work

Cost-based optimization in R-programs

Distributed/parallel XQuery engine

top related