ECI 2015 Day 4: CQ Buenos Aires ∀∃ ¬ Fundamentos lógicos de bases de datos (Logical foundations of databases) Diego Figueira Gabriele Puppis CNRS LaBRI
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
Ti e class NP LOGSPACE ⊆ PTIME PSPACE ⊆ EXPTIME ⊆ 3
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Evaluation via homomorphisms Ti eorem . Evaluation of CQ is NP-complete (combined complexity) 12
Recommend
More recommend