Logical foundations of databases Diego Figueira Gabriele Puppis - - PowerPoint PPT Presentation

logical foundations of databases diego figueira gabriele
SMART_READER_LITE
LIVE PREVIEW

Logical foundations of databases Diego Figueira Gabriele Puppis - - PowerPoint PPT Presentation

day 3 ESSLLI 2016 Bolzano, Italy Logical foundations of databases Diego Figueira Gabriele Puppis CNRS LaBRI Recap Active domain semantics and expressiveness: FO act =* RA Undecidable problems (Halting Domino


slide-1
SLIDE 1

Logical foundations of databases

∀∃ ¬

ESSLLI 2016 Bolzano, Italy

CNRS LaBRI Diego Figueira Gabriele Puppis

day 3

slide-2
SLIDE 2

Recap

  • Active domain semantics and expressiveness: FOact =* RA
  • Undecidable problems (Halting ≤ Domino ≤ FO-Satisfiability ≤ FO-Equivalence)
  • Data complexity / Combined complexity
  • Evaluation problem for FO: in PSPACE (combined comp.)


in PSPACE (query comp.)
 in LOGSPACE (data comp.)


  • Positive FO: evaluation in NP (combined comp.)
  • Conjunctive Queries
slide-3
SLIDE 3

3

Conjunctive Queries

Def.

CQ = FO without ∀,¬,⋁

Usual notation: “Grandparent(X,Y) : – Parent(X,Z), Parent(Z,Y)” Eg: φ(x, y) = ∃ z . (Parent(x, z) ⋀ Parent(z, y))

slide-4
SLIDE 4

3

Conjunctive Queries

Def.

CQ = FO without ∀,¬,⋁

Usual notation: “Grandparent(X,Y) : – Parent(X,Z), Parent(Z,Y)” Eg: φ(x, y) = ∃ z . (Parent(x, z) ⋀ Parent(z, y))

Normal form: “ ∃ x1, …, xn . φ(x1, …, xn) ”

quantifier-free and no equalities!

slide-5
SLIDE 5

3

Conjunctive Queries

Def.

CQ = FO without ∀,¬,⋁

Usual notation: “Grandparent(X,Y) : – Parent(X,Z), Parent(Z,Y)” Eg: φ(x, y) = ∃ z . (Parent(x, z) ⋀ Parent(z, y))

Select ¡... ¡ From ¡... ¡ Where ¡Z

no negation or disjunction It corresponds to positive “SELECT-FROM-WHERE” SQL queries πX(σZ(R1 ×···× Rn)) no negation It corresponds to “π-σ-×” RA queries

Normal form: “ ∃ x1, …, xn . φ(x1, …, xn) ”

quantifier-free and no equalities!

slide-6
SLIDE 6

4

Homomorphisms

S = (V , R1 , R2) S' = (V ', R1' , R2') Homomorphism between structures S=(V, R1, …, Rn) and S '=(V ', R1', …, Rn')
 is a function h : V ⟶ V ' such that (x1, …, xn) ∈ Ri implies (h(x1), …, h(xn)) ∈ Ri'

slide-7
SLIDE 7

5

Homomorphisms

