Download presentation
Presentation is loading. Please wait.
1
Managing XML and Semistructured Data
Lecture 5: Query Languages - Lorel and UnQL Prof. Dan Suciu Spring 2001
2
In this lecture A core query language Lorel UnQL Resources:
UnQL: A Query Language and Algebra for Semistructured Data Based on Structural Recursion Buneman, Fernandez, Suciu. VLDBJ 2000 The Lorel Query Language for Semistructured Data by Abiteboul, Quass, McHugh, Widom, Wiener, in International Journal on Digital Libraries, 1997.
3
A Core Query Language Will illustrate with: DB = . . . 1976 Database
biblio &o1 book paper book &o12 &o24 &o29 . . . title author date author title author date &o52 &96 &25 &30 1976 Database Systems &o47 &o48 &o50 Roux Combalusier Smith 1999 Database Systems
4
Query 1: SELECT author: X FROM biblio.book.author X . . .
answer &o1 &o12 &o24 &o29 &96 &30 paper book author date title biblio &o47 &o48 &o50 &o52 &25 Smith 1999 Database Systems Roux Combalusier 1976 . . . author Answer = {author: “Smith”, author: “Roux”, author: “Comalusier”} author author
5
Query 2: SELECT row: X FROM biblio._ X WHERE “Smith” in X.author . . .
answer &o1 &o12 &o24 &o29 &96 &30 paper book author date title biblio &o47 &o48 &o50 &o52 &25 Smith 1999 Database Systems Roux Combalusier 1976 . . . Answer = {row: {author:“Smith”, date: 1999, title: “Database…”}, row: … } row
6
SELECT row: ( SELECT author: Y FROM X.author Y) FROM biblio.book X
Query 3: row answer &o1 &o12 &o24 &o29 &96 &30 paper book author date title biblio &o47 &o48 &o50 &o52 &25 Smith 1999 Database Systems Roux Combalusier 1976 . . . &a1 row Answer = {row: {author:“Smith”}, row: {author:“Roux”, author:“Combalusier”,}, } &a2 author author author
7
SELECT ( SELECT row: {author: Y, title: T} FROM X. author Y, X
SELECT ( SELECT row: {author: Y, title: T} FROM X.author Y, X.title T) FROM biblio.book X WHERE “Roux” in X.author Query 4: row answer &o1 &o12 &o24 &o29 &96 &30 paper book author date title biblio &o47 &o48 &o50 &o52 &25 Smith 1999 Database Systems Roux Combalusier 1976 . . . Answer = {row: {author:“Roux”, title: “Database…”}, row: {author:“Combalusier”, title: “Database…”}, } &a1 row author &a2 title title author (Query has typo in the book )
8
Formal Semantics SELECT E[X1, …, Xn] FROM F WHERE C
Given query Q = and database DB Answer(Q,DB) is defined in two steps: Step 1: compute all bindings: Cij are node oids or atomic values Must satisfy paths in F Must satisfy conditions in C Step 2: answer is E[C11, …, C1n] … E[Cm1, …, Cmn] X1 X2 … Xn Ci1 Ci2 Cin
9
Formal Semantics When E has nested subqueries, apply semantics recursively Note: so far we have dealt with an unordered model What do we need to do for order ? Complexity: PTIME in |DB| (not in |Q|).
10
Lorel Minor syntactic differences in regular path expressions (% instead of _, # instead of _*) Common path convention: becomes: SELECT biblio.book.author FROM biblio.book WHERE biblio.book.year = 1999 SELECT X.author FROM biblio.book X WHERE X.year = 1999
11
Lorel Existential variables:
What happens with books having multiple authors ? Author is existentially quantified: SELECT biblio.book.year FROM biblio.book WHERE biblio.book.author = “Roux” SELECT X.year FROM biblio.book X, X.author Y WHERE Y = “Roux”
12
Lorel Path variables. @P in: Constructing new results
What happens on graphs with cycles ? Constructing new results Several default rules Casting between datatypes Very useful in practice SELECT P FROM X
13
UnQL Patterns: Equivalent to:
SELECT row: X WHERE {biblio.book: {author “Roux”, title X}} in DB, SELECT row: X FROM biblio.book Y, Y.author Z, Y.title X WHERE Z=“Roux”
14
UnQL Label variables: “find all publication types and their titles where Roux is an author” SELECT row: {type: L, title : X} WHERE {biblio.L: {author “Roux”, title X}} in DB,
15
UnQL Unrestricted use of label variables creates problems:
SELECT row: {type: L, title : Y} WHERE {biblio.(book|L).title X} in DB, SELECT row: {type: L, title : Y} WHERE {biblio.(L)*.title X} in DB,
16
UnQL In UnQL regular path expressions cannot contain label variables:
Pat ::= Var | Const | {L1:Pat1, …, Ln:Patn} L ::= RegularPathExpression | LabelVariable
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.