Fundamentos lgicos de bases de datos (Logical foundations of - - PowerPoint PPT Presentation

fundamentos l gicos de bases de datos logical foundations
SMART_READER_LITE
LIVE PREVIEW

Fundamentos lgicos de bases de datos (Logical foundations of - - PowerPoint PPT Presentation

ECI 2015 Day 4: CQ Buenos Aires Fundamentos lgicos de bases de datos (Logical foundations of databases) Diego Figueira Gabriele Puppis CNRS LaBRI Trading expressiveness for e ffi ciency expressiveness efficiency


slide-1
SLIDE 1

Fundamentos lógicos de bases de datos

∀∃ ¬

ECI 2015 Buenos Aires

CNRS LaBRI Diego Figueira Gabriele Puppis

(Logical foundations of databases)

Day 4: CQ

slide-2
SLIDE 2

2

Trading expressiveness for efficiency

expressiveness efficiency

Alternation of quantifiers significantly affects complexity (recall that evaluation of QBF is PSPACE-complete: ∀x ∃y ∀z ∃w … φ). 
 What happens if we disallow ∀ and ¬ ?

slide-3
SLIDE 3

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

3

Tie class NP

slide-4
SLIDE 4

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

3

Tie class NP

⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring)

slide-5
SLIDE 5

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

3

Tie class NP

⊆ NP ⊆

Examples:

  • 3-COLORABILITY: Given a graph G, can we assign a colour from {R,G,B} to each node


so that adjacent nodes have always different colours ?


  • SAT: Given a propositional formula, e.g. (p ⋁ ¬q ⋁ r) ⋀ (¬p ⋁ s ) ⋀ (¬s ⋁ ¬p),


can we assign a truth value to each variable so that the formula becomes true ?


  • MONEY-CHANGE: Given an amount of money A and a set of coins {B1, …, Bn},


can we find a subset S ⊆ {B1, …, Bn} such that ∑ S = A ?

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring)

slide-6
SLIDE 6

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

4

Tie class NP

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring) ⊆ NP ⊆

slide-7
SLIDE 7

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

4

Tie class NP

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring) ⊆ NP ⊆

Initial configuration Final
 configuration

slide-8
SLIDE 8

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

4

Tie class NP

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring) ⊆ NP ⊆

Final
 configuration Final
 configuration Initial configuration Final
 configuration

slide-9
SLIDE 9

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

4

Tie class NP

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring) ⊆ NP ⊆

Final
 configuration Final
 configuration Non-deterministic transitions Initial configuration Final
 configuration

slide-10
SLIDE 10

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

4

Tie class NP

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring) ⊆ NP ⊆

Final
 configuration Final
 configuration Non-deterministic transitions Many paths, each has length
 bounded by a polynomial Initial configuration Final
 configuration

slide-11
SLIDE 11

LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME

4

Tie class NP

NP = Problems whose solutions can be witnessed by a certificate
 to be guessed and checked in polynomial time (e.g. a colouring) ⊆ NP ⊆

Final
 configuration Final
 configuration Non-deterministic transitions A solution exists if there is at least a successful path. Many paths, each has length
 bounded by a polynomial Initial configuration Final
 configuration

slide-12
SLIDE 12

5

Question

Consider:

Positive FO = FO without ∀,¬

E.g. φ = ∃ x ∃ y ∃ z . (E(x, y) ⋁ E(y, z)) ⋀ ( y=z ⋁ E(x, z)) What is the complexity of evaluating Positive FO on graphs ?

slide-13
SLIDE 13

5

Question

Consider:

Positive FO = FO without ∀,¬

E.g. φ = ∃ x ∃ y ∃ z . (E(x, y) ⋁ E(y, z)) ⋀ ( y=z ⋁ E(x, z)) What is the complexity of evaluating Positive FO on graphs ?

Solution

Tiis is in NP: Given φ and G=(V, E) it suffices to guess a binding α : { x, y, z, … } → V 
 and then verify that the formula holds.

slide-14
SLIDE 14

6

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-15
SLIDE 15

6

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-16
SLIDE 16

6

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-17
SLIDE 17

7

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-18
SLIDE 18

8

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-19
SLIDE 19

9

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

Canonical structures

Canonical structure Sφ of a Conjunctive Query φ has

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


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

slide-20
SLIDE 20

9

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

Canonical structures

Canonical structure Sφ 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-21
SLIDE 21

9

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

Canonical structures

Canonical structure Sφ 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-22
SLIDE 22

9

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

Canonical structures

Canonical structure Sφ 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-23
SLIDE 23

9

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

Canonical structures

Canonical structure Sφ 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 ’’ ⊨ φ implies ∃ h: Gφ ⟶ G ’’

v1 v2 v3

slide-24
SLIDE 24

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

10

Evaluation via homomorphisms

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


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

slide-25
SLIDE 25

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

10

Evaluation via homomorphisms

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


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

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

v1 v2 v3

slide-26
SLIDE 26

11

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-27
SLIDE 27

11

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-28
SLIDE 28

11

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-29
SLIDE 29

12

Evaluation via homomorphisms

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

12

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-31
SLIDE 31

12

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 () ∈ φ(G).
  • Tieorem. Evaluation of CQ is NP-complete (combined complexity)
slide-32
SLIDE 32

13

Monotonicity and preservation theorems

  • Lemma. Every CQ is monotone:

S ⊆ S ’ implies φ(S ) ⊆ φ(S ’)

slide-33
SLIDE 33

13

Monotonicity and preservation theorems

  • Lemma. Every CQ is monotone:

S ⊆ S ’ implies φ(S ) ⊆ φ(S ’)

Proof: by closure under homomorphisms.

slide-34
SLIDE 34

13

Monotonicity and preservation theorems

  • Lemma. Every CQ is monotone:

S ⊆ S ’ implies φ(S ) ⊆ φ(S ’)

Proof: by closure under homomorphisms.

“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-35
SLIDE 35

14

Monotonicity and preservation theorems

  • Tieorem. If an FO query φ is monotone

then φ ∈ UCQ

[Rossman '08]

slide-36
SLIDE 36

14

Monotonicity and preservation theorems

  • Tieorem. If an FO query φ is monotone

then φ ∈ UCQ

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

slide-37
SLIDE 37

14

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-38
SLIDE 38

14

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-39
SLIDE 39

15

Tie satisfiability problem for CQ is decidable…

Static analysis with CQs

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

slide-40
SLIDE 40

15

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-41
SLIDE 41

16

Static analysis with CQs

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

slide-42
SLIDE 42

16

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-43
SLIDE 43

16

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-44
SLIDE 44

16

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-45
SLIDE 45

16

  • 1. n = m
  • 2. Tiere is g: Sψ ⟶ Sφ
  • 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-46
SLIDE 46

16

  • 1. n = m
  • 2. Tiere is g: Sψ ⟶ Sφ
  • 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-47
SLIDE 47

17

Static analysis with CQs

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

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

slide-48
SLIDE 48

17

Static analysis with CQs

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

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

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

slide-49
SLIDE 49

17

Static analysis with CQs

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

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

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

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

slide-50
SLIDE 50

17

Static analysis with CQs

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

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

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

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

slide-51
SLIDE 51

17

Static analysis with CQs

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

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

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

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

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

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

slide-52
SLIDE 52

17

Static analysis with CQs

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

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

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

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

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

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

slide-53
SLIDE 53

[⟸] Consider (v1,…,vm) ∈ φ(S )

17

Static analysis with CQs

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

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

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

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

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

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

slide-54
SLIDE 54

[⟸] Consider (v1,…,vm) ∈ φ(S )

17

Static analysis with CQs

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

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

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

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

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

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

(v1,…,vm) = (h(x1), …, h(xn))
 for some h : Sφ ⟶ S

slide-55
SLIDE 55

[⟸] Consider (v1,…,vm) ∈ φ(S )

17

Static analysis with CQs

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

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

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

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

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

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

(v1,…,vm) = (h(x1), …, h(xn))
 for some h : Sφ ⟶ S

Since g(y1, …, ym) = (x1, …, xn), then (v1, …, vm) = h(x1, …, xn) = h(g(y1, …, ym))

slide-56
SLIDE 56

[⟸] Consider (v1,…,vm) ∈ φ(S )

17

Static analysis with CQs

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

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

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

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

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

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

(v1,…,vm) = (h(x1), …, h(xn))
 for some h : Sφ ⟶ S

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

slide-57
SLIDE 57

18

Static analysis with CQs

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

slide-58
SLIDE 58

18

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-59
SLIDE 59

18

Static analysis with CQs

Amounts to testing if Gφ and Gψ are hom-equivalent (i.e. there are 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
slide-60
SLIDE 60

19

Static analysis with CQs

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

slide-61
SLIDE 61

19

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-62
SLIDE 62

19

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 non-injective endomorphism
 g: Gφ ⟶ Gφ 


  • r, equally, if the smallest graph hom-equivalent to Gφ is Gφ itself

(we say that Gφ is a core)

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

20

Adding functional dependencies

A functional dependency is a sentence of the form 𝜹 = ∀… R(x1, …, xn) ∧ R(x1’, …, xn’ ) ∧ ⋀j ( xij = xij’ ) ⇒ ( xi = xi’ )

slide-64
SLIDE 64

20

Adding functional dependencies

A functional dependency is a sentence of the form 𝜹 = ∀… R(x1, …, xn) ∧ R(x1’, …, xn’ ) ∧ ⋀j ( xij = xij’ ) ⇒ ( xi = xi’ )

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’ )

slide-65
SLIDE 65

20

Adding functional dependencies

A functional dependency is a sentence of the form 𝜹 = ∀… R(x1, …, xn) ∧ R(x1’, …, xn’ ) ∧ ⋀j ( xij = xij’ ) ⇒ ( xi = xi’ )

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’ ) 
 We ofuen abbreviate this with

R: 1 ⇾ 2

slide-66
SLIDE 66

21

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

A functional dependency (FD) is a sentence of the form F = ∀… R(x1, …, xn) ∧ R(x1’, …, xn’ ) ∧ ⋀j ( xij = xij’ ) ⇒ ( xi = xi’ )

slide-67
SLIDE 67

21

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

A functional dependency (FD) is a sentence of the form F = ∀… R(x1, …, xn) ∧ R(x1’, …, xn’ ) ∧ ⋀j ( xij = xij’ ) ⇒ ( xi = xi’ )

Modify the canonical structure Sφ …

slide-68
SLIDE 68

22

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

22

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-70
SLIDE 70

22

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

22

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-72
SLIDE 72

22

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-73
SLIDE 73

22

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

= Sφ (the chased canonical structure)

  • Sφ is unique and 


can be constructed in polynomial time

  • It is the “most general” constrained model of φ :


φ(S) = h(φ(Sφ)) for all S satisfying the funct. depend.

slide-74
SLIDE 74

23

Adding functional dependencies

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

slide-75
SLIDE 75

23

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