G = (V , E) G' = (V', E' ) Homomorphism between structures S=(V, R1, …, Rn) and S '=(V ', R1', …, Rn')
 is a function h : V ⟶ V ' such that (x1, …, xn) ∈ Ri implies (h(x1), …, h(xn)) ∈ Ri'

slide-8
SLIDE 8

6

Gφ = (V , E) G' = (V', E' )

Canonical structures

Canonical structure Gφ of a Conjunctive Query φ has

  • variables as nodes
  • tuples (x1, …, xn) ∈ Ri


for all atomic sub-formulas Ri (x1, …, xn) of φ

slide-9
SLIDE 9

6

Gφ = (V , E) G' = (V', E' )

Canonical structures

Canonical structure Gφ of a Conjunctive Query φ has

  • variables as nodes
  • tuples (x1, …, xn) ∈ Ri


for all atomic sub-formulas Ri (x1, …, xn) of φ

Gφ = (V , E) E.g.: φ = ∃x ∃y ∃z . (E(x, y) ⋀ E(y, z) ⋀ E(x, z)) x y z v1 v2 v3

slide-10
SLIDE 10

6

Gφ = (V , E) G' = (V', E' )

Canonical structures

Canonical structure Gφ of a Conjunctive Query φ has

  • variables as nodes
  • tuples (x1, …, xn) ∈ Ri


for all atomic sub-formulas Ri (x1, …, xn) of φ

Gφ = (V , E) E.g.: φ = ∃x ∃y ∃z . (E(x, y) ⋀ E(y, z) ⋀ E(x, z)) x y z

Fact 1: Gφ ⊨ φ

v1 v2 v3

slide-11
SLIDE 11

6

Gφ = (V , E) G' = (V', E' )

Canonical structures

Canonical structure Gφ of a Conjunctive Query φ has

  • variables as nodes
  • tuples (x1, …, xn) ∈ Ri


for all atomic sub-formulas Ri (x1, …, xn) of φ

Gφ = (V , E) E.g.: φ = ∃x ∃y ∃z . (E(x, y) ⋀ E(y, z) ⋀ E(x, z)) x y z

Fact 1: Gφ ⊨ φ Fact 2: h(Gφ) ⊨ φ

v1 v2 v3

slide-12
SLIDE 12

6

Gφ = (V , E) G' = (V', E' )

Canonical structures

Canonical structure Gφ of a Conjunctive Query φ has

  • variables as nodes
  • tuples (x1, …, xn) ∈ Ri


for all atomic sub-formulas Ri (x1, …, xn) of φ

Gφ = (V , E) E.g.: φ = ∃x ∃y ∃z . (E(x, y) ⋀ E(y, z) ⋀ E(x, z)) x y z

Fact 1: Gφ ⊨ φ Fact 2: h(Gφ) ⊨ φ

Fact 3:
 G'' ⊨ φ iff ∃ h: Gφ ⟶ G ''

v1 v2 v3

slide-13
SLIDE 13

Gφ = (V , E) G' = (V', E' ) Gφ = (V , E) E.g.: φ (x) = ∃y ∃z . (E(x, y) ⋀ E(y, z) ⋀ E(x, z)) x y z

7

Evaluation via homomorphisms

  • Lemma. Tie evaluation of a CQ φ(x1, …, xn) on S' returns the set


φ(S' ) = { (h(x1), …, h(xn) ) | h : Gφ ⟶ S' } v1 v2 v3

slide-14
SLIDE 14

Gφ = (V , E) G' = (V', E' ) Gφ = (V , E) E.g.: φ (x) = ∃y ∃z . (E(x, y) ⋀ E(y, z) ⋀ E(x, z)) x y z

7

Evaluation via homomorphisms

  • Lemma. Tie evaluation of a CQ φ(x1, …, xn) on S' returns the set


φ(S' ) = { (h(x1), …, h(xn) ) | h : Gφ ⟶ S' }

Question: Which are the 
 homomorphisms Gφ ⟶ G' ? What is the result of φ(G' ) ?

v1 v2 v3

slide-15
SLIDE 15

8

Evaluation via homomorphisms

Input: A CQ φ(x1, …, xn), a graph G, a tuple (a1, …, an) Output: Is (a1, …, an) ∈ φ(G) ? Gφφ= (V , E) G' = (V', E' ) v1 v2 v3 x y z

  • Tieorem. Evaluation of CQ is in NP (combined complexity)
slide-16
SLIDE 16

8

Evaluation via homomorphisms

Input: A CQ φ(x1, …, xn), a graph G, a tuple (a1, …, an) Output: Is (a1, …, an) ∈ φ(G) ?

Ideas?

Gφφ= (V , E) G' = (V', E' ) v1 v2 v3 x y z

  • Tieorem. Evaluation of CQ is in NP (combined complexity)
slide-17
SLIDE 17

8

Evaluation via homomorphisms

  • 1. Guess h: Gφ ⟶ G
  • 2. Check that it is a homomorphism
  • 3. Output YES if (h(x1), …, h(xn)) = (a1, …, an); NO otherwise.

Input: A CQ φ(x1, …, xn), a graph G, a tuple (a1, …, an) Output: Is (a1, …, an) ∈ φ(G) ?

Ideas?

