fundamentos l gicos de bases de datos logical foundations
play

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


  1. ECI 2015 Day 4: CQ Buenos Aires ∀∃ ¬ Fundamentos lógicos de bases de datos (Logical foundations of databases) Diego Figueira Gabriele Puppis CNRS LaBRI

  2. 
 Trading expressiveness for e ffi ciency expressiveness efficiency Alternation of quanti fi ers signi fi cantly a ff ects complexity (recall that evaluation of QBF is PSPACE-complete: ∀ x ∃ y ∀ z ∃ w … φ ). What happens if we disallow ∀ and ¬ ? 2

  3. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ 3

  4. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) 3

  5. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) 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 di ff erent 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 { B 1 , …, B n }, 
 can we fi nd a subset S ⊆ { B 1 , …, B n } such that ∑ S = A ? 3

  6. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) 4

  7. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) Initial con fi guration Final 
 con fi guration 4

  8. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) Initial con fi guration Final 
 con fi guration Final 
 con fi guration Final 
 con fi guration 4

  9. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) Initial con fi guration Non-deterministic transitions Final 
 con fi guration Final 
 con fi guration Final 
 con fi guration 4

  10. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) Initial con fi guration Non-deterministic transitions Many paths, each has length 
 bounded by a polynomial Final 
 con fi guration Final 
 con fi guration Final 
 con fi guration 4

  11. Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ NP ⊆ NP = Problems whose solutions can be witnessed by a certificate 
 to be guessed and checked in polynomial time (e.g. a colouring) Initial con fi guration Non-deterministic transitions Many paths, each has length 
 bounded by a polynomial Final 
 A solution exists if there is con fi guration at least a successful path. Final 
 con fi guration Final 
 con fi guration 4

  12. 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 ? 5

  13. 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 Ti is is in NP: Given φ and G =( V , E ) it su ffi ces to guess a binding α : { x , y , z , … } → V 
 and then verify that the formula holds. 5

  14. 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)” 6

  15. 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)” 6

  16. 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 6

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

  18. 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 ) 8

  19. Canonical structures Canonical structure S φ 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 ) 9

  20. Canonical structures Canonical structure S φ 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 ) 9

  21. Canonical structures Canonical structure S φ 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 ) 9

  22. Canonical structures Canonical structure S φ 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 ) 9

  23. Canonical structures Canonical structure S φ 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 ’’ ⊨ φ implies ∃ 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 ) 9

  24. 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 : S φ ⟶ 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 ) 10

  25. 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 : S φ ⟶ 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 ) 10

  26. 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 ) ? 11

  27. 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 ) ? 11

  28. 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. 11

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

Recommend


More recommend