Presentation is loading. Please wait.

Presentation is loading. Please wait.

Answering Queries and Hypertree Decompositions Conjunctive Queries The problem BCQ: Instance: Question:Has Q a nonempty result over DB? Combined Complexity.

Similar presentations


Presentation on theme: "Answering Queries and Hypertree Decompositions Conjunctive Queries The problem BCQ: Instance: Question:Has Q a nonempty result over DB? Combined Complexity."— Presentation transcript:

1

2 Answering Queries and Hypertree Decompositions

3 Conjunctive Queries The problem BCQ: Instance: Question:Has Q a nonempty result over DB? Combined Complexity (Vardi ’82)

4 Problems Equivalent to BCQ Conjunctive Query Containment Query of Tuple Problem Constraint Satisfaction in AI Clause Subsumption in Theorem Proving

5 Example of CSP: Crossword Puzzle

6 Complexity of BCQ NP -complete in the general case (Chandra and Merlin ’77) NP -hard even for fixed database Polynomial if Q has an acyclic hypergraph (Yannakakis ’81) LOGCFL - complete (in NC 2 ) (G.L.S. ’98) Interest in larger tractable classes of CQS

7 Teaches(P,C,A) Parent(P,S) Acyclic queries ans  Enrolled(S,C’,R)  Teaches(P,C,A)  Parent(P,S) S C’ AR P C Enrolled(S,C’,R) Join Tree

8 Is this query hard? nsize of the database m number of atoms in the query Classical methods worst-case complexity: O(n m ) m = 11 ! Despite its apparence, this query is nearly acyclic It can be evaluated in O(m·n 2 · logn)

9 Nearly Acyclic Queries Bounded Treewidth (tw) a measure of the cyclicity of graphs for queries:tw(Q) = tw(G(Q)) For fixed k: checking tw(Q)  k Computing a tree decomposition linear time (Bodlaender’96) Answering BCQ of treewidth k: O(n k log n)(Chekuri & Rajaraman’97) LOGCFL -complete(G.L.S.’98)

10 Beyond treewidth Bounded Degree of Cyclicity Bounded Query width (Gyssens & Paredaens ’84) (Chekuri & Rajaraman ’97) Group together query atoms (hyperedges) instead of variables

11 Hypertree Decomposition We use p(X,Y,Z) partially p(X,Y,_), c(T,W) d(X,T) a(X,U,W), b(Y,V,W) c(Y,T) p(X,Y,Z), q(U,V,Z) p(X,Y,_), p(X,Y,_), c(T,W) We group atoms p(X,Y,Z), q(U,V,Z)

12 Reusing atoms We use p(X,Y,Z) partially p(X,Y,_), c(T,W) d(X,T) a(X,U,W), b(Y,V,W) c(Y,T) p(X,Y,Z), q(U,V,Z) p(X,Y,_), p(X,Y,_), c(T,W)

13 a(S,X,X’,C,F), b(S,Y,Y’,C’,F’) j(J,X,Y,X’,Y’) j(_,X,Y,_,_), c(C,C’,Z)j(_,_,_,X’,Y’), f(F,F’,Z’) d(X,Z)e(Y,Z)h(Y’,Z’)g(X’,Z’), f(F,_,Z’) p(B,X’,F)q(B’,X’,F)

14 Connectedness Condition a(S,X,X’,C,F), b(S,Y,Y’,C’,F’) j(J,X,Y,X’,Y’) j(_,X,Y,_,_), c(C,C’,Z) j(_,_,_,X’,Y’), f(F,F’,Z’) d(X,Z)e(Y,Z)h(Y’,Z’) g(X’,Z’), f(F,_,Z’) p(B,X’,F)q(B’,X’,F)

15 Special Condition a(S,X,X’,C,F), b(S,Y,Y’,C’,F’) j(J,X,Y,X’,Y’) j(_,X,Y,_,_), c(C,C’,Z)j(_,_,_,X’,Y’), f(F,F’,Z’) d(X,Z)e(Y,Z)h(Y’,Z’)g(X’,Z’), f(F,_,Z’) p(B,X’,F)q(B’,X’,F) Each variable that disappeared at some vertex v Does not reappear in the subtrees rooted at v JXY

16 Special Condition a(S,X,X’,C,F), b(S,Y,Y’,C’,F’) j(J,X,Y,X’,Y’) j(_,X,Y,_,_), c(C,C’,Z)j(_,_,_,X’,Y’), f(F,F’,Z’) d(X,Z)e(Y,Z) h(Y’,Z’)g(X’,Z’), f(F,_,Z’) p(B,X’,F)q(B’,X’,F) Each variable that disappeared at some vertex v Does not appear in the subtrees rooted at v JXY