Gφφ= (V , E) G' = (V', E' ) v1 v2 v3 x y z

  • Tieorem. Evaluation of CQ is in NP (combined complexity)
slide-18
SLIDE 18

9

Evaluation via homomorphisms

  • Tieorem. Evaluation of CQ is NP-complete (combined complexity)
slide-19
SLIDE 19

9

Evaluation via homomorphisms

K3

Input: A graph G Output: Can we assign a colour from {R,G,B} to each node
 so that adjacent nodes have always different colours ? = Is there a homomorphism from G to K3 ?

NP-complete problem: 3-COLORABILITY

  • Tieorem. Evaluation of CQ is NP-complete (combined complexity)
slide-20
SLIDE 20

9

Evaluation via homomorphisms

K3

Input: A graph G Output: Can we assign a colour from {R,G,B} to each node
 so that adjacent nodes have always different colours ? = Is there a homomorphism from G to K3 ?

NP-complete problem: 3-COLORABILITY Reduction 3COL ⤳ CQ-EVAL: 1. Given G, build a CQ φ such that Gφ = G.

  • 2. Test if () ∈ φ(K3).
  • Tieorem. Evaluation of CQ is NP-complete (combined complexity)
slide-21
SLIDE 21

10

Monotonicity and preservation theorems

  • Lemma. Every CQ is monotone:

S ⊆ S ' implies φ(S ) ⊆ φ(S ')

slide-22
SLIDE 22

10

Monotonicity and preservation theorems

  • Lemma. Every CQ is monotone:

S ⊆ S ' implies φ(S ) ⊆ φ(S ')

Proof: φ(S ) = { (h(x1), …, h(xn) ) | h : Gφ ⟶ S } ⊆ { (h' (x1), …, h' (xn) ) | h' : Gφ ⟶ S' } 
 = φ(S' )

slide-23
SLIDE 23

10

Monotonicity and preservation theorems

  • Lemma. Every CQ is monotone:

S ⊆ S ' implies φ(S ) ⊆ φ(S ')

Proof: φ(S ) = { (h(x1), …, h(xn) ) | h : Gφ ⟶ S } ⊆ { (h' (x1), …, h' (xn) ) | h' : Gφ ⟶ S' } 
 = φ(S' )

“Tie relation R has at most 2 elements” ∉ CQ “Tiere is a node connected to every other node” ∉ CQ “Tie radius of the graph is 5” ∉ CQ

slide-24
SLIDE 24

11

Monotonicity and preservation theorems

  • Tieorem. If an FO query φ is monotone

then φ ∈ UCQ

[Rossman '08]

slide-25
SLIDE 25

11

Monotonicity and preservation theorems

  • Tieorem. If an FO query φ is monotone

then φ ∈ UCQ

[Rossman '08] Finite unions of CQs ≈ ∃ ⋀ ⋁ fragment of FO

slide-26
SLIDE 26

11

Monotonicity and preservation theorems

  • Tieorem. If an FO query φ is monotone

then φ ∈ UCQ

[Rossman '08] Finite unions of CQs ≈ ∃ ⋀ ⋁ fragment of FO Equally expressive, but
 UCQ are less succinct

slide-27
SLIDE 27

11

Monotonicity and preservation theorems

  • One example of the few properties which still hold on finite structures.
  • Proof in the finite is difficult and independent.
  • Tieorem. If an FO query φ is monotone

then φ ∈ UCQ

[Rossman '08] Finite unions of CQs ≈ ∃ ⋀ ⋁ fragment of FO Equally expressive, but
 UCQ are less succinct

slide-28
SLIDE 28

12

Tie satisfiability problem for CQ is decidable…

Static analysis with CQs

Question: What is the algorithm for CQ-SAT? What is the complexity?

slide-29
SLIDE 29

12

Tie satisfiability problem for CQ is decidable…

Static analysis with CQs

Question: What is the algorithm for CQ-SAT? What is the complexity? Answer: CQs are always satisfiable by their canonical structure! Gφ ⊨ φ

slide-30
SLIDE 30

13

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) ⊆ ψ(S) holds for every structure S ? problem: CQ-CONTAINMENT

slide-31
SLIDE 31

13

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) ⊆ ψ(S) holds for every structure S ? problem: CQ-CONTAINMENT

  • Tieorem. Tie containment problem for CQ is NP-complete
slide-32
SLIDE 32

13

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) ⊆ ψ(S) holds for every structure S ? problem: CQ-CONTAINMENT

  • Tieorem. Tie containment problem for CQ is NP-complete

Question: Is this combined or data complexity?

slide-33
SLIDE 33

13

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) ⊆ ψ(S) holds for every structure S ? problem: CQ-CONTAINMENT

  • Tieorem. Tie containment problem for CQ is NP-complete

Question: Is this combined or data complexity? Answer: None!

slide-34
SLIDE 34

13

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) ⊆ ψ(S) holds for every structure S ? problem: CQ-CONTAINMENT

  • Tieorem. Tie containment problem for CQ is NP-complete

