logical foundations of databases diego figueira gabriele
play

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


  1. day 3 ESSLLI 2016 Bolzano, Italy ∀∃ ¬ Logical foundations of databases Diego Figueira Gabriele Puppis CNRS LaBRI

  2. Recap • Active domain semantics and expressiveness: FO act =* RA • Undecidable problems (Halting ≤ Domino ≤ FO-Satis fi ability ≤ 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 Q ueries

  3. Conjunctive Q ueries Def. CQ = FO without ∀ ,¬, ⋁ Eg: φ ( x , y ) = ∃ z . (Parent( x , z ) ⋀ Parent( z , y )) Usual notation: “Grandparent(X,Y) : – Parent(X,Z), Parent(Z,Y)” 3

  4. Conjunctive Q ueries Def. CQ = FO without ∀ ,¬, ⋁ Normal form: “ ∃ x 1 , …, x n . φ ( x 1 , …, x n ) ” quanti fi er-free and no equalities! Eg: φ ( x , y ) = ∃ z . (Parent( x , z ) ⋀ Parent( z , y )) Usual notation: “Grandparent(X,Y) : – Parent(X,Z), Parent(Z,Y)” 3

  5. Conjunctive Q ueries Def. CQ = FO without ∀ ,¬, ⋁ Normal form: “ ∃ x 1 , …, x n . φ ( x 1 , …, x n ) ” quanti fi er-free and no equalities! Eg: φ ( x , y ) = ∃ z . (Parent( x , z ) ⋀ Parent( z , y )) Usual notation: “Grandparent(X,Y) : – Parent(X,Z), Parent(Z,Y)” It corresponds to positive It corresponds to “ π - σ - × ” RA queries “SELECT-FROM-WHERE” SQL queries Select ¡... ¡ π X ( σ Z (R 1 × ··· × R n )) From ¡... ¡ Where ¡Z no negation no negation or disjunction 3

  6. Homomorphisms Homomorphism between structures S =( V , R 1 , …, R n ) and S '=( V ', R 1 ', …, R n ') 
 is a function h : V ⟶ V ' such that ( x 1 , …, x n ) ∈ R i implies (h( x 1 ), …, h( x n )) ∈ R i ' S = ( V , R 1 , R 2 ) S' = ( V ', R 1 ' , R 2 ') 4

  7. Homomorphisms Homomorphism between structures S =( V , R 1 , …, R n ) and S '=( V ', R 1 ', …, R n ') 
 is a function h : V ⟶ V ' such that ( x 1 , …, x n ) ∈ R i implies (h( x 1 ), …, h( x n )) ∈ R i ' G' = ( V', E' ) G = ( V , E ) 5

  8. Canonical structures Canonical structure G φ of a Conjunctive Q uery φ has • variables as nodes • tuples ( x 1 , …, x n ) ∈ R i 
 for all atomic sub-formulas R i ( x 1 , …, x n ) of φ G' = ( V', E' ) G φ = ( V , E ) 6

  9. Canonical structures Canonical structure G φ of a Conjunctive Q uery φ has • variables as nodes • tuples ( x 1 , …, x n ) ∈ R i 
 for all atomic sub-formulas R i ( x 1 , …, x n ) of φ E.g.: φ = ∃ x ∃ y ∃ z . (E( x , y ) ⋀ E( y , z ) ⋀ E( x , z )) x z v 1 v 2 y v 3 G' = ( V', E' ) G φ = ( V G φ = ( V , E ) , E ) 6

  10. Canonical structures Canonical structure G φ of a Conjunctive Q uery φ has • variables as nodes • tuples ( x 1 , …, x n ) ∈ R i 
 for all atomic sub-formulas R i ( x 1 , …, x n ) of φ Fact 1: G φ ⊨ φ E.g.: φ = ∃ x ∃ y ∃ z . (E( x , y ) ⋀ E( y , z ) ⋀ E( x , z )) x z v 1 v 2 y v 3 G' = ( V', E' ) G φ = ( V G φ = ( V , E ) , E ) 6

  11. Canonical structures Canonical structure G φ of a Conjunctive Q uery φ has • variables as nodes • tuples ( x 1 , …, x n ) ∈ R i 
 for all atomic sub-formulas R i ( x 1 , …, x n ) of φ Fact 1: G φ ⊨ φ Fact 2: h( G φ ) ⊨ φ E.g.: φ = ∃ x ∃ y ∃ z . (E( x , y ) ⋀ E( y , z ) ⋀ E( x , z )) x z v 1 v 2 y v 3 G' = ( V', E' ) G φ = ( V G φ = ( V , E ) , E ) 6

  12. Canonical structures Canonical structure G φ of a Conjunctive Q uery φ has • variables as nodes • tuples ( x 1 , …, x n ) ∈ R i 
 for all atomic sub-formulas R i ( x 1 , …, x n ) of φ Fact 3: 
 Fact 1: G φ ⊨ φ Fact 2: h( G φ ) ⊨ φ G'' ⊨ φ i ff ∃ h: G φ ⟶ G '' E.g.: φ = ∃ x ∃ y ∃ z . (E( x , y ) ⋀ E( y , z ) ⋀ E( x , z )) x z v 1 v 2 y v 3 G' = ( V', E' ) G φ = ( V G φ = ( V , E ) , E ) 6

  13. Evaluation via homomorphisms Lemma . Ti e evaluation of a CQ φ ( x 1 , …, x n ) on S' returns the set 
 φ ( S' ) = { ( h( x 1 ), …, h( x n ) ) | h : G φ ⟶ S' } E.g.: φ ( x ) = ∃ y ∃ z . (E( x , y ) ⋀ E( y , z ) ⋀ E( x , z )) x z v 1 v 2 y v 3 G' = ( V', E' ) G φ = ( V G φ = ( V , E ) , E ) 7

  14. Evaluation via homomorphisms Lemma . Ti e evaluation of a CQ φ ( x 1 , …, x n ) on S' returns the set 
 φ ( S' ) = { ( h( x 1 ), …, h( x n ) ) | h : G φ ⟶ S' } Q uestion: Which are the 
 homomorphisms G φ ⟶ G' ? What is the result of φ ( G' ) ? E.g.: φ ( x ) = ∃ y ∃ z . (E( x , y ) ⋀ E( y , z ) ⋀ E( x , z )) x z v 1 v 2 y v 3 G' = ( V', E' ) G φ = ( V G φ = ( V , E ) , E ) 7

  15. Evaluation via homomorphisms Ti eorem . Evaluation of CQ is in NP (combined complexity) x z v 1 v 2 y v 3 G' = ( V', E' ) G φφ = ( V , E ) Input : A CQ φ ( x 1 , …, x n ), a graph G , a tuple ( a 1 , …, a n ) Output : Is ( a 1 , …, a n ) ∈ φ ( G ) ? 8

  16. Evaluation via homomorphisms Ti eorem . Evaluation of CQ is in NP (combined complexity) x z v 1 v 2 y v 3 G' = ( V', E' ) G φφ = ( V , E ) Input : A CQ φ ( x 1 , …, x n ), a graph G , a tuple ( a 1 , …, a n ) Ideas? Output : Is ( a 1 , …, a n ) ∈ φ ( G ) ? 8

  17. Evaluation via homomorphisms Ti eorem . Evaluation of CQ is in NP (combined complexity) x z v 1 v 2 y v 3 G' = ( V', E' ) G φφ = ( V , E ) Input : A CQ φ ( x 1 , …, x n ), a graph G , a tuple ( a 1 , …, a n ) Ideas? Output : Is ( a 1 , …, a n ) ∈ φ ( G ) ? 1. Guess h: G φ ⟶ G 2. Check that it is a homomorphism 3. Output YES if (h( x 1 ), …, h( x n )) = ( a 1 , …, a n ); NO otherwise. 8

  18. Evaluation via homomorphisms Ti eorem . Evaluation of CQ is NP-complete (combined complexity) 9

  19. Evaluation via homomorphisms Ti eorem . Evaluation of CQ is NP-complete (combined complexity) NP-complete problem: 3-COLORABILITY Input : A graph G Output : Can we assign a colour from { R , G , B } to each node 
 so that adjacent nodes have always di ff erent colours ? K 3 = Is there a homomorphism from G to K 3 ? 9

  20. Evaluation via homomorphisms Ti eorem . Evaluation of CQ is NP-complete (combined complexity) NP-complete problem: 3-COLORABILITY Input : A graph G Output : Can we assign a colour from { R , G , B } to each node 
 so that adjacent nodes have always di ff erent colours ? K 3 = Is there a homomorphism from G to K 3 ? Reduction 3COL ⤳ CQ-EVAL: 1. Given G, build a CQ φ such that G φ = G. 2. Test if () ∈ φ ( K 3 ). 9

  21. Monotonicity and preservation theorems Lemma. Every CQ is monotone : S ⊆ S ' implies φ ( S ) ⊆ φ ( S ') 10

  22. Monotonicity and preservation theorems Lemma. Every CQ is monotone : S ⊆ S ' implies φ ( S ) ⊆ φ ( S ') Proof: φ ( S ) = { (h( x 1 ), …, h( x n ) ) | h : G φ ⟶ S } ⊆ { (h ' ( x 1 ), …, h ' ( x n ) ) | h ' : G φ ⟶ S' } 
 = φ ( S' ) 10

  23. Monotonicity and preservation theorems Lemma. Every CQ is monotone : S ⊆ S ' implies φ ( S ) ⊆ φ ( S ') Proof: φ ( S ) = { (h( x 1 ), …, h( x n ) ) | h : G φ ⟶ S } ⊆ { (h ' ( x 1 ), …, h ' ( x n ) ) | h ' : G φ ⟶ S' } 
 = φ ( S' ) “ Ti e relation R has at most 2 elements” ∉ CQ “ Ti ere is a node connected to every other node” ∉ CQ “ Ti e radius of the graph is 5” ∉ CQ 10

  24. Monotonicity and preservation theorems Ti eorem. If an FO query φ is monotone then φ ∈ UCQ [Rossman '08] 11

  25. Monotonicity and preservation theorems Ti eorem. If an FO query φ is monotone then φ ∈ UCQ [Rossman '08] Finite unions of CQs ≈ ∃ ⋀ ⋁ fragment of FO 11

  26. Monotonicity and preservation theorems Ti eorem. If an FO query φ is monotone then φ ∈ UCQ [Rossman '08] Finite unions of CQs ≈ ∃ ⋀ ⋁ fragment of FO Equally expressive, but 
 UCQ are less succinct 11

  27. Monotonicity and preservation theorems Ti eorem. If an FO query φ is monotone then φ ∈ UCQ [Rossman '08] Finite unions of CQs ≈ ∃ ⋀ ⋁ fragment of FO Equally expressive, but 
 UCQ are less succinct • One example of the few properties which still hold on fi nite structures. • Proof in the fi nite is di ffi cult and independent. 11

  28. Static analysis with CQs Ti e satis fi ability problem for CQ is decidable… Q uestion: What is the algorithm for CQ-SAT? What is the complexity? 12

  29. Static analysis with CQs Ti e satis fi ability problem for CQ is decidable… Q uestion: What is the algorithm for CQ-SAT? What is the complexity? Answer: CQs are always satis fi able by their canonical structure! G φ ⊨ φ 12

  30. Static analysis with CQs problem: CQ-CONTAINMENT Input : Two CQs φ , ψ Output : Does φ ( S ) ⊆ ψ ( S ) holds for every structure S ? 13

  31. Static analysis with CQs problem: CQ-CONTAINMENT Input : Two CQs φ , ψ Output : Does φ ( S ) ⊆ ψ ( S ) holds for every structure S ? Ti eorem . Ti e containment problem for CQ is NP-complete 13

  32. Static analysis with CQs problem: CQ-CONTAINMENT Input : Two CQs φ , ψ Output : Does φ ( S ) ⊆ ψ ( S ) holds for every structure S ? Ti eorem . Ti e containment problem for CQ is NP-complete Q uestion: Is this combined or data complexity? 13

Recommend


More recommend