17 Positive Results on Hypertree Decompositions For each query Q, hw(Q)  qw(Q) In some cases, hw(Q) < qw(Q) For fixed k, deciding whether hw(Q)  k is in polynomial time (LOGCFL) Computing hypertree decompositions is feasible in polynomial time (for fixed k)

18 Evaluating queries having bounded hypertree width k fixed Given: a database db a query Q over db such that hw(Q)  k a width k hypertree decomposition of Q Deciding whether Q(db) is not empty is in O(n k+1 log n) and complete for LOGCFL Computing Q(db) is feasible in output-polynomial time

19 Comparison results Hypertree Decomposition Hinge Decomposition + Tree Clustering Cycle Hypercutset Tree Clustering w*  treewidth Cycle Cutset Hinge Decomposition Biconnected Components

20 Characterizations of Hypertree width Is hypertree width A natural concept? A natural generalization of hypergraph acyclicity? Are there nice characterizations In terms of logic? In terms of games? Yes !

21 Characterizations of Hypertree width Logical characterization: Loosely guarded logic Game characterization: The robber and marshals game

22 Guarded Formulas Guard atom: k-guarded Formulas (loosely guarded): k-guard GF(FO), GF k (FO) are well-studied fragments of FO (Van Benthem’97, Gradel’99)

23 Logical Characterization of HW Theorem: From this general result, we also get a nice logical characterization of acyclic queries: Corollary:

24 An Example p(X,Y,Z) q(X,Y,T) s(T,W) r(Y,Z,U) Is acyclic: Indeed, there exists an equivalent guarded formula: Guard Guarded subformula

25 An Example p(X,Y,Z) q(X,Y,T) s(T,W) r(Y,Z,U) Is acyclic: Indeed, there exists an equivalent guarded formula: Guard Guarded subformula

26 Game characterization: Robber and Marshals A robber and k marshals play the game on a hypergraph The marshals have to capture the robber The robber tries to elude her capture, by running arbitrarily fast on the vertices of the hypergraph

27 Robbers and Marshals: the rules Each marshal stays on an edge of the hypergraph and controls all of its vertices at once The robber can go from a vertex to another vertex running along the edges, but she cannot pass through vertices controlled by some marshal The marshals win the game if they are able to monotonically shrink the moving space of the robber, and thus eventually capture her Consequently, the robber wins if she can go back to some vertex previously controlled by marshals

28 Step 0: the empty hypergraph V PR S XY ZTU W

29 V Step 1: first move of the marshals V PR S XY ZTU W

30 V PR S XY ZTU W

31 Step 2a: shrinking the space V PR S XY ZTU W

32 V PR S XY ZTU W

33 V PR S XY ZTU W

34 The capture V PR S XY ZTU W

35 V A different robber’s choice V PR S XY ZTU W

36 V Step 2b: the capture V PR S XY ZTU W V

37 R&M Game and Hypertree Width Let H be a hypergraph. Theorem: H has hypertree width  k if and only if k marshals have a winning strategy on H. Corollary: H is acyclic if and only if one marshal has a winning strategy on H. Winning strategies on H correspond to hypertree decompositions of H and vice versa.

38 VV PR S X Y ZTU W Strategies and Decompositions

39 VV PR S X Y ZTU W a(S,X,T,R), b(S,Y,U,P) First choice of the two marshals

40 VV PR S X Y ZTU W a(S,X,T,R), b(S,Y,U,P) A possible choice for the robber

41 V PR S X Y ZTU W a(S,X,T,R), b(S,Y,U,P) f(R,P,V) V The capture

42 VV PR S X Y ZTU W a(S,X,T,R), b(S,Y,U,P) f(R,P,V) The second choice for the robber

43 VV PR S X Y ZTU W a(S,X,T,R), b(S,Y,U,P) f(R,P,V)g(X,Y), c(T,Z,U) The marshals corner the robber

44 VV PR S X Y ZTU W a(S,X,T,R), b(S,Y,U,P) f(R,P,V)g(X,Y), c(T,Z,U) g(X,Y), d(W,X,Z) The capture

45 Work in progress Answering queries and hypertree decompositions: A query-planner based on hypertree decompositions Choosing the best query plan (i.e., the best decomposition) exploiting data on tables, attibute selectivity, indices, etc. Further possible applications: Answering queries using views


Download ppt "Answering Queries and Hypertree Decompositions Conjunctive Queries The problem BCQ: Instance: Question:Has Q a nonempty result over DB? Combined Complexity."

Similar presentations


Ads by Google