Question: Is this combined or data complexity? Answer: None!

slide-35
SLIDE 35

13

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) ⊆ ψ(S) holds for every structure S ? problem: CQ-CONTAINMENT

  • Tieorem. Tie containment problem for CQ is NP-complete

Question: Is this combined or data complexity? Answer: None! Why?

slide-36
SLIDE 36

14

Static analysis with CQs

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

slide-37
SLIDE 37

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

slide-38
SLIDE 38

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S }

slide-39
SLIDE 39

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S } { (g(y1), …, g(yn) ) | g : Gψ ⟶ S }

slide-40
SLIDE 40

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S }

If there is h: Gφ ⟶ S 
 Tien there is g: Gψ ⟶ S such that h(x1, …, xn) = g(y1, …, ym)

{ (g(y1), …, g(yn) ) | g : Gψ ⟶ S }

slide-41
SLIDE 41

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S }

If there is h: Gφ ⟶ S 
 Tien there is g: Gψ ⟶ S such that h(x1, …, xn) = g(y1, …, ym) Take S = Gφ and h = identity.

{ (g(y1), …, g(yn) ) | g : Gψ ⟶ S }

slide-42
SLIDE 42

[⟸] Consider S and (v1,…,vn) ∈ φ(S). Tien, (v1,…,vn) = (h(x1), …, h(xn)) for some h : Gφ ⟶ S.

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S }

If there is h: Gφ ⟶ S 
 Tien there is g: Gψ ⟶ S such that h(x1, …, xn) = g(y1, …, ym) Take S = Gφ and h = identity.

{ (g(y1), …, g(yn) ) | g : Gψ ⟶ S }

slide-43
SLIDE 43

[⟸] Consider S and (v1,…,vn) ∈ φ(S). Tien, (v1,…,vn) = (h(x1), …, h(xn)) for some h : Gφ ⟶ S.

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S }

If there is h: Gφ ⟶ S 
 Tien there is g: Gψ ⟶ S such that h(x1, …, xn) = g(y1, …, ym) Take S = Gφ and h = identity.

{ (g(y1), …, g(yn) ) | g : Gψ ⟶ S }

Since g(y1, …, yn) = (x1, …, xn), then (v1, …, vn) = h(x1, …, xn) = h(g(y1, …, yn)).

slide-44
SLIDE 44

[⟸] Consider S and (v1,…,vn) ∈ φ(S). Tien, (v1,…,vn) = (h(x1), …, h(xn)) for some h : Gφ ⟶ S.

14

Static analysis with CQs

[⟹] Suppose ∀ S φ(S) ⊆ ψ(S)

  • 1. n = m
  • 2. Tiere is g: Gψ ⟶ Gφ
  • 3. g(yi) = xi for all i

φ(x1, …, xn) is contained in ψ(y1, …, ym) iff

{ (h(x1), …, h(xn) ) | h : Gφ ⟶ S }

If there is h: Gφ ⟶ S 
 Tien there is g: Gψ ⟶ S such that h(x1, …, xn) = g(y1, …, ym) Take S = Gφ and h = identity.

{ (g(y1), …, g(yn) ) | g : Gψ ⟶ S }

Since g(y1, …, yn) = (x1, …, xn), then (v1, …, vn) = h(x1, …, xn) = h(g(y1, …, yn)). h ° g is a homomorphism from Gψ to S. Hence, (v1, …, vn) ∈ ψ(S).

