Docsity

Datalog, Transitive Closure - Database Theory - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Datalog, Transitive Closure - Database Theory - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Datalog

Docsity.com

Example:The DuckGenealogy ¢ Is Scrooge^ an ancestorof Huey? ¢ Are Donald^ and^ Daisy related? ¢ Are Donald^ and^ Mickey related? ¢ Who are the descendantsof Gladstone? Calculus cannotcompute^ transitiveclosure^ of graphs!

Docsity.com

IntuitionTransitive closure of a graph:^ T(x,y) :- G(x,y)T(x,y) :- G(x,z), T(z,y)

G____ 1 | 22 | 33 | 2

T____| | |

1 2 3

Docsity.com

IntuitionTransitive closure of a graph:^ T(x,y) :- G(

T(x,y) :- G(x,z), T(z,y)

G____ 1 | 22 | 33 | 2

T____| | |

(^1) (1) Map from instancesover the relations in the rule body 2 3

Docsity.com

IntuitionTransitive closure of a graph:^ T(^1 ,^2 ) :- G(

T(x,y) :- G(x,z), T(z,y)

G____ 1 | 22 | 33 | 2

T____1 | 2| |^ (2) ... map to instancesover the relations in the rule head

1 2 3

Docsity.com

IntuitionTransitive closure of a graph:^ T(x,y) :- G(

x,y) T(x,y) :- G(x,z), T(z,y)

G____ 1 | 22 | 33 | 2

T____1 | 22 | 3|

1 2 3

Docsity.com

IntuitionTransitive closure of a graph:^ T(x,y) :- G(x,y)T(x,y) :- G(

1 ,^2 ), T(

G____ 2 , 3 )

1 | 22 | 33 | 2

T____1 | 22 | 33 | 2

(^1) (1) Map from instancesover the relations in the rule body 2 3

Docsity.com

IntuitionTransitive closure of a graph:^ T(x,y) :- G(x,y)T(^1 ,^3 ) :- G(

1 ,^2 ), T(

G____ 2 , 3 )

1 | 22 | 33 | 2

T____1 | 22 | 33 | 2^ (2) ... map to instancesover the relations in the rule head

1 2 3

Docsity.com

IntuitionTransitive closure of a graph:^ T(x,y) :- G(x,y)T(x,y) :- G(x,z), T(z,y)

G____ 1 | 22 | 33 | 2

T____1 | 22 | 33 | 21 | 32 | 23 | 3

... repeat until fixpoint is reached(datalog without negation is monotone)

1 2 3

Docsity.com

Outline ¢ Datalog rules ¢ 3 equivalent semantics l Model theoretic l Fixpoint l Proof theoretic ¢ Datalog evaluation l Naive l Semi-naive l Magic!

Docsity.com

Safe Datalog ¢ Here: Datalog without negation. ¢ Again, notion of

range-restricted

queries.

¢^ This query is not safe:^ Colored_edges(x,y,col) :- G(x,y)^ Every variable in the head of a rulemust also appear in the body.

Docsity.com

Semantics of Datalog3 equivalent approaches: l Model theoretic l Fixpoint theoretic l Proof theoretic

Docsity.com

Model Theoretic Approach ∀ x,y(^ T(x,y)

←^ G(x,y) ) ∀^ x,y,z( T(x,y)

←^ ( G(x,z)

∧^ T(z,y) ) )

Possible solutions:

G:^1

1 2 3

1 2 3

1 2 3 Docsity.com

Model Theoretic Approach ∀ x,y(^ T(x,y)

←^ G(x,y) ) ∀^ x,y,z( T(x,y)

←^ ( G(x,z)

∧^ T(z,y) ) )

Possible solutions:

G: Chose the^ minimum model (^1 23) T consists of the smallest set of facts that make the sentences true.

1 2 3

(^1 1 ) (^23) Docsity.com