• No results found

Foundations of Query Languages

N/A
N/A
Protected

Academic year: 2021

Share "Foundations of Query Languages"

Copied!
22
0
0

Loading.... (view fulltext now)

Full text

(1)

Foundations of Query Languages

Dr. Fang Wei

Lehrstuhl f¨ur Datenbanken und Informationssysteme Universit¨at Freiburg

(2)

Formal languages with syntax and semantics.

Syntax: algebraic or logical formalism or specific query language (SQL). Uses DB schema vocabulary.

Semantics:M[Q] a mapping that transforms a database (instance)D into a database (instance)D0 =M[Q](D).

We always disregard queries that are dependent on the particular representation of domain values. We thus restrict our attention toGeneric queries: Queries that Produce isomorphic results on isomorphic databases.

(3)

Expressive Power

Expressive power of a query language L:

E(L) ={M[Q]|Q∈L}

This way we can compare query languages, e.g.: if E(L)⊂E(L0) thenL0 is strictly more expressive thanL.

(4)

σSelection * πProjection * ×Cross product * ./ Join ρRename * −Difference * ∪Union * ∩Intersection

(5)

First-order Formulas (Relational Calculus)

Quantifiers: ∀, ∃ Boolean connectives ∧,∨,¬ Parentheses (, ) Atoms R(t1, . . . ,tn)

(6)

Schema

Author (AID integer, name string, age integer) Paper (PID string, title string, yearinteger) Write (AID integer, PID integer)

Instance

{(h142, Knuth, 70), (h123, Ullman, 60),. . .} {(h181140pods, Query containment, 1998),. . .} {(h123, 181140pods), (h142, 193214algo),. . .}

(7)

Example

PID’s of the papers that Knuth is NOT writing.

πPIDPaper−πPID(Write./ σname=0Knuth0Author) {PID|∃title,year.Paper(PID,title,year)∧

¬∃age,AID.(Write(AID,PID)∧Author(AID,0Knuth0,age))} Rules:

KnuthPapers(P)←Write(A,P),Author(A,0Knuth0,age).

(8)

PID’s of the papers that Knuth is NOT writing.

πPIDPaper−πPID(Write./ σname=0Knuth0Author)

{PID|∃title,year.Paper(PID,title,year)∧

¬∃age,AID.(Write(AID,PID)∧Author(AID,0Knuth0,age))} Rules:

KnuthPapers(P)←Write(A,P),Author(A,0Knuth0,age).

(9)

Example

PID’s of the papers that Knuth is NOT writing.

πPIDPaper−πPID(Write./ σname=0Knuth0Author)

{PID|∃title,year.Paper(PID,title,year)∧

¬∃age,AID.(Write(AID,PID)∧Author(AID,0Knuth0,age))}

Rules:

KnuthPapers(P)←Write(A,P),Author(A,0Knuth0,age).

(10)

PID’s of the papers that Knuth is NOT writing.

πPIDPaper−πPID(Write./ σname=0Knuth0Author)

{PID|∃title,year.Paper(PID,title,year)∧

¬∃age,AID.(Write(AID,PID)∧Author(AID,0Knuth0,age))} Rules:

KnuthPapers(P)←Write(A,P),Author(A,0Knuth0,age).

(11)

Example

AID’s of authors who wrote exactly one paper

S2 =ρWrite(AID1,PID1)./AID1=AID2,PID16=PID2ρWrite(AID2,PID2)

S=πAIDWrite−πAID1S2

{AID|∃PID.(Write(AID,PID)∧ ¬∃PID2.(Write(AID,PID2)∧PID 6=PID2))} Rules:

(12)

AID’s of authors who wrote exactly one paper

S2 =ρWrite(AID1,PID1)./AID1=AID2,PID16=PID2ρWrite(AID2,PID2)

S=πAIDWrite−πAID1S2

{AID|∃PID.(Write(AID,PID)∧ ¬∃PID2.(Write(AID,PID2)∧PID 6=PID2))} Rules:

(13)

Example

AID’s of authors who wrote exactly one paper

S2 =ρWrite(AID1,PID1)./AID1=AID2,PID16=PID2ρWrite(AID2,PID2)

S=πAIDWrite−πAID1S2

{AID|∃PID.(Write(AID,PID)∧ ¬∃PID2.(Write(AID,PID2)∧PID 6=PID2))}

Rules:

(14)

AID’s of authors who wrote exactly one paper

S2 =ρWrite(AID1,PID1)./AID1=AID2,PID16=PID2ρWrite(AID2,PID2)

S=πAIDWrite−πAID1S2

{AID|∃PID.(Write(AID,PID)∧ ¬∃PID2.(Write(AID,PID2)∧PID 6=PID2))}

Rules:

(15)
(16)
(17)

RA to FO

R(A,B)S(C,D) σA=3R {(x,y)|R(x,y)∧x = 3} rule:R0(x,y)←R(x,y),x = 3 πAR {x|∃y.R(x,y)} R./B R0(x,y,z)←R(x,y),S(y,z) union? difference?

(18)
(19)

Unsafe FO Queries

Sometimes FO queries can express queries which are ’unsafe’. {x|∀yR(x,y)}

R={(1,1)}, dom={1,2}, x=∅

R={(1,1)}, dom={1},x ={1}

(20)

Another ’unsafe’ query.

{x|¬R(x)}

R={(1)}, dom={1,2},x ={2}

R={(1)}, dom={1},x =∅

(21)

Active Domain

The active domain interpretation restricts quantified variables of the query to range over the active domain of the query and the input

Given the database and the query, the domain is determined using the active domain semantics

R={(1,1)}dom(R)={1,2}

adom ={1} not{1,2}!

(22)

The active domain interpretation is a viable solution. Under this

interpretation, every query in FO is expressible in RA, and thus FO and RA have the same expressive Power: RA=FO (See AHV, Section 5).

The same is true for safe, i.e., domain independent queries. But it is unfortunately undecidable whether a query is safe. (We will come back to this later)

It is even true for a subset of the safe queries, the range restricted queries (see AHV)

References

Related documents

Class Name (Class Code) & Descriptions Name Advance Study of Mathematics for Information

Veitchi Industrial Flooring provide a tailored flooring solution across a wide range of sectors.. By careful selection we can offer the best solution for all types of

All correlations shown are significant at p<0.05; error bars represent the range of values obtained by calculating the correlation coefficient from the results of

This research begins to fill the literature gap identified in cloud computing adoption by SMEs and indeed the gap in researching information systems in developing

After an overnight admission with their usual evening hydrocortisone dose, subjects were administered their usual morning dose of steroid after obtaining baseline serum

By means of an appropriate selection of tweets, and of the employment of graphical Gaussian models to estimate relationships between bank tweet sentiment variations, the paper

Documents in the TREC collection that contain abbreviations reported as separate entities were either present as a separate abbreviations section in the scientific article or