slide-45
SLIDE 45

15

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) = ψ(S) holds for every S ? (we write “φ≣ψ”) problem: CQ-EQUIVALENCE

slide-46
SLIDE 46

15

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) = ψ(S) holds for every S ? (we write “φ≣ψ”) problem: CQ-EQUIVALENCE

  • Tieorem. Tie equivalence problem for CQ is NP-complete
slide-47
SLIDE 47

15

Static analysis with CQs

Input: Two CQs φ, ψ Output: Does φ(S) = ψ(S) holds for every S ? (we write “φ≣ψ”) problem: CQ-EQUIVALENCE

  • Tieorem. Tie equivalence problem for CQ is NP-complete
  • 1. n = m
  • 2a. Tiere is g: Gψ ⟶ Gφ
  • 2b. Tiere is h: Gφ ⟶ Gψ
  • 3a. g(yi) = xi for all i
  • 3b. h(xi) = yi for all i

φ≣ψ iff

slide-48
SLIDE 48

15

Static analysis with CQs

Amounts to testing if Gφ and Gψ are hom-equivalent (homomorphisms in both senses) Input: Two CQs φ, ψ Output: Does φ(S) = ψ(S) holds for every S ? (we write “φ≣ψ”) problem: CQ-EQUIVALENCE

  • Tieorem. Tie equivalence problem for CQ is NP-complete
  • 1. n = m
  • 2a. Tiere is g: Gψ ⟶ Gφ
  • 2b. Tiere is h: Gφ ⟶ Gψ
  • 3a. g(yi) = xi for all i
  • 3b. h(xi) = yi for all i

φ≣ψ iff

slide-49
SLIDE 49

16

Static analysis with CQs

Query optimisation: Can I simplify the query?

slide-50
SLIDE 50

16

Static analysis with CQs

Input: A CQ φ Output: Is there a smaller CQ ψ such that ψ≣φ ? problem: CQ-MINIMIZATION smaller = with less number of atoms

Query optimisation: Can I simplify the query?

slide-51
SLIDE 51

17

Static analysis with CQs

Input: A CQ φ Output: Is there a smaller CQ ψ such that ψ≣φ ? problem: CQ-MINIMIZATION

slide-52
SLIDE 52

17

Static analysis with CQs

Input: A CQ φ Output: Is there a smaller CQ ψ such that ψ≣φ ? problem: CQ-MINIMIZATION

  • Tieorem. Tie minimization problem for CQ is NP-complete
slide-53
SLIDE 53

17

Static analysis with CQs

Input: A CQ φ Output: Is there a smaller CQ ψ such that ψ≣φ ? problem: CQ-MINIMIZATION Amounts to testing if there is a smaller structure hom-equivalent to Gφ ≈ testing if there is a non-injective endomorphism
 g: Gφ ⟶ Gφ Tie smallest structure hom-equivalent to S is called the core of S, and it is unique.

  • Tieorem. Tie minimization problem for CQ is NP-complete
slide-54
SLIDE 54

18

Static analysis with CQs

Question: • Is φ = ∃ x,y,z R(x,y) ∧ R(x,z) ∧ S(z,z) ∧ S(z,y) minimal?

  • What is its minimal equivalent query?

Answer:

slide-55
SLIDE 55

18

Static analysis with CQs

Question: • Is φ = ∃ x,y,z R(x,y) ∧ R(x,z) ∧ S(z,z) ∧ S(z,y) minimal?

  • What is its minimal equivalent query?

Answer: Gφ x y z R R S S

slide-56
SLIDE 56

18

Static analysis with CQs

Question: • Is φ = ∃ x,y,z R(x,y) ∧ R(x,z) ∧ S(z,z) ∧ S(z,y) minimal?

  • What is its minimal equivalent query?

Answer: core(Gφ) x z R S hom Gφ x y z R R S S

slide-57
SLIDE 57

18

Static analysis with CQs

Question: • Is φ = ∃ x,y,z R(x,y) ∧ R(x,z) ∧ S(z,z) ∧ S(z,y) minimal?

  • What is its minimal equivalent query?

Answer: core(Gφ) x z R S hom Gφ x y z R R S S

slide-58
SLIDE 58

18

