day 5: acq, fo eci 2015 buenos aires -...

91
Fundamentos lógicos de bases de datos ¬ ECI 2015 Buenos Aires CNRS LaBRI Diego Figueira Gabriele Puppis (Logical foundations of databases) Day 5: ACQ, FO k

Upload: others

Post on 13-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Fundamentos lógicos de bases de datos

∀∃¬

ECI 2015 Buenos Aires

CNRS LaBRI

Diego Figueira Gabriele Puppis(Logical foundations of databases)

Day 5: ACQ, FOk

Page 2: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Recap

• NP complexity class (SAT, 3COL, ….)

• Conjunctive Queries (correspondence with SQL and Relational Algebra)

• Homomorphisms and canonical structure

• Evaluation of CQ (NP-completeness)

• Containment, Equivalence, Minimisation of CQ (NP-completeness)

• Extension to functional dependencies (chased canonical structure)

Page 3: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

Page 4: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

underlying undirected graph is

acyclic

Page 5: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) z t

y

x

Page 6: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) z t

y

x

On arbitrary structures: a CQ φ is acyclic if it has a join tree

φ(ȳ) = ∃z̄ . R1(z̄1) ⋀ … ⋀ Rm(z̄m)

Page 7: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) z t

y

x

On arbitrary structures: a CQ φ is acyclic if it has a join tree

φ(ȳ) = ∃z̄ . R1(z̄1) ⋀ … ⋀ Rm(z̄m)

A join tree is a tree T s.t.: • nodes are the atoms Ri(z̄i) • for every variable x of φ the set of Ri(z̄i)’s with x ∈ z̄i forms a subtree of T

Page 8: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) z t

y

x

On arbitrary structures: a CQ φ is acyclic if it has a join tree

φ(ȳ) = ∃z̄ . R1(z̄1) ⋀ … ⋀ Rm(z̄m)

A join tree is a tree T s.t.: • nodes are the atoms Ri(z̄i) • for every variable x of φ the set of Ri(z̄i)’s with x ∈ z̄i forms a subtree of T

If x occurs in two nodes, then it occurs in the path linking

the two nodes.

Page 9: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) z t

y

x

On arbitrary structures: a CQ φ is acyclic if it has a join tree

φ(ȳ) = ∃z̄ . R1(z̄1) ⋀ … ⋀ Rm(z̄m)

A join tree is a tree T s.t.: • nodes are the atoms Ri(z̄i) • for every variable x of φ the set of Ri(z̄i)’s with x ∈ z̄i forms a subtree of T

Alternatively, if its canonical hyper-graph is

α-acyclic.

Page 10: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

3

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) z t

y

x

On arbitrary structures: a CQ φ is acyclic if it has a join tree

φ(ȳ) = ∃z̄ . R1(z̄1) ⋀ … ⋀ Rm(z̄m)

A join tree is a tree T s.t.: • nodes are the atoms Ri(z̄i) • for every variable x of φ the set of Ri(z̄i)’s with x ∈ z̄i forms a subtree of T

Alternatively, if its canonical hyper-graph is

α-acyclic.

A reduced hypergraph F =(V,E) is α-acyclic if for each U ⊆V,

if F|U is connected and has more than one edge, then it has an articulation set.

Page 11: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z)

Page 12: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z) E(x,z)

E(x,t)E(y,z)

join tree

Page 13: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z) E(x,z)

E(x,t)E(y,z)

join tree

Page 14: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z) E(x,z)

E(x,t)E(y,z)

join tree

S(z,t)

S(x,z)

R(x,y,z) T(z)

T(x)

Page 15: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z) E(x,z)

E(x,t)E(y,z)

join tree

S(z,t)

S(x,z)

R(x,y,z) T(z)

T(x)

not a join tree

Page 16: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z) E(x,z)

E(x,t)E(y,z)

join tree

S(z,t)

S(x,z)

R(x,y,z) T(z)

T(x)

not a join tree

S(z,t)

S(x,z)

R(x,y,z) T(z)

T(x)

Page 17: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

4

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(x,t) ⋀ E(y,z) E(x,z)

E(x,t)E(y,z)

join tree

S(z,t)

S(x,z)

R(x,y,z) T(z)

T(x)

not a join tree

S(z,t)

S(x,z)

R(x,y,z) T(z)

T(x)

a join tree

Page 18: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

5

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)[Yannakakis]

Page 19: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

5

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)[Yannakakis]

The semi-join

R ⋉{i1=j1,…,in=jn} S = { (x1,…,xn) ∈ R | there is (y1,…,ym) ∈ S where xik = yjk for all k}

