lecture 14: database theory in xml processing
DESCRIPTION
Lecture 14: Database Theory in XML Processing. Thursday, February 15, 2001. Outline. Skolem Functions XML Publishing. Skolem Functions. In Logic Vocabulary: R 1 , …, R k , g 1 , …, g p Recall that Mathematical Logic talks about relations R 1 , …, R k and functions g 1 , …, g p - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/1.jpg)
Lecture 14: Database Theory in XML Processing
Thursday, February 15, 2001
![Page 2: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/2.jpg)
Outline
• Skolem Functions
• XML Publishing
![Page 3: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/3.jpg)
Skolem Functions
In Logic
• Vocabulary: R1, …, Rk, g1, …, gp
– Recall that Mathematical Logic talks about relations R1, …, Rk and functions g1, …, gp
• The problem: given a formula , decide whether it is satisfiable: true in some model D = (D, R1, …, Rk, g1, …, gp)
![Page 4: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/4.jpg)
Skolem Functions
• Write in prenex normal form:
• Replace existential quantifiers with Skolem functions (next)
)y,y,y,y ;x,x,(x.yyxyxxy 43213214332211
![Page 5: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/5.jpg)
Skolem Functions
• Becomes:
• Then delete universal quantifiers:
))x,x,x,(xf ),x,x,(xf ),x,(xf (),f ;x,x,(x.xxx 4321432132121321321
)y,y,y,y ;x,x,(x.yyxyxxy 43213214332211
))x,x,x,(xf ),x,x,(xf ),x,(xf (),f ;x,x,(x ' 4321432132121321
![Page 6: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/6.jpg)
Skolem Functions
In Logic
Theorem is satisfiable iff ’ is satisfiable.
true in some model:– D = (D, R1, …, Rk, g1, …, gp)
• iff ’ true in some model:– D’ = (D, R1, …, Rk, g1, …, gp, f1, f2, f3, f4)
![Page 7: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/7.jpg)
Skolem Functions in Databases
Author(aid, name, email), Paper(pid, title, year), AP(aid, pid)
• Want to construct Webpages declaratively– WebPage(wid) - all webpage id’s
– Text(wid, value) - some text associated to web pages
![Page 8: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/8.jpg)
Skolem Functions in Databases
root
author1 author2 author3
1985 1992 1992 1972 1985 1999
John Fred Josh
John’s papers from 1985 Fred’s papers from 1992
A great Website, with papers grouped by year !
![Page 9: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/9.jpg)
Skolem Functions in Databases
Author(aid, name, email), Paper(pid, title, year), AP(aid, pid)
WebPage(Root()) :-
WebPage(Author(aid)) :- Author(aid, _, _)
Text(Author(aid), name)) :- Author(aid, name, _)
WebPage(Year(aid,year)) :- Author(aid, _, _), AP(aid, pid), Paper(pid, _, year)
WebPage(Paper(aid, pid, year)) :- ……
• Author(aid) “means”: create a new object, for each value of aid
• Year(aid,year) “means”: create a new object, for each value of aid and year
![Page 10: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/10.jpg)
Skolem Functions in Databases
• A closer look:Text(Y, name)) :- Author(aid, name, _)
• Unsafe, because of Y
z))name,,Author(aidname)Y.(Text(Y,z.name.aid.
![Page 11: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/11.jpg)
Skolem Functions in Databases
• But let us change the rules of the game:– “all variables in the head that don’t occur in the
body are existentially quantified (not universally)”
• Becomes equivalent to a Skolem function:Text(f(aid, name, z), name) :- Author(aid, name, z)
z))name,,Author(aidname)Y.(Text(Y,z.name.aid.
![Page 12: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/12.jpg)
Skolem Functions in Databases
• f’s arguments depend on the order in which we write the quantifiers
• Becomes:Text(f(name), name) :- Author(aid, name, z)
• Idea in databases: write the Skolem functions and their arguments explicitly: Text(author(aid), name) :- Author(aid, name, z)
• Makes possible object fusion, when we reuse the Skolem function
z))name,,Author(aidname)z.(Text(Y,aid.Y.name.
![Page 13: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/13.jpg)
Publishing XML Data
• mediator for exporting legacy data to XML
• define XML view declaratively– virtual XML view – materialized XML view
![Page 14: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/14.jpg)
SilkRoute: an Example
Eu-Stores US-Stores
Products
Eu-Sales US-Sales
name country name url
date
date tax
name priceUSD
euSid usSid
pid
Legacy data in E/R:
![Page 15: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/15.jpg)
SilkRoute: an Example• XML view
<allsales> <country> <name> France </name> <store> <name> Nicolas </name> <product> <name> Blanc de Blanc </name> <sold> 10/10/2000 </sold> <sold> 12/10/2000 </sold> … </product> <product>…</product>… </store>…. </country> …</allsales>
• In summary: group by country store product
![Page 16: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/16.jpg)
allsales
country
name store
name product
name sold
date tax
url
PCDATA
PCDATA
PCDATA
PCDATA PCDATA
PCDATA
*
*
*
*
?
?
Output “schema”:
![Page 17: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/17.jpg)
{ FROM EuStores $S, EuSales $L, Products $P WHERE $S.euSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT <allsales()> <country ID=c($S.country)> <name> $S.country </name> <store ID=s($S.euSid)> /* means: s($S.country, $S.euSid) */ <name> $S.name </name> <product ID=p($P.pid)> /* same: add arguments above */ <name> $P.name </name> <price> $P.priceUSD </price> </product> </store> </country> <allsales>} /* union….. */
{ FROM EuStores $S, EuSales $L, Products $P WHERE $S.euSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT <allsales()> <country ID=c($S.country)> <name> $S.country </name> <store ID=s($S.euSid)> /* means: s($S.country, $S.euSid) */ <name> $S.name </name> <product ID=p($P.pid)> /* same: add arguments above */ <name> $P.name </name> <price> $P.priceUSD </price> </product> </store> </country> <allsales>} /* union….. */
SilkRoute Query
![Page 18: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/18.jpg)
…. /* union */{ FROM USStores $S, EuSales $L, Products $P WHERE $S.usSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT <allsales()> <country ID= c(“USA”)> /* object fusion here */ <name> USA </name> <store ID= s($S.euSid)> /* object fusion here */ <name> $S.name </name> <url> $S.url </url> <product ID= p($P.pid)> /* object fusion here */ <name> $P.name </name> <price> $P.priceUSD </price> <tax> $L.tax </tax> </product> </store> </country> <allsales>}
…. /* union */{ FROM USStores $S, EuSales $L, Products $P WHERE $S.usSid = $L.euSid AND $L.pid = $P.pid CONSTRUCT <allsales()> <country ID= c(“USA”)> /* object fusion here */ <name> USA </name> <store ID= s($S.euSid)> /* object fusion here */ <name> $S.name </name> <url> $S.url </url> <product ID= p($P.pid)> /* object fusion here */ <name> $P.name </name> <price> $P.priceUSD </price> <tax> $L.tax </tax> </product> </store> </country> <allsales>}
![Page 19: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/19.jpg)
Notes on the Syntax
• All Skolem functions inherit the arguments of their parent.– Why ?
• Have explicit Skolem functions:CONSTRUCT … <store ID=s($S.euSid)>
CONSTRUCT … <store ID=s($S.euSid)> /* fuse ! */
CONSTRUCT … <store ID=t($S.euSid)> /* don’t fuse ! */
![Page 20: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/20.jpg)
Users Ask XML-QL Queries
• find names, urls of all stores who sold on 1/1/2000
WHERE <allsales/country/store> <product/sold/date> 1/1/2000 </> <name> $X </> <url> $Y </> </>CONSTRUCT <result> <name> $X </> <url> $Y </> </result>
WHERE <allsales/country/store> <product/sold/date> 1/1/2000 </> <name> $X </> <url> $Y </> </>CONSTRUCT <result> <name> $X </> <url> $Y </> </result>
![Page 21: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/21.jpg)
allsales()
country(c)
name(c) store(c,x)
name(n) product(c,x,y)
name(n) sold(c,x,y,d)
date(c,x,y,d) Tax(c,x,y,d,t)
url(c,x,u)
c
n
n
d t
u
XML-QL to SQL (1/4)
country(c) :-EuStores(x,_,c), EuSales(x,y,_), Products(y,_,_)
country(“USA”) :-
store(c,x) :- EuStores(x,_,c), EuSales(x,y,_), Products(y,_,_)
store(c,x) :- USStores(x,_,_), USSales(x,y,_), Products(y,_,_), c=“USA”
url(c,x,u):-USStores(x,_,u), USSales(x,y,_),Products(y,_,_)
allsales():-
Step1: construct the View Tree
Non-recursive Datalog
![Page 22: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/22.jpg)
name(c)
name(n)
Tax(c,x,y,d,t)date(c,x,y,d)
allsales()
country(c)
store(c,x)
name(n) product(c,x,y)
sold(c,x,y,d)
url(c,x,u)
c
n
n
d t
u
XML-QL to SQL (2/4)allsales
country
store
product
sold
date
url
1/1/2000
name
$X $Y
View Tree XML-QL Query Pattern
$n1
$n2
$n3
$n4
$n5
$Z
Step2: “evaluate” the XML-QL pattern(s) on the view tree
![Page 23: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/23.jpg)
XML-QL to SQL (3/4)
• Step 3: for each answer:
– Collect all datalog rules– Rename variables properly– Do query minimization on the result– Obtain…
$n1 $n2 $n3 $n4 $n5 $X $Y $Z
Allsales() Country(c) Store(c,x) Product(c,x,y) Sold(c,x,y,d) n u d
![Page 24: Lecture 14: Database Theory in XML Processing](https://reader031.vdocuments.site/reader031/viewer/2022032414/568132b2550346895d996e2f/html5/thumbnails/24.jpg)
XML-QL to SQL (4/4)
( SELECT S.name, S.url FROM USStores S, USSales L, Products P WHERE S.usSid=L.usSid AND L.pid=P.pid AND L.date=‘1/1/2000’)
UNION
( SELECT S2.name, S2.url FROM EUStores S1, EUSales L1, Products P1 USStores S2, USSales L2, Products P2,WHERE S1.usSid=L1.usSid AND L1.pid=P1.pid AND L1.date=‘1/1/2000’ AND S2.usSid=L2.usSid AND L2.pid=P1.pid AND S1.country=“USA” AND S1.euSid = S2.usSid)