Static analysis with CQs

Question: • Is φ = ∃ x,y,z R(x,y) ∧ R(x,z) ∧ S(z,z) ∧ S(z,y) minimal?

  • What is its minimal equivalent query?

Answer: No! ψ = ∃ x,z R(x,z) ∧ S(z,z) is the minimal query s.t. φ ≣ ψ core(Gφ) x z R S hom Gφ x y z R R S S

slide-59
SLIDE 59

19

Adding functional dependencies

slide-60
SLIDE 60

19

Adding functional dependencies

key constraints like "column SSN determines column Name in the table Employees" (component i) (component j) (relation)

e.g.

slide-61
SLIDE 61

20

Adding functional dependencies

∀ x1,…,xn,y1,…,yn . R(x1,…,xn) ∧ R(y1,…,yn) ∧ (xi = yi) ⇒ (xj = yj) "R[i⟶j]" : in relation R the i-th component determines the j-th component A unary functional dependency is a sentence of the form

slide-62
SLIDE 62

20

Adding functional dependencies

Agent Name Drives 007 James Bond Aston Martin 200 Mr Smith Cadillac 201 Mrs Smith Mercedes 3 Jason Bourne BMW

Example: In the following relation we may enforce the functional dependency

𝜹 = ∀ x, y, z, x', y', z' R(x, y, z) ∧ R(x', y', z' ) ∧ ( x = x' ) ⇒ ( y = y' )

∀ x1,…,xn,y1,…,yn . R(x1,…,xn) ∧ R(y1,…,yn) ∧ (xi = yi) ⇒ (xj = yj) "R[i⟶j]" : in relation R the i-th component determines the j-th component A unary functional dependency is a sentence of the form

slide-63
SLIDE 63

21

Adding functional dependencies

∀ x1,…,xn,y1,…,yn . R(x1,…,xn) ∧ R(y1,…,yn) ∧ (xi = yi) ⇒ (xj = yj) "R[i⟶j]" : in relation R the i-th component determines the j-th component A unary functional dependency is a sentence of the form

slide-64
SLIDE 64

21

Adding functional dependencies

A structure S verifies a set of UFD {φ1, . . . ,φn} if S ⊨ φ1 ∧ · · · ∧ φn.

∀ x1,…,xn,y1,…,yn . R(x1,…,xn) ∧ R(y1,…,yn) ∧ (xi = yi) ⇒ (xj = yj) "R[i⟶j]" : in relation R the i-th component determines the j-th component A unary functional dependency is a sentence of the form

slide-65
SLIDE 65

22

All the previous problems:


  • CQ-CONTAINMENT
  • CQ-EQUIVALENCE
  • CQ-MINIMIZATION

remain in NP if we further restrict finite structures
 so as to satisfy any set of functional dependencies

Adding functional dependencies

∀ x1,…,xn,y1,…,yn . R(x1,…,xn) ∧ R(y1,…,yn) ∧ (xi = yi) ⇒ (xj = yj) "R[i⟶j]" : in relation R the i-th component determines the j-th component A unary functional dependency is a sentence of the form

slide-66
SLIDE 66

22

All the previous problems:


  • CQ-CONTAINMENT
  • CQ-EQUIVALENCE
  • CQ-MINIMIZATION

remain in NP if we further restrict finite structures
 so as to satisfy any set of functional dependencies

Adding functional dependencies

Modify the canonical structure Gφ …

∀ x1,…,xn,y1,…,yn . R(x1,…,xn) ∧ R(y1,…,yn) ∧ (xi = yi) ⇒ (xj = yj) "R[i⟶j]" : in relation R the i-th component determines the j-th component A unary functional dependency is a sentence of the form

slide-67
SLIDE 67

23

Adding functional dependencies

CQ φ = R2(x, y, z) ∧ R2(x, y', z') ∧ R1(z, w) ∧ R1(z', w' )
 under functional dependencies F={ R1[1⟶2], R2: [1⟶3] }

x y z y' z' w' w

slide-68
SLIDE 68

23

Adding functional dependencies

CQ φ = R2(x, y, z) ∧ R2(x, y', z') ∧ R1(z, w) ∧ R1(z', w' )
 under functional dependencies F={ R1[1⟶2], R2: [1⟶3] }