Note: R ⋉{i1=j1,…,in=jn} S ⊆ R

Page 20: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

6

Acyclic CQ’s

1. Compute the join tree T for φ

2. Populate the nodes of T with tuples from corresponding relations of D

3. For every leaf S(x1,…,xn) with parent R(y1,…,ym) replace tuples of parent with and delete the leaf S(x1,…,xn).

4. Repeat until we are left with one node. If it contains a non-empty relation, then D satisfies φ, otherwise it does not.

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)[Yannakakis]

R ⋉{i=j |xi = yj} S

Page 21: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

6

Acyclic CQ’s

1. Compute the join tree T for φ

2. Populate the nodes of T with tuples from corresponding relations of D

3. For every leaf S(x1,…,xn) with parent R(y1,…,ym) replace tuples of parent with and delete the leaf S(x1,…,xn).

4. Repeat until we are left with one node. If it contains a non-empty relation, then D satisfies φ, otherwise it does not.

in linear time

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)[Yannakakis]

R ⋉{i=j |xi = yj} S

Page 22: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

6

Acyclic CQ’s

1. Compute the join tree T for φ

2. Populate the nodes of T with tuples from corresponding relations of D

3. For every leaf S(x1,…,xn) with parent R(y1,…,ym) replace tuples of parent with and delete the leaf S(x1,…,xn).

4. Repeat until we are left with one node. If it contains a non-empty relation, then D satisfies φ, otherwise it does not.

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)[Yannakakis]

R ⋉{i=j |xi = yj} S

remove all the tuples from the parent that do not match a tuple from

the child

Page 23: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 24: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)}

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 25: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)}

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 26: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)}

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 27: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)}

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 28: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)}

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 29: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)}

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 30: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

7

Acyclic CQ’s

The evaluation problem for acyclic CQ sentences is in O(|φ|.|D|)

S(z,t)

S(x,z)

R(x,y,z) T(z) T(x)

φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

:{1,2,3,4}:{1,2,3,4}:{(1,4,4),(4,1,4)}

:{(4,5),(5,2),(4,4)}

:{(4,5),(5,2),(4,4)} ≠ ∅

R={(1,4,4),(4,1,4)} S={(4,5),(5,2),(4,4)} T={1,2,3,4}

Page 31: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

8

Acyclic CQ’sHow to compute a join tree?

GYO reducts [Graham, Yu, Ozsoyoglu]

x4

An ear of a hypergraph (V,E) is a hyperedge e in E such that one of the following conditions holds: (1) There is a witness e' in E, such that e' ≠ e and each vertex from e is either (a) only in e or (b) in e'; or (2) e has no intersection with any other hyperedge.

x1x2

x5

x6x7

x3

ears?

Page 32: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

9

Ears?

x1x2

x3 x4

x1

x2

x5

x6

x3

Page 33: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

10

Ears!

Definition: The GYO reduct of a hyper-graph is the result of

removing ears until no more ears are left.

Page 34: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

10

Ears!

Definition: The GYO reduct of a hyper-graph is the result of

removing ears until no more ears are left.

Theorem: TFAE

• The GYO reduct of a hyper graph G is empty

• A CQ φ having G as underlying canonical hyper-graph is acyclic

• The hyper graph G is α-acyclic

Page 35: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

10

Ears!

Definition: The GYO reduct of a hyper-graph is the result of

removing ears until no more ears are left.

Theorem: TFAE

• The GYO reduct of a hyper graph G is empty

• A CQ φ having G as underlying canonical hyper-graph is acyclic

• The hyper graph G is α-acyclic

We can test acyclicity by computing the GYO reduct!

Page 36: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

11

Ears?

x4

x1

x2

x5

x6

x3

Page 37: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

11

Ears?

x4

x1

x2

x5

x6

x3

Page 38: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

11

Ears?

x4

x1

x2

x5

x6

x3

Page 39: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

11

Ears?

x4

x1

x2

x5

x6

x3

Page 40: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

11

Ears?

x4

x1

x2

x5

x6

x3

Acyclic!

Page 41: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 42: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 43: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

S(x,y)

R(x,y,z)

T(x,x)

R(x,x,y)

T(y,y)

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 44: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

S(x,y)

R(x,y,z)

T(x,x)

R(x,x,y)

T(y,y)

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 45: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

S(x,y)

R(x,y,z)

T(x,x)

R(x,x,y)

T(y,y)

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 46: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

S(x,y)

R(x,y,z)

T(x,x)

R(x,x,y)

T(y,y)

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 47: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

S(x,y)

R(x,y,z)

T(x,x)

R(x,x,y)

T(y,y)

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 48: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

12

Acyclic CQ’s

How to compute a join tree?

Given the query Q = { R1(X1),…,Rn(Xn) } Consider its canonical structure GQ For Ri(Xi) an ear with witness Rj(Yj) Put an edge between Ri(Xi) and Rj(Xj), and remove Ri from Q. Repeat.

E.g. R(x,y,z), S(x,y), T(x,x), R(x,x,y), T(y,y)

S(x,y)

R(x,y,z)

T(x,x)

R(x,x,y)

T(y,y)

Remove ears until you’re left with only one!

GYO algorithm [Graham, Yu, Ozsoyoglu]

Page 49: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

13

Acyclic CQ’s

• Evaluation problem for boolean ACQ’s is LOGCFL-complete

• NL ⊆ LOGCFL ⊆ AC1 ⊆ NC2 ⊆ P

[Gottlob, Leone, Scarcello]

the class of problems logspace-reducible to

a context-free language

Page 50: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

14

Beyond acyclic CQ’s

• (Hyper-)Treewidth = a measure of the cyclicity of (hyper-)graphs tw(Q) = tw(canonical hypergraph of Q) tw = 1 are forests, tw = 2 are graphs without K4 as a minor, …

• For fixed k, computing whether Q has tw ≤k and calculating a tree decompositioncan be done in linear time

Page 51: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

14

Beyond acyclic CQ’s

• (Hyper-)Treewidth = a measure of the cyclicity of (hyper-)graphs tw(Q) = tw(canonical hypergraph of Q) tw = 1 are forests, tw = 2 are graphs without K4 as a minor, …

• For fixed k, computing whether Q has tw ≤k and calculating a tree decompositioncan be done in linear time

Bounded tree width queries = a class of CQ’s so that for some k,

every query has tw ≤ k

Page 52: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

15

Beyond acyclic CQ’s

CQ’s with bounded treewidth can be evaluated in PTIME

Page 53: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

15

Beyond acyclic CQ’s

CQ’s with bounded treewidth can be evaluated in PTIME

Containment of CQ’s with bounded treewidth is in PTIME

Page 54: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

15

Beyond acyclic CQ’s

CQ’s with bounded treewidth can be evaluated in PTIME

Containment of CQ’s with bounded treewidth is in PTIME

φ ⊆ ψ iff ψ(Gφ)≠∅

Page 55: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

15

Beyond acyclic CQ’s

CQ’s with bounded treewidth can be evaluated in PTIME

A class C of CQ’s can be evaluated in PTIME iff they have bounded tree width!

[Grohe, Schwentick, Segoufin]For graphs, assuming W[1]≠︎ FPT, and C a r.e. class of graphs.

Containment of CQ’s with bounded treewidth is in PTIME

Page 56: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

16

Querying with semi-joins

The semi-joinR ⋉{i1=j1,…,in=jn} S = { (x1,…,xn) ∈ R | there is (y1,…,ym) ∈ S where xik = yjk for all k}

The semi-join algebra (SA): variant of RA with operations: ⋉, ∪, π, σ, \, dupcol

Page 57: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

16

Querying with semi-joins

The semi-joinR ⋉{i1=j1,…,in=jn} S = { (x1,…,xn) ∈ R | there is (y1,…,ym) ∈ S where xik = yjk for all k}

The semi-join algebra (SA): variant of RA with operations: ⋉, ∪, π, σ, \, dupcol

Output at most linear in the database. Further,

The evaluation problem for SA is in O(|φ|.|D|)

Logical characterisation: “stored-tuples guarded fragment of FO”

Page 58: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

17

Acyclic CQs: • every intermediate relation is linear in |D| • we apply |φ| semi-joins

What if we allow intermediate relations to be polynomial in |D|?

Page 59: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Def.

18

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

Page 60: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

G

Page 61: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

Question: in FO2 ?

G

Page 62: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

= ∀y. ( E(x, y) ⟹ ∃x (E(y, x) ⋀ ∃y E(x, y) ) ) ∈ FO2

G

Page 63: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

PTIME

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

= ∀y. ( E(x, y) ⟹ ∃x (E(y, x) ⋀ ∃y E(x, y) ) ) ∈ FO2

G

Page 64: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

PTIME

PTIME

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

= ∀y. ( E(x, y) ⟹ ∃x (E(y, x) ⋀ ∃y E(x, y) ) ) ∈ FO2

G

Page 65: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

PTIME

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

= ∀y. ( E(x, y) ⟹ ∃x (E(y, x) ⋀ ∃y E(x, y) ) ) ∈ FO2

G

Page 66: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

PTIME

PTIME

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

= ∀y. ( E(x, y) ⟹ ∃x (E(y, x) ⋀ ∃y E(x, y) ) ) ∈ FO2

G

Page 67: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

φ(x) = “Every neighbour of x has an outgoing path of length 2”

= ∀y. ( E(x, y) ⟹ ∃z ∃w ( E(y, z) ⋀ E(z, w) ) ) ∈ FO4

Def.

18

PTIME

PTIME

Bounded variable FO

FOk = The fragment of FO restricted to k variable names

= ∀y. ( E(x, y) ⟹ ∃x (E(y, x) ⋀ ∃y E(x, y) ) ) ∈ FO2

The evaluation problem for FOk is in PTIME (combined c.)

G

Page 68: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

The evaluation problem for FOk is in PTIME (combined c.)

Page 69: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

The evaluation problem for FOk is in PTIME (combined c.)

Page 70: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

qr 1

The evaluation problem for FOk is in PTIME (combined c.)

Page 71: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

qr 1qr 2 . . .

The evaluation problem for FOk is in PTIME (combined c.)

Page 72: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

. . .

1. Evaluate qr=0 subformulas α and output result in relations R0,α

2. Evaluate qr=1 subformulas β based on R0,α and output in R1,β

3. Evaluate qr=2 subformulas γ based on R1,β and output in R1,γ

4. . . .

r. . . .

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

qr 1qr 2 . . .

The evaluation problem for FOk is in PTIME (combined c.)

Page 73: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

. . .

1. Evaluate qr=0 subformulas α and output result in relations R0,α

2. Evaluate qr=1 subformulas β based on R0,α and output in R1,β

3. Evaluate qr=2 subformulas γ based on R1,β and output in R1,γ

4. . . .

r. . . .

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

qr 1qr 2 . . .

⇝ |V|k · (|α| · |G|)p

The evaluation problem for FOk is in PTIME (combined c.)

Page 74: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

. . .

1. Evaluate qr=0 subformulas α and output result in relations R0,α

2. Evaluate qr=1 subformulas β based on R0,α and output in R1,β

3. Evaluate qr=2 subformulas γ based on R1,β and output in R1,γ

4. . . .

r. . . .

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

qr 1qr 2 . . .

⇝ |V|k · (|α| · |G|)p

The evaluation problem for FOk is in PTIME (combined c.)

≤|V|k

⇝ |V|k · (|β| · (|G|+ |R1|))p

Page 75: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

19

. . .

1. Evaluate qr=0 subformulas α and output result in relations R0,α

2. Evaluate qr=1 subformulas β based on R0,α and output in R1,β

3. Evaluate qr=2 subformulas γ based on R1,β and output in R1,γ

4. . . .

r. . . .

Bounded variable FO

Algorithm for a FOk formula ψ of quantifier rank r:

Maximum number of nested quantifiers “∃x(… ∀y(… ∃x(… ∃z(…) ) ) )”qr 0

qr 1qr 2 . . .

⇝ |V|k · (|α| · |G|)p

≤|V|k

⇝ |V|k · (|γ| · (|G|+ |R2|))p

The evaluation problem for FOk is in PTIME (combined c.)

≤|V|k

⇝ |V|k · (|β| · (|G|+ |R1|))p

Page 76: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

20

Bounded variable FO

Desirable:

• Given k and a FO query φ, is φ in FOk ? ⇝ 💀 Undecidable (even w.o. ¬)

Page 77: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

20

Bounded variable FO

Desirable:

• Given k and a FO query φ, is φ in FOk ? ⇝ 💀 Undecidable (even w.o. ¬)

• Given k and a CQ query φ, is φ in FOk ? ⇝ NP-complete

Page 78: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

20

Bounded variable FO

Desirable:

• Given k and a FO query φ, is φ in FOk ? ⇝ 💀 Undecidable (even w.o. ¬)

• Given k and a CQ query φ, is φ in FOk ? ⇝ NP-complete

• Satisfiability for FOk ⇝ Undecidable if k≥3 (Domino)

⇝ NEXPTIME-complete if k=2

Page 79: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

21

Recap

LOGSPACEPTIMEPSPACEUNDECIDABLE

Domino

Eval-FO (combined)

Eval-FO (data)

Sat-FO

Equivalence-FO

Equivalence-SQL

Equivalence-RA

QBF

NP

Cont-CQ

Eval-FOk (combined)SAT

3COL

Eval-CQ (combined)

Page 80: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Descriptive complexityWhat properties can be checked efficiently? E.g. 3COL can be tested in NP

Metatheorem “A property can be expressed in [insert some logic here] iff it can be checked in [some complexity class here]”

Page 81: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Descriptive complexityWhat properties can be checked efficiently? E.g. 3COL can be tested in NP

[Fagin 73]

⇝ “A property is FO-definable iff it can be tested in AC0”

⇝ “A property is ∃SO-definable iff it can be tested in NP”

⇝ Open problem: which logic captures PTIME?

Metatheorem “A property can be expressed in [insert some logic here] iff it can be checked in [some complexity class here]”

Page 82: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Recursion

Datalog (semantics based on least fixpoint)    Ancestor(X,Y)  :-­‐  Parent(X,Z),  Ancestor(Z,Y)    Ancestor(X,X)  :-­‐  .    ?-­‐  Ancestor(“Louis  XIV”,Y)

Page 83: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

RecursionCan we enhance query languages with recursion ? E.g. express reachability properties

Datalog (semantics based on least fixpoint)    Ancestor(X,Y)  :-­‐  Parent(X,Z),  Ancestor(Z,Y)    Ancestor(X,X)  :-­‐  .    ?-­‐  Ancestor(“Louis  XIV”,Y)

Page 84: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

RecursionCan we enhance query languages with recursion ? E.g. express reachability properties

⇝ Incomparable with FO (has recursion, but is monotone)

⇝ Evaluation is in PTIME (for data complexity, but also for bounded arity)

Datalog (semantics based on least fixpoint)    Ancestor(X,Y)  :-­‐  Parent(X,Z),  Ancestor(Z,Y)    Ancestor(X,X)  :-­‐  .    ?-­‐  Ancestor(“Louis  XIV”,Y)

Page 85: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Semi-structured dataTree-structured or graph-structures dbs in place of relational dbs.

XML, XPath, Stream processing, …

 <catalog>        <book  id="1">            <title>XML  Developer's  Guide</title>            <author>Matthew  Gambardella</author>            <year>2000</year>        </book>        <book  id="2">            <title>Beginning  XML</title>            <author>David  Hunter</author>            <author>David  Gibbons</author>            <year>2007</year>        </book>        …      <catalog>

Page 86: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Semi-structured dataTree-structured or graph-structures dbs in place of relational dbs.

XML, XPath, Stream processing, …

 <catalog>        <book  id="1">            <title>XML  Developer's  Guide</title>            <author>Matthew  Gambardella</author>            <year>2000</year>        </book>        <book  id="2">            <title>Beginning  XML</title>            <author>David  Hunter</author>            <author>David  Gibbons</author>            <year>2007</year>        </book>        …      <catalog>

⇝ Evaluation of XPath is in linear time (data complexity)⇝ Satisfiability for FO2[↓,~] is decidable [Bojanczyk, Muscholl, Schwentick, Segoufin 09]

[Bojanczyk, Parys 08]

Page 87: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Incomplete information

Certain Query Answers (CQA)

V

φ ⟦V⟧ = ∩D ∈ ⟦V⟧ φ (D)

⟦V⟧

Page 88: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Incomplete informationHow to correctly treat NULL values, missing tuples, noisy data ?

Certain Query Answers (CQA)

V

φ ⟦V⟧ = ∩D ∈ ⟦V⟧ φ (D)

⟦V⟧

Page 89: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Some more cool stuff…

Incomplete informationHow to correctly treat NULL values, missing tuples, noisy data ?

Certain Query Answers (CQA)

V

φ ⟦V⟧ = ∩D ∈ ⟦V⟧ φ (D)

⟦V⟧

⇝ CQA computable in PTIME w.r.t. view size. [Abiteboul, Kanellakis, Grahne 91]

Page 90: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

Recap

• Relational Algebra = simple SQL = FO on active domain

• Evaluation, Satisfiability, Equivalence, Containment

• Data / Combined complexity

• Expressiveness of FO: EF games, 0-1 law, Rado structure, Locality

• Conjunctive Queries: Homomorphism lemma, Canonical structures

• Acyclic CQ

• FOk

Page 91: Day 5: ACQ, FO ECI 2015 Buenos Aires - Uniudusers.dimi.uniud.it/~gabriele.puppis/slides/ECI2015-day5.pdfFundamentos lógicos de bases de datos ¬ ∀∃ ECI 2015 Buenos Aires CNRS

27

Bibliography

• Abiteboul, Hull, Vianu, “Foundations of Databases”, Addison-Wesley, 1995.

(freely available at http://webdam.inria.fr/Alice/)

• Libkin, “Elements of Finite Model Theory”, Springer, 2004.

• Immerman, “Descriptive Complexity”, Springer, 1999.