slide1 l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Logic as a Query Language: from Frege to XML PowerPoint Presentation
Download Presentation
Logic as a Query Language: from Frege to XML

Loading in 2 Seconds...

play fullscreen
1 / 31

Logic as a Query Language: from Frege to XML - PowerPoint PPT Presentation


  • 155 Views
  • Uploaded on

Logic as a Query Language: from Frege to XML. Victor Vianu U.C. San Diego. Logic and Databases: a success story. • FO lies at the core of modern database systems • Relational query languages are based on FO: SQL, QBE.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Logic as a Query Language: from Frege to XML' - Leo


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

Logic as a Query Language:

from Frege to XML

Victor Vianu

U.C. San Diego

slide2

Logic and Databases: a success story

• FO lies at the core of modern database systems

• Relational query languages are based on FO:

SQL, QBE

• More powerful query languages (all the way to XML)

are based on extensions of FO

• Foundations lie in classical logic

FO :Frege relational algebra :Tarski

slide3

Why is FO so successful as a query language?

• easy to use syntactic variants

SQL, QBE

• efficient implementation via relational algebra

amenable to analysis and simplification

• potential for perfect scaling to large databases

very fast response can be achieved

using parallel processing

slide4

A relational database:

drinker bar

bar beer

frequents

serves

Joe King’s

King’s Bass

Joe Molly’s

King’s Bud

Sue Molly’s

Molly’s Bass

………...

……………

• logically a finite first-order structure

slide5

Find the drinkers who frequent some bar serving Bass

FO:

d:drinker | b:bar (frequents(d,b)  serves(b, Bass))

QBE:

bar beer

drinker bar

frequents

serves

d b

b Bass

drinker

answer

d

slide6

not

Find the drinkers who frequent some bar serving Bass

FO:

d:drinker | b:bar (frequents(d,b)  serves(b, Bass))

¬

QBE:

bar beer

drinker bar

frequents

serves

d b

b Bass

¬

drinker

answer

d

slide7

• Naïve implementation: nested loops

d:drinker | b:bar (frequents(d,b)  serves(b, Bass))

for each drinker

for each bar

check the pattern

Number of checks:|drinkers|  |bars|

Roughly n : unacceptable for large databases!

2

• Better approach: relational algebra

slide8

Relational algebra operations

• union, difference

bar beer

King’s Bass

Molly’s Bass

• selection  (serves) =

……………

……………

beer = Bass

bar

King’s

• projection   (serves) =

bar

Molly’s

……

slide9

• join|| frequents || serves

drinker bar

bar beer

frequents

serves

Joe King’s

King’s Bass

Joe Molly’s

King’s Bud

Sue Molly’s

Molly’s Bass

………...

……………

drinker bar beer

frequents || serves

King’s Bass

JoeKing’s Bass

Molly’s Bass

JoeKing’s Bud

……………

JoeMolly’s Bass

SueMolly’s Bass

……………

slide10

Relational algebra queries

Find the drinkers who frequent some bar serving Bass

 (  ( frequents || serves ))

drinker

beer = Bass

drinker bar beer

drinker bar beer

drinker

JoeKing’s Bass

King’s Bass

King’s Bass

Joe

Sue

…..

JoeKing’s Bass

Molly’s Bass

Molly’s Bass

JoeKing’s Bud

……………

……………

JoeMolly’s Bass

JoeMolly’s Bass

SueMolly’s Bass

SueMolly’s Bass

……………

……………

Theorem: Relational algebra and FO are equivalent

journey of a query
Journey of a Query

FO (SQL) z(P(xz)  Q(zy))  …

Relational Algebra 13(PQ)  …

Query Rewriting 14(PS)  Q  R

Query Execution Plan

Execution

Physical Level





14

Q

R



P

S

slide12

• rewriting rules for algebra queries

 ( ( frequents || serves ))

drinker

beer = Bass

• efficient algorithms for individual operations

Indexes: special “directories” to data

cost:roughly n ( log n)

much better than n for large databases!

2

slide13

• rewriting rules for algebra queries

 ( ( frequents || serves ))

drinker

beer = Bass

 [frequents ||  ( (serves ))]

drinker

bar

beer = Bass

• efficient algorithms for individual operations

Indexes: special “directories” to data

cost:roughly n ( log n)

much better than n for large databases!

2

slide14

Most spectacular: theoretical potential for perfect scaling!

•perfect scaling: given sufficient resources,

performance does not degrade as the database

becomes larger

•key: parallel processing

•cost:number of processors polynomial in the size

of the database

•role of algebra:operations highlight parallelism

slide15

Each algebra operation can in principle be implemented

very efficiently in parallel

Example: projection

 (serves)

bar

bar beer

bar

serves

King’s Bass

King’s

King’s Bud

Molly’s

Molly’s Bass

……

……………

Constant parallel time!

slide16

Another example: join

frequents || serves

drinker bar

frequents

Joe King’s

Joe Molly’s

drinker bar beer

Sue Molly’s

………...

King’s Bass

JoeKing’s Bass

JoeKing’s Bass

Molly’s Bass

JoeKing’s Bud

……………

JoeMolly’s Bass

bar beer

SueMolly’s Bass

serves

King’s Bass

King’s Bud

……………

Molly’s Bass

……………

slide17

Every relational algebra query takes constant parallel time!

 ( ( frequents || serves ))

drinker

beer = Bass

drinker

beer = Bass

constant parallel time

||

frequents

serves

slide18

Summary so far:

• Keys to the success of FO as a query language:

-ease of use

-efficient implementation via relational algebra

• Constant parallel complexity:

the full potential of FO as a query language remains

yet to be realized!

slide19

Beyond relational databases: the Web and XML

• relations replaced by trees (XML data)

• structure described by schemas (e.g., DTDs)

Again, logic provides the foundations:

• DTDs are equivalent to tree automata (MSO on trees)

• XML queries are essentially tree transducers

• Can use automata and logic to understand semantics

and expressiveness, perform static analysis

slide20

Most XML query languages are extensions of SQL

• implementation based on same paradigm

• uses extensions of relational algebra

•query optimization builds upon relational techniques

xml and dtds
XML and DTDs

<dealer>

<UsedCars>

<ad>

<model>Honda</model>

<year>96</year>

</ad>

</UsedCars>

<NewCars>

<ad>

<model>Acura</model>

</ad>

</NewCars>

</dealer>

dealer

UsedCars

NewCars

ad

ad

model

year

model

Honda

96

Acura

data type definition dtd
Data Type Definition (DTD)

: alphabet of element names, root  

set of rules:

e

r

regular expression

over 

element name

documents satisfying a dtd
Documents satisfying a DTD

root

….

e

r

e

e1 …. ek

r

Set of trees satisfying DTD d: T(d)

example
Example

A DTD and a tree satisfying it:

root section*;

section intro, section*,conclusions;

root

section section

intro section conc intro conc

intro section section conc

intro conc intro conc

slide25

Specialization

dealer

UsedCars

NewCars

ad

ad

model

year

model

ad has different structure in different contexts

specialization
Specialization

dealer

UsedCars

NewCars

adused

adnew

model

year

model

ad has different structure in different contexts

slide27
• What sets of trees can be defined?

Exactly the regular tree languages!

--trees accepted by tree automata

--trees defined by Monadic Second-Order Logic (MSO)

•XML query languages are essentially tree transducers

• Consequences:

can use automata/logic techniques to analyze

and manipulate DTDs and XML queries

slide28

Example: static analysis for robust data integration

Integrated View

Common

DTD

XML Source

XML Source

Source DTDs

slide29

Example: static analysis for robust data integration

Integrated View

Tree automaton B

Common

DTD

Tree transducer T

XML Source

XML Source

Tree automaton A

Source DTDs

slide30

Example: static analysis for robust data integration

Integrated View

Tree automaton B

Common

DTD

Tree transducer T

XML Source

XML Source

Tree automaton A

Source DTDs

Need to check: T(A) B

Key: T-1(B) definable in MSO

slide31

Conclusion

  • Logic has provided the foundations of databases,
  • from relational databases all the way to XML
  • FO lies at the core of relational database systems
  • •XML and its query languages are founded upon
  • tree automata, tree transducers, and logics on trees
  • • Implementation uses extensions of relational algebra
  • and builds upon relational database techniques