x y z y' z' w' w

slide-69
SLIDE 69

23

Adding functional dependencies

CQ φ = R2(x, y, z) ∧ R2(x, y', z') ∧ R1(z, w) ∧ R1(z', w' )
 under functional dependencies F={ R1[1⟶2], R2: [1⟶3] }

y ' z' y z w x w'

slide-70
SLIDE 70

23

Adding functional dependencies

CQ φ = R2(x, y, z) ∧ R2(x, y', z') ∧ R1(z, w) ∧ R1(z', w' )
 under functional dependencies F={ R1[1⟶2], R2: [1⟶3] }

y ' z' y z w x w'

slide-71
SLIDE 71

23

Adding functional dependencies

CQ φ = R2(x, y, z) ∧ R2(x, y', z') ∧ R1(z, w) ∧ R1(z', w' )
 under functional dependencies F={ R1[1⟶2], R2: [1⟶3] }

y ' z' w y z x

slide-72
SLIDE 72

23

Adding functional dependencies

CQ φ = R2(x, y, z) ∧ R2(x, y', z') ∧ R1(z, w) ∧ R1(z', w' )
 under functional dependencies F={ R1[1⟶2], R2: [1⟶3] }

y ' z' w y z x

= chaseF(Gφ) (the chased canonical structure)

  • chaseF(Gφ) is unique and 


can be constructed in polynomial time

slide-73
SLIDE 73

24

Adding functional dependencies

φ ∈ CQ FD's F={fd1, …, fdn} chase chaseF(φ) ∈ CQ

slide-74
SLIDE 74

24

Adding functional dependencies

φ ∈ CQ FD's F={fd1, …, fdn} chase chaseF(φ) ∈ CQ Tie static analysis problems restricted to FD's can now be also shown in NP

  • CQ-Containment
  • CQ-Equivalence
  • CQ-Minimization

φ ⊆F ψ iff chaseF(φ) ⊆ chaseF(ψ) φ ≣F ψ iff chaseF(φ) ≣ chaseF(ψ) iff chaseF(φ) is minimal φ is minimal wrt 
 structures verifying F

slide-75
SLIDE 75

25

Acyclic CQ’s : Definition

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

slide-76
SLIDE 76

25

Acyclic CQ’s : Definition

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

underlying undirected graph is acyclic

slide-77
SLIDE 77

25

Acyclic CQ’s : Definition

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

underlying undirected graph is acyclic

slide-78
SLIDE 78

25

Acyclic CQ’s : Definition

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

underlying undirected graph is acyclic

acyclic

slide-79
SLIDE 79

25

Acyclic CQ’s : Definition

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

underlying undirected graph is acyclic

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

z t y x

acyclic

slide-80
SLIDE 80

25

Acyclic CQ’s : Definition

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

underlying undirected graph is acyclic

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

z t y x

acyclic non acyclic

slide-81
SLIDE 81

26

Acyclic CQ’s

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

slide-82
SLIDE 82

26

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like On general structures: a CQ φ is acyclic if it has a join tree φ(ȳ) = ∃z ̄ . R1(z ̄1) ⋀ … ⋀ Rm(z ̄m)

slide-83
SLIDE 83

26

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like On general 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 st:

  • 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

slide-84
SLIDE 84

26

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like On general 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 st:

  • 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.

slide-85
SLIDE 85

26

Acyclic CQ’s

On graphs: CQ φ is acyclic if Gφ is tree-like On general 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 st:

  • 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. Alternatively, if its canonical hyper-graph is α-acyclic.

slide-86
SLIDE 86

27

Acyclic CQ’s

φ(x,y) = ∃z . E(x,z) ⋀ E(z,t) ⋀ E(y,z) E(x,z) E(z,t) E(y,z) join tree S(z,t) S(x,z) R(x,y,z) T(z) T(x) S(z,t) S(x,z) R(x,y,z) T(z) T(x) not a join tree a join tree φ = ∃x,y,z,t . R(x,y,z) ⋀ S(z,t) ⋀ S(x,z) ⋀ T(z) ⋀ T(x)

slide-87
SLIDE 87

28

Acyclic CQ’s

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

[Yannakakis]